Skip to content

Commit

Permalink
Merge "Replacing instance id's in in xenapi.vmops and the xen plugin …
Browse files Browse the repository at this point in the history
…with instance uuids. The only references to instance id's left are calls to the wait_for_task() method. I will address that in another branch. blueprint: internal-uuids"
  • Loading branch information
Jenkins authored and openstack-gerrit committed Dec 2, 2011
2 parents 9c3502e + 9dbcd8b commit ab215c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
55 changes: 29 additions & 26 deletions nova/virt/xenapi/vmops.py
Expand Up @@ -318,7 +318,7 @@ def _create_vm(self, context, instance, vdis, network_info, image_meta):

def _attach_disks(self, instance, disk_image_type, vm_ref, first_vdi_ref,
vdis):
instance_id = instance.id
instance_uuid = instance['uuid']
# device 0 reserved for RW disk
userdevice = 0

Expand All @@ -344,7 +344,7 @@ def _attach_disks(self, instance, disk_image_type, vm_ref, first_vdi_ref,
else:
if instance.auto_disk_config:
LOG.debug(_("Auto configuring disk for instance"
" %(instance_id)s, attempting to"
" %(instance_uuid)s, attempting to"
" resize partition...") % locals())
VMHelper.auto_configure_disk(session=self._session,
vdi_ref=first_vdi_ref)
Expand Down Expand Up @@ -618,10 +618,11 @@ def _create_snapshot(self, instance):
return

def _migrate_vhd(self, instance, vdi_uuid, dest, sr_path):
instance_id = instance.id
instance_id = instance['id']
instance_uuid = instance['uuid']
params = {'host': dest,
'vdi_uuid': vdi_uuid,
'instance_id': instance_id,
'instance_uuid': instance_uuid,
'sr_path': sr_path}

try:
Expand Down Expand Up @@ -650,10 +651,10 @@ def _update_instance_progress(self, context, instance, step, total_steps):
# better approximation would use the percentage of the VM image that
# has been streamed to the destination host.
progress = round(float(step) / total_steps * 100)
instance_id = instance['id']
LOG.debug(_("Updating instance '%(instance_id)s' progress to"
instance_uuid = instance['uuid']
LOG.debug(_("Updating instance '%(instance_uuid)s' progress to"
" %(progress)d") % locals())
db.instance_update(context, instance_id, {'progress': progress})
db.instance_update(context, instance_uuid, {'progress': progress})

def migrate_disk_and_power_off(self, context, instance, dest):
"""Copies a VHD from one host machine to another.
Expand Down Expand Up @@ -727,7 +728,7 @@ def link_disks(self, instance, base_copy_uuid, cow_uuid):
"""Links the base copy VHD to the COW via the XAPI plugin."""
new_base_copy_uuid = str(uuid.uuid4())
new_cow_uuid = str(uuid.uuid4())
params = {'instance_id': instance.id,
params = {'instance_uuid': instance['uuid'],
'old_base_copy_uuid': base_copy_uuid,
'old_cow_uuid': cow_uuid,
'new_base_copy_uuid': new_base_copy_uuid,
Expand Down Expand Up @@ -909,8 +910,8 @@ def _shutdown(self, instance, vm_ref, hard=True):
"skipping shutdown...") % locals())
return

instance_id = instance.id
LOG.debug(_("Shutting down VM for Instance %(instance_id)s")
instance_uuid = instance['uuid']
LOG.debug(_("Shutting down VM for Instance %(instance_uuid)s")
% locals())
try:
task = None
Expand Down Expand Up @@ -941,8 +942,8 @@ def _shutdown_rescue(self, rescue_vm_ref):

def _destroy_vdis(self, instance, vm_ref):
"""Destroys all VDIs associated with a VM."""
instance_id = instance.id
LOG.debug(_("Destroying VDIs for Instance %(instance_id)s")
instance_uuid = instance['uuid']
LOG.debug(_("Destroying VDIs for Instance %(instance_uuid)s")
% locals())
vdi_refs = VMHelper.lookup_vm_vdis(self._session, vm_ref)

Expand Down Expand Up @@ -997,16 +998,16 @@ def _destroy_kernel_ramdisk(self, instance, vm_ref):
and the ramdisk.
"""
instance_id = instance.id
instance_uuid = instance['uuid']
if not instance.kernel_id and not instance.ramdisk_id:
# 1. No kernel or ramdisk
LOG.debug(_("Instance %(instance_id)s using RAW or VHD, "
LOG.debug(_("Instance %(instance_uuid)s using RAW or VHD, "
"skipping kernel and ramdisk deletion") % locals())
return

if not (instance.kernel_id and instance.ramdisk_id):
# 2. We only have kernel xor ramdisk
raise exception.InstanceUnacceptable(instance_id=instance_id,
raise exception.InstanceUnacceptable(instance_id=instance_uuid,
reason=_("instance has a kernel or ramdisk but not both"))

# 3. We have both kernel and ramdisk
Expand All @@ -1018,14 +1019,15 @@ def _destroy_kernel_ramdisk(self, instance, vm_ref):

def _destroy_vm(self, instance, vm_ref):
"""Destroys a VM record."""
instance_id = instance.id
instance_id = instance['id']
instance_uuid = instance['uuid']
try:
task = self._session.call_xenapi('Async.VM.destroy', vm_ref)
self._session.wait_for_task(task, instance_id)
except self.XenAPI.Failure, exc:
LOG.exception(exc)

LOG.debug(_("Instance %(instance_id)s VM destroyed") % locals())
LOG.debug(_("Instance %(instance_uuid)s VM destroyed") % locals())

def _destroy_rescue_instance(self, rescue_vm_ref):
"""Destroy a rescue instance."""
Expand All @@ -1042,8 +1044,8 @@ def destroy(self, instance, network_info):
destroy_* methods are internal.
"""
instance_id = instance.id
LOG.info(_("Destroying VM for Instance %(instance_id)s") % locals())
instance_uuid = instance['uuid']
LOG.info(_("Destroying VM for Instance %(instance_uuid)s") % locals())
vm_ref = VMHelper.lookup(self._session, instance.name)
return self._destroy(instance, vm_ref, network_info, shutdown=True)

Expand Down Expand Up @@ -1134,7 +1136,7 @@ def unrescue(self, instance):
"%s-rescue" % instance.name)

if not rescue_vm_ref:
raise exception.InstanceNotInRescueMode(instance_id=instance.id)
raise exception.InstanceNotInRescueMode(instance_id=instance.uuid)

original_vm_ref = VMHelper.lookup(self._session, instance.name)
instance._rescue = False
Expand Down Expand Up @@ -1466,9 +1468,9 @@ def _make_agent_call(self, method, vm, path, addl_args=None):
try:
return json.loads(ret)
except TypeError:
instance_id = vm.id
instance_uuid = vm['uuid']
LOG.error(_('The agent call to %(method)s returned an invalid'
' response: %(ret)r. VM id=%(instance_id)s;'
' response: %(ret)r. VM id=%(instance_uuid)s;'
' path=%(path)s; args=%(addl_args)r') % locals())
return {'returncode': 'error',
'message': 'unable to deserialize response'}
Expand All @@ -1479,7 +1481,8 @@ def _make_plugin_call(self, plugin, method, vm, path, addl_args=None,
Abstracts out the process of calling a method of a xenapi plugin.
Any errors raised by the plugin will in turn raise a RuntimeError here.
"""
instance_id = vm.id
instance_id = vm['id']
instance_uuid = vm['uuid']
vm_ref = vm_ref or self._get_vm_opaque_ref(vm)
vm_rec = self._session.call_xenapi("VM.get_record", vm_ref)
args = {'dom_id': vm_rec['domid'], 'path': path}
Expand All @@ -1492,16 +1495,16 @@ def _make_plugin_call(self, plugin, method, vm, path, addl_args=None,
err_msg = e.details[-1].splitlines()[-1]
if 'TIMEOUT:' in err_msg:
LOG.error(_('TIMEOUT: The call to %(method)s timed out. '
'VM id=%(instance_id)s; args=%(args)r') % locals())
'VM id=%(instance_uuid)s; args=%(args)r') % locals())
return {'returncode': 'timeout', 'message': err_msg}
elif 'NOT IMPLEMENTED:' in err_msg:
LOG.error(_('NOT IMPLEMENTED: The call to %(method)s is not'
' supported by the agent. VM id=%(instance_id)s;'
' supported by the agent. VM id=%(instance_uuid)s;'
' args=%(args)r') % locals())
return {'returncode': 'notimplemented', 'message': err_msg}
else:
LOG.error(_('The call to %(method)s returned an error: %(e)s. '
'VM id=%(instance_id)s; args=%(args)r') % locals())
'VM id=%(instance_uuid)s; args=%(args)r') % locals())
return {'returncode': 'error', 'message': err_msg}
return ret

Expand Down
10 changes: 5 additions & 5 deletions plugins/xenserver/xenapi/etc/xapi.d/plugins/migration
Expand Up @@ -35,7 +35,7 @@ configure_logging('migration')
def move_vhds_into_sr(session, args):
"""Moves the VHDs from their copied location to the SR"""
params = pickle.loads(exists(args, 'params'))
instance_id = params['instance_id']
instance_uuid = params['instance_uuid']

old_base_copy_uuid = params['old_base_copy_uuid']
old_cow_uuid = params['old_cow_uuid']
Expand All @@ -48,12 +48,12 @@ def move_vhds_into_sr(session, args):

# Discover the copied VHDs locally, and then set up paths to copy
# them to under the SR
source_image_path = "/images/instance%d" % instance_id
source_image_path = "/images/instance%s" % instance_uuid
source_base_copy_path = "%s/%s.vhd" % (source_image_path,
old_base_copy_uuid)
source_cow_path = "%s/%s.vhd" % (source_image_path, old_cow_uuid)

temp_vhd_path = "%s/instance%d/" % (sr_temp_path, instance_id)
temp_vhd_path = "%s/instance%s/" % (sr_temp_path, instance_uuid)
new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid)
new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid)

Expand Down Expand Up @@ -89,14 +89,14 @@ def move_vhds_into_sr(session, args):
def transfer_vhd(session, args):
"""Rsyncs a VHD to an adjacent host"""
params = pickle.loads(exists(args, 'params'))
instance_id = params['instance_id']
instance_uuid = params['instance_uuid']
host = params['host']
vdi_uuid = params['vdi_uuid']
sr_path = params['sr_path']
vhd_path = "%s.vhd" % vdi_uuid

source_path = "%s/%s" % (sr_path, vhd_path)
dest_path = '%s:/images/instance%d/' % (host, instance_id)
dest_path = '%s:/images/instance%s/' % (host, instance_uuid)

logging.debug("Preparing to transmit %s to %s" % (source_path,
dest_path))
Expand Down

0 comments on commit ab215c4

Please sign in to comment.