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): ...@@ -313,6 +313,8 @@ class Disk(TimeStampedModel):
if self.is_ready: if self.is_ready:
return True 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") queue_name = self.get_remote_queue_name('storage', priority="fast")
disk_desc = self.get_disk_desc() disk_desc = self.get_disk_desc()
if self.base is not None: if self.base is not None:
...@@ -433,7 +435,7 @@ class Disk(TimeStampedModel): ...@@ -433,7 +435,7 @@ class Disk(TimeStampedModel):
disk = Disk.create(datastore=self.datastore, disk = Disk.create(datastore=self.datastore,
base=new_base, base=new_base,
name=self.name, size=self.size, 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") queue_name = self.get_remote_queue_name("storage", priority="slow")
remote = storage_tasks.merge.apply_async(kwargs={ remote = storage_tasks.merge.apply_async(kwargs={
...@@ -450,4 +452,6 @@ class Disk(TimeStampedModel): ...@@ -450,4 +452,6 @@ class Disk(TimeStampedModel):
AbortableAsyncResult(remote.id).abort() AbortableAsyncResult(remote.id).abort()
disk.destroy() disk.destroy()
raise Exception("Save as aborted by use.") raise Exception("Save as aborted by use.")
disk.is_ready = True
disk.save()
return disk return disk
...@@ -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)
with activity.sub_activity(
'destroy_disk',
readable_name=ugettext_noop('destroy disk')
):
return self.instance.disks.remove(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',
readable_name=ugettext_noop("save disks")):
for disk in self.instance.disks.all(): 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)) 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,17 @@ def agent_started(vm, version=None): ...@@ -73,13 +76,17 @@ 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')):
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 +98,9 @@ def agent_started(vm, version=None): ...@@ -91,7 +98,9 @@ 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 acces server')
):
start_access_server.apply_async(queue=queue, args=(vm, )) start_access_server.apply_async(queue=queue, args=(vm, ))
...@@ -122,5 +131,5 @@ def agent_stopped(vm): ...@@ -122,5 +131,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