Skip to content

Commit

Permalink
Merge "Refactors more snapshot code into vm_utils."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 11, 2012
2 parents 40d8f5e + 1c18e27 commit 647684a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
4 changes: 2 additions & 2 deletions nova/tests/xenapi/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def SR_forget(self, _1, ref):


def stub_out_migration_methods(stubs):
def fake_create_snapshot(self, instance):
def fake_create_snapshot(session, instance, vm_ref, label):
return 'vm_ref', dict(image='foo', snap='bar')

def fake_move_disks(self, instance, disk_info):
Expand Down Expand Up @@ -347,7 +347,7 @@ def fake_generate_ephemeral(*args):
stubs.Set(vmops.VMOps, '_move_disks', fake_move_disks)
stubs.Set(vm_utils, 'scan_default_sr', fake_sr)
stubs.Set(vm_utils, '_scan_sr', fake_sr)
stubs.Set(vmops.VMOps, '_create_snapshot', fake_create_snapshot)
stubs.Set(vm_utils, 'create_snapshot', fake_create_snapshot)
stubs.Set(vm_utils, 'get_vdi_for_vm_safely', fake_get_vdi)
stubs.Set(vm_utils, 'get_sr_path', fake_get_sr_path)
stubs.Set(vm_utils, 'generate_ephemeral', fake_generate_ephemeral)
Expand Down
10 changes: 10 additions & 0 deletions nova/virt/xenapi/vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ def get_vdi_for_vm_safely(session, vm_ref):


def create_snapshot(session, instance, vm_ref, label):
LOG.debug(_("Starting snapshot for VM"), instance=instance)
try:
return _create_snapshot(session, instance, vm_ref, label)
except session.XenAPI.Failure, exc:
LOG.error(_("Unable to Snapshot instance: %(exc)s"), locals(),
instance=instance)
raise


def _create_snapshot(session, instance, vm_ref, label):
"""Creates Snapshot (Template) VM, Snapshot VBD, Snapshot VDI,
Snapshot VHD"""
LOG.debug(_("Snapshotting with label '%(label)s'"), locals(),
Expand Down
41 changes: 13 additions & 28 deletions nova/virt/xenapi/vmops.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,38 +601,21 @@ def snapshot(self, context, instance, image_id):
Glance.
"""
template_vm_ref = None
vm_ref = self._get_vm_opaque_ref(instance)
label = "%s-snapshot" % instance.name
template_vm_ref, template_vdi_uuids = vm_utils.create_snapshot(
self._session, instance, vm_ref, label)

try:
_snapshot_info = self._create_snapshot(instance)
template_vm_ref, template_vdi_uuids = _snapshot_info
# call plugin to ship snapshot off to glance
vm_utils.upload_image(context,
self._session, instance, template_vdi_uuids, image_id)
vm_utils.upload_image(context, self._session, instance,
template_vdi_uuids, image_id)
finally:
if template_vm_ref:
self._destroy(instance, template_vm_ref,
destroy_kernel_ramdisk=False)
self._destroy(instance, template_vm_ref,
destroy_kernel_ramdisk=False)

LOG.debug(_("Finished snapshot and upload for VM"),
instance=instance)

def _create_snapshot(self, instance):
#TODO(sirp): Add quiesce and VSS locking support when Windows support
# is added

LOG.debug(_("Starting snapshot for VM"), instance=instance)
vm_ref = self._get_vm_opaque_ref(instance)

label = "%s-snapshot" % instance.name
try:
template_vm_ref, template_vdi_uuids = vm_utils.create_snapshot(
self._session, instance, vm_ref, label)
return template_vm_ref, template_vdi_uuids
except self._session.XenAPI.Failure, exc:
LOG.error(_("Unable to Snapshot instance: %(exc)s"), locals(),
instance=instance)
raise

def _migrate_vhd(self, instance, vdi_uuid, dest, sr_path):
instance_uuid = instance['uuid']
params = {'host': dest,
Expand Down Expand Up @@ -693,8 +676,10 @@ def migrate_disk_and_power_off(self, context, instance, dest,
template_vdi_uuids = template_vm_ref = None
try:
# 1. Create Snapshot
_snapshot_info = self._create_snapshot(instance)
template_vm_ref, template_vdi_uuids = _snapshot_info
label = "%s-snapshot" % instance.name
template_vm_ref, template_vdi_uuids = vm_utils.create_snapshot(
self._session, instance, vm_ref, label)

self._update_instance_progress(context, instance,
step=1,
total_steps=RESIZE_TOTAL_STEPS)
Expand Down

0 comments on commit 647684a

Please sign in to comment.