Commit ea6a29e0 by Bach Dániel

Merge remote-tracking branch 'origin/readable-name-review'

Conflicts:
	circle/vm/operations.py
parents 2c621f0f 91a49ee5
......@@ -313,6 +313,8 @@ class Disk(TimeStampedModel):
if self.is_ready:
return True
if self.base and not self.base.is_ready:
raise Exception("Base image is not ready.")
queue_name = self.get_remote_queue_name('storage', priority="fast")
disk_desc = self.get_disk_desc()
if self.base is not None:
......@@ -433,7 +435,7 @@ class Disk(TimeStampedModel):
disk = Disk.create(datastore=self.datastore,
base=new_base,
name=self.name, size=self.size,
type=new_type)
type=new_type, dev_num=self.dev_num)
queue_name = self.get_remote_queue_name("storage", priority="slow")
remote = storage_tasks.merge.apply_async(kwargs={
......@@ -450,4 +452,6 @@ class Disk(TimeStampedModel):
AbortableAsyncResult(remote.id).abort()
disk.destroy()
raise Exception("Save as aborted by use.")
disk.is_ready = True
disk.save()
return disk
......@@ -439,9 +439,12 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def vm_state_changed(self, new_state):
# log state change
try:
act = InstanceActivity.create(code_suffix='vm_state_changed',
instance=self,
readable_name="vm state changed")
act = InstanceActivity.create(
code_suffix='vm_state_changed',
readable_name=create_readable(
ugettext_noop("vm state changed to %(state)s"),
state=new_state),
instance=self)
except ActivityInProgressError:
pass # discard state change if another activity is in progress.
else:
......
......@@ -24,6 +24,8 @@ from django.core.exceptions import PermissionDenied
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from sizefield.utils import filesizeformat
from celery.exceptions import TimeLimitExceeded
from common.models import create_readable, humanize_exception
......@@ -133,7 +135,9 @@ class AddInterfaceOperation(InstanceOperation):
if self.instance.is_running:
try:
with activity.sub_activity('attach_network'):
with activity.sub_activity(
'attach_network',
readable_name=ugettext_noop("attach network")):
self.instance.attach_network(net)
except Exception as e:
if hasattr(e, 'libvirtError'):
......@@ -173,14 +177,21 @@ class CreateDiskOperation(InstanceOperation):
self.instance.disks.add(disk)
if self.instance.is_running:
with activity.sub_activity('deploying_disk'):
with activity.sub_activity(
'deploying_disk',
readable_name=ugettext_noop("deploying disk")
):
disk.deploy()
with activity.sub_activity('attach_disk'):
with activity.sub_activity(
'attach_disk',
readable_name=ugettext_noop("attach disk")
):
self.instance.attach_disk(disk)
def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("create %(size)s disk"),
size=kwargs['size'])
return create_readable(
ugettext_noop("create disk %(name)s (%(size)s)"),
size=filesizeformat(kwargs['size']), name=kwargs['name'])
register_operation(CreateDiskOperation)
......@@ -213,7 +224,10 @@ class DownloadDiskOperation(InstanceOperation):
# TODO iso (cd) hot-plug is not supported by kvm/guests
if self.instance.is_running and disk.type not in ["iso"]:
with activity.sub_activity('attach_disk'):
with activity.sub_activity(
'attach_disk',
readable_name=ugettext_noop("attach disk")
):
self.instance.attach_disk(disk)
register_operation(DownloadDiskOperation)
......@@ -402,13 +416,20 @@ class RemoveInterfaceOperation(InstanceOperation):
def _operation(self, activity, user, system, interface):
if self.instance.is_running:
with activity.sub_activity('detach_network'):
with activity.sub_activity(
'detach_network',
readable_name=ugettext_noop("detach network")
):
self.instance.detach_network(interface)
interface.shutdown()
interface.destroy()
interface.delete()
def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("remove %(vlan)s interface"),
vlan=kwargs['interface'].vlan)
register_operation(RemoveInterfaceOperation)
......@@ -423,10 +444,20 @@ class RemoveDiskOperation(InstanceOperation):
def _operation(self, activity, user, system, disk):
if self.instance.is_running and disk.type not in ["iso"]:
with activity.sub_activity('detach_disk'):
with activity.sub_activity(
'detach_disk',
readable_name=ugettext_noop('detach disk')
):
self.instance.detach_disk(disk)
with activity.sub_activity(
'destroy_disk',
readable_name=ugettext_noop('destroy disk')
):
return self.instance.disks.remove(disk)
def get_activity_name(self, kwargs):
return create_readable(ugettext_noop('remove disk %(name)s'),
name=kwargs["disk"].name)
register_operation(RemoveDiskOperation)
......@@ -515,9 +546,13 @@ class SaveAsTemplateOperation(InstanceOperation):
return disk
self.disks = []
with activity.sub_activity('saving_disks',
readable_name=ugettext_noop("save disks")):
for disk in self.instance.disks.all():
with activity.sub_activity(
'saving_disk',
readable_name=create_readable(
ugettext_noop("saving disk %(name)s"),
name=disk.name)
):
self.disks.append(__try_save_disk(disk))
# create template and do additional setup
......
......@@ -25,22 +25,25 @@ from StringIO import StringIO
from tarfile import TarFile, TarInfo
from django.conf import settings
from django.utils import timezone
from django.utils.translation import ugettext_noop
from celery.result import TimeoutError
from monitor.client import Client
def send_init_commands(instance, act, vm):
queue = instance.get_remote_queue_name("agent")
with act.sub_activity('cleanup'):
with act.sub_activity('cleanup', readable_name=ugettext_noop('cleanup')):
cleanup.apply_async(queue=queue, args=(vm, ))
with act.sub_activity('restart_networking'):
with act.sub_activity('restart_networking',
readable_name=ugettext_noop('restart networking')):
restart_networking.apply_async(queue=queue, args=(vm, ))
with act.sub_activity('change_password'):
with act.sub_activity('change_password',
readable_name=ugettext_noop('change password')):
change_password.apply_async(queue=queue, args=(vm, instance.pw))
with act.sub_activity('set_time'):
with act.sub_activity('set_time', readable_name=ugettext_noop('set time')):
set_time.apply_async(queue=queue, args=(vm, time.time()))
with act.sub_activity('set_hostname'):
with act.sub_activity('set_hostname',
readable_name=ugettext_noop('set hostname')):
set_hostname.apply_async(
queue=queue, args=(vm, instance.primary_host.hostname))
......@@ -73,13 +76,17 @@ def agent_started(vm, version=None):
initialized = InstanceActivity.objects.filter(
instance=instance, activity_code='vm.Instance.agent.cleanup').exists()
with instance_activity(code_suffix='agent', instance=instance) as act:
with act.sub_activity('starting'):
with instance_activity(code_suffix='agent',
readable_name=ugettext_noop('agent'),
instance=instance) as act:
with act.sub_activity('starting',
readable_name=ugettext_noop('starting')):
pass
if version and version != settings.AGENT_VERSION:
try:
with act.sub_activity('update'):
with act.sub_activity('update',
readable_name=ugettext_noop('update')):
update.apply_async(
queue=queue,
args=(vm, create_agent_tar())).get(timeout=10)
......@@ -91,7 +98,9 @@ def agent_started(vm, version=None):
measure_boot_time(instance)
send_init_commands(instance, act, vm)
with act.sub_activity('start_access_server'):
with act.sub_activity('start_access_server',
readable_name=ugettext_noop('start acces server')
):
start_access_server.apply_async(queue=queue, args=(vm, ))
......@@ -122,5 +131,5 @@ def agent_stopped(vm):
qs = InstanceActivity.objects.filter(instance=instance,
activity_code='vm.Instance.agent')
act = qs.latest('id')
with act.sub_activity('stopping'):
with act.sub_activity('stopping', readable_name=ugettext_noop('stopping')):
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment