Merge "Refactors more snapshot code into vm_utils."
This commit is contained in:
@@ -317,7 +317,7 @@ class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests):
|
||||
|
||||
|
||||
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):
|
||||
@@ -347,7 +347,7 @@ def stub_out_migration_methods(stubs):
|
||||
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)
|
||||
|
@@ -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(),
|
||||
|
@@ -601,38 +601,21 @@ class VMOps(object):
|
||||
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,
|
||||
@@ -693,8 +676,10 @@ class VMOps(object):
|
||||
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)
|
||||
|
Reference in New Issue
Block a user