Commit 89d48699 by Bach Dániel

Merge branch 'readable-name-review-rebased'

Conflicts:
	circle/storage/models.py
parents 3b92a4c0 a2294a09
...@@ -439,9 +439,12 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -439,9 +439,12 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def vm_state_changed(self, new_state): def vm_state_changed(self, new_state):
# log state change # log state change
try: try:
act = InstanceActivity.create(code_suffix='vm_state_changed', act = InstanceActivity.create(
instance=self, code_suffix='vm_state_changed',
readable_name="vm state changed") readable_name=create_readable(
ugettext_noop("vm state changed to %(state)s"),
state=new_state),
instance=self)
except ActivityInProgressError: except ActivityInProgressError:
pass # discard state change if another activity is in progress. pass # discard state change if another activity is in progress.
else: else:
......
...@@ -24,6 +24,8 @@ from django.core.exceptions import PermissionDenied ...@@ -24,6 +24,8 @@ from django.core.exceptions import PermissionDenied
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ugettext_noop from django.utils.translation import ugettext_lazy as _, ugettext_noop
from sizefield.utils import filesizeformat
from celery.exceptions import TimeLimitExceeded from celery.exceptions import TimeLimitExceeded
from common.models import create_readable, humanize_exception from common.models import create_readable, humanize_exception
...@@ -133,7 +135,9 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -133,7 +135,9 @@ class AddInterfaceOperation(InstanceOperation):
if self.instance.is_running: if self.instance.is_running:
try: try:
with activity.sub_activity('attach_network'): with activity.sub_activity(
'attach_network',
readable_name=ugettext_noop("attach network")):
self.instance.attach_network(net) self.instance.attach_network(net)
except Exception as e: except Exception as e:
if hasattr(e, 'libvirtError'): if hasattr(e, 'libvirtError'):
...@@ -173,14 +177,21 @@ class CreateDiskOperation(InstanceOperation): ...@@ -173,14 +177,21 @@ class CreateDiskOperation(InstanceOperation):
self.instance.disks.add(disk) self.instance.disks.add(disk)
if self.instance.is_running: 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() 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) self.instance.attach_disk(disk)
def get_activity_name(self, kwargs): def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("create %(size)s disk"), return create_readable(
size=kwargs['size']) ugettext_noop("create disk %(name)s (%(size)s)"),
size=filesizeformat(kwargs['size']), name=kwargs['name'])
register_operation(CreateDiskOperation) register_operation(CreateDiskOperation)
...@@ -213,7 +224,10 @@ class DownloadDiskOperation(InstanceOperation): ...@@ -213,7 +224,10 @@ class DownloadDiskOperation(InstanceOperation):
# TODO iso (cd) hot-plug is not supported by kvm/guests # TODO iso (cd) hot-plug is not supported by kvm/guests
if self.instance.is_running and disk.type not in ["iso"]: 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) self.instance.attach_disk(disk)
register_operation(DownloadDiskOperation) register_operation(DownloadDiskOperation)
...@@ -402,13 +416,20 @@ class RemoveInterfaceOperation(InstanceOperation): ...@@ -402,13 +416,20 @@ class RemoveInterfaceOperation(InstanceOperation):
def _operation(self, activity, user, system, interface): def _operation(self, activity, user, system, interface):
if self.instance.is_running: 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) self.instance.detach_network(interface)
interface.shutdown() interface.shutdown()
interface.destroy() interface.destroy()
interface.delete() interface.delete()
def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("remove %(vlan)s interface"),
vlan=kwargs['interface'].vlan)
register_operation(RemoveInterfaceOperation) register_operation(RemoveInterfaceOperation)
...@@ -423,10 +444,20 @@ class RemoveDiskOperation(InstanceOperation): ...@@ -423,10 +444,20 @@ class RemoveDiskOperation(InstanceOperation):
def _operation(self, activity, user, system, disk): def _operation(self, activity, user, system, disk):
if self.instance.is_running and disk.type not in ["iso"]: 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) self.instance.detach_disk(disk)
return self.instance.disks.remove(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) register_operation(RemoveDiskOperation)
...@@ -515,9 +546,13 @@ class SaveAsTemplateOperation(InstanceOperation): ...@@ -515,9 +546,13 @@ class SaveAsTemplateOperation(InstanceOperation):
return disk return disk
self.disks = [] self.disks = []
with activity.sub_activity('saving_disks', for disk in self.instance.disks.all():
readable_name=ugettext_noop("save disks")): with activity.sub_activity(
for disk in self.instance.disks.all(): 'saving_disk',
readable_name=create_readable(
ugettext_noop("saving disk %(name)s"),
name=disk.name)
):
self.disks.append(__try_save_disk(disk)) self.disks.append(__try_save_disk(disk))
# create template and do additional setup # create template and do additional setup
......
...@@ -25,22 +25,25 @@ from StringIO import StringIO ...@@ -25,22 +25,25 @@ from StringIO import StringIO
from tarfile import TarFile, TarInfo from tarfile import TarFile, TarInfo
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_noop
from celery.result import TimeoutError from celery.result import TimeoutError
from monitor.client import Client from monitor.client import Client
def send_init_commands(instance, act, vm): def send_init_commands(instance, act, vm):
queue = instance.get_remote_queue_name("agent") queue = instance.get_remote_queue_name("agent")
with act.sub_activity('cleanup', readable_name=ugettext_noop('cleanup')):
with act.sub_activity('cleanup'):
cleanup.apply_async(queue=queue, args=(vm, )) 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, )) 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)) 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())) 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( set_hostname.apply_async(
queue=queue, args=(vm, instance.primary_host.hostname)) queue=queue, args=(vm, instance.primary_host.hostname))
...@@ -73,13 +76,20 @@ def agent_started(vm, version=None): ...@@ -73,13 +76,20 @@ def agent_started(vm, version=None):
initialized = InstanceActivity.objects.filter( initialized = InstanceActivity.objects.filter(
instance=instance, activity_code='vm.Instance.agent.cleanup').exists() instance=instance, activity_code='vm.Instance.agent.cleanup').exists()
with instance_activity(code_suffix='agent', instance=instance) as act: with instance_activity(code_suffix='agent',
with act.sub_activity('starting'): readable_name=ugettext_noop('agent'),
instance=instance) as act:
with act.sub_activity('starting',
readable_name=ugettext_noop('starting')):
pass pass
if version and version != settings.AGENT_VERSION: if version and version != settings.AGENT_VERSION:
try: try:
with act.sub_activity('update'): with act.sub_activity(
'update',
readable_name=ugettext_noop('update to %(version)s'),
version=settings.AGENT_VERSION
):
update.apply_async( update.apply_async(
queue=queue, queue=queue,
args=(vm, create_agent_tar())).get(timeout=10) args=(vm, create_agent_tar())).get(timeout=10)
...@@ -91,7 +101,10 @@ def agent_started(vm, version=None): ...@@ -91,7 +101,10 @@ def agent_started(vm, version=None):
measure_boot_time(instance) measure_boot_time(instance)
send_init_commands(instance, act, vm) 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 access server')
):
start_access_server.apply_async(queue=queue, args=(vm, )) start_access_server.apply_async(queue=queue, args=(vm, ))
...@@ -122,5 +135,5 @@ def agent_stopped(vm): ...@@ -122,5 +135,5 @@ def agent_stopped(vm):
qs = InstanceActivity.objects.filter(instance=instance, qs = InstanceActivity.objects.filter(instance=instance,
activity_code='vm.Instance.agent') activity_code='vm.Instance.agent')
act = qs.latest('id') act = qs.latest('id')
with act.sub_activity('stopping'): with act.sub_activity('stopping', readable_name=ugettext_noop('stopping')):
pass 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