From cb05f783d0c26063b2ce069c7f2a8fd794f4fa0e Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 4 Nov 2011 12:44:30 -0400 Subject: Reducing the number of compute calls to Glance Fixes bug 886224 Change-Id: Ibd270d24eb68cc2503fee933a2154125995d352d --- nova/virt/driver.py | 9 +++++++-- nova/virt/fake.py | 2 +- nova/virt/hyperv.py | 2 +- nova/virt/libvirt/connection.py | 2 +- nova/virt/vmwareapi/vmops.py | 2 +- nova/virt/vmwareapi_conn.py | 4 ++-- nova/virt/xenapi/vm_utils.py | 23 ++++++----------------- nova/virt/xenapi/vmops.py | 19 ++++++++++--------- nova/virt/xenapi_conn.py | 8 ++++---- 9 files changed, 33 insertions(+), 38 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 6bd83fb4d..bcdd20f2c 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -127,7 +127,7 @@ class ComputeDriver(object): # TODO(Vek): Need to pass context in for access to auth_token raise NotImplementedError() - def spawn(self, context, instance, + def spawn(self, context, instance, image_meta, network_info=None, block_device_info=None): """ Create a new instance/VM/domain on the virtualization platform. @@ -143,6 +143,8 @@ class ComputeDriver(object): :param instance: Instance object as returned by DB layer. This function should use the data there to guide the creation of the new instance. + :param image_meta: image object returned by nova.image.glance that + defines the image from which to boot this instance :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` :param block_device_info: Information about block devices to be @@ -253,11 +255,14 @@ class ComputeDriver(object): raise NotImplementedError() def finish_migration(self, context, migration, instance, disk_info, - network_info, resize_instance): + network_info, image_meta, resize_instance): """Completes a resize, turning on the migrated instance :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` + :param image_meta: image object returned by nova.image.glance that + defines the image from which this instance + was created """ raise NotImplementedError() diff --git a/nova/virt/fake.py b/nova/virt/fake.py index ad40297a3..d4a554c81 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -97,7 +97,7 @@ class FakeConnection(driver.ComputeDriver): """Plugin VIFs into networks.""" pass - def spawn(self, context, instance, + def spawn(self, context, instance, image_meta, network_info=None, block_device_info=None): name = instance.name state = power_state.RUNNING diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py index 16fd94e7f..34c784e7a 100644 --- a/nova/virt/hyperv.py +++ b/nova/virt/hyperv.py @@ -138,7 +138,7 @@ class HyperVConnection(driver.ComputeDriver): return instance_infos - def spawn(self, context, instance, + def spawn(self, context, instance, image_meta, network_info=None, block_device_info=None): """ Create a new VM and start it.""" vm = self._lookup(instance.name) diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index a2022ec18..c2a13f6a7 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -641,7 +641,7 @@ class LibvirtConnection(driver.ComputeDriver): # NOTE(ilyaalekseyev): Implementation like in multinics # for xenapi(tr3buchet) @exception.wrap_exception() - def spawn(self, context, instance, network_info, + def spawn(self, context, instance, image_meta, network_info, block_device_info=None): xml = self.to_xml(instance, network_info, False, block_device_info=block_device_info) diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index b4cb7f037..3206bab71 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -79,7 +79,7 @@ class VMWareVMOps(object): LOG.debug(_("Got total of %s instances") % str(len(lst_vm_names))) return lst_vm_names - def spawn(self, context, instance, network_info): + def spawn(self, context, instance, image_meta, network_info): """ Creates a VM instance. diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py index bef8b00f8..4d6e9d5fb 100644 --- a/nova/virt/vmwareapi_conn.py +++ b/nova/virt/vmwareapi_conn.py @@ -124,10 +124,10 @@ class VMWareESXConnection(driver.ComputeDriver): """List VM instances.""" return self._vmops.list_instances() - def spawn(self, context, instance, network_info, + def spawn(self, context, instance, image_meta, network_info, block_device_mapping=None): """Create VM instance.""" - self._vmops.spawn(context, instance, network_info) + self._vmops.spawn(context, instance, image_meta, network_info) def snapshot(self, context, instance, name): """Create snapshot from a running VM instance.""" diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 006cdbbc6..2c394ce64 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -717,7 +717,7 @@ w raise e @classmethod - def determine_disk_image_type(cls, instance, context): + def determine_disk_image_type(cls, image_meta): """Disk Image Types are used to determine where the kernel will reside within an image. To figure out which type we're dealing with, we use the following rules: @@ -736,12 +736,11 @@ w ImageType.DISK_VHD: 'DISK_VHD', ImageType.DISK_ISO: 'DISK_ISO'} disk_format = pretty_format[image_type] - image_ref = instance.image_ref - instance_id = instance.id + image_ref = image_meta['id'] LOG.debug(_("Detected %(disk_format)s format for image " - "%(image_ref)s, instance %(instance_id)s") % locals()) + "%(image_ref)s") % locals()) - def determine_from_glance(): + def determine_from_image_meta(): glance_disk_format2nova_type = { 'ami': ImageType.DISK, 'aki': ImageType.KERNEL, @@ -749,23 +748,13 @@ w 'raw': ImageType.DISK_RAW, 'vhd': ImageType.DISK_VHD, 'iso': ImageType.DISK_ISO} - image_ref = instance.image_ref - glance_client, image_id = glance.get_glance_client(context, - image_ref) - meta = glance_client.get_image_meta(image_id) - disk_format = meta['disk_format'] + disk_format = image_meta['disk_format'] try: return glance_disk_format2nova_type[disk_format] except KeyError: raise exception.InvalidDiskFormat(disk_format=disk_format) - def determine_from_instance(): - if instance.kernel_id: - return ImageType.DISK - else: - return ImageType.DISK_RAW - - image_type = determine_from_glance() + image_type = determine_from_image_meta() log_disk_format(image_type) return image_type diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index a797fa3ea..4f53c8ab9 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -139,13 +139,13 @@ class VMOps(object): self._start(instance, vm_ref) def finish_migration(self, context, migration, instance, disk_info, - network_info, resize_instance): + network_info, image_meta, resize_instance): vdi_uuid = self.link_disks(instance, disk_info['base_copy'], disk_info['cow']) vm_ref = self._create_vm(context, instance, [dict(vdi_type='os', vdi_uuid=vdi_uuid)], - network_info) + network_info, image_meta) if resize_instance: self.resize_instance(instance, vdi_uuid) @@ -165,8 +165,8 @@ class VMOps(object): LOG.debug(_("Starting instance %s"), instance.name) self._session.call_xenapi('VM.start', vm_ref, False, False) - def _create_disks(self, context, instance): - disk_image_type = VMHelper.determine_disk_image_type(instance, context) + def _create_disks(self, context, instance, image_meta): + disk_image_type = VMHelper.determine_disk_image_type(image_meta) vdis = VMHelper.fetch_image(context, self._session, instance, instance.image_ref, instance.user_id, instance.project_id, @@ -178,7 +178,7 @@ class VMOps(object): return vdis - def spawn(self, context, instance, network_info): + def spawn(self, context, instance, image_meta, network_info): vdis = None try: # 1. Vanity Step @@ -193,13 +193,14 @@ class VMOps(object): total_steps=BUILD_TOTAL_STEPS) # 2. Fetch the Image over the Network - vdis = self._create_disks(context, instance) + vdis = self._create_disks(context, instance, image_meta) self._update_instance_progress(context, instance, step=2, total_steps=BUILD_TOTAL_STEPS) # 3. Create the VM records - vm_ref = self._create_vm(context, instance, vdis, network_info) + vm_ref = self._create_vm(context, instance, vdis, network_info, + image_meta) self._update_instance_progress(context, instance, step=3, total_steps=BUILD_TOTAL_STEPS) @@ -222,7 +223,7 @@ class VMOps(object): """Spawn a rescue instance.""" self.spawn(context, instance, network_info) - def _create_vm(self, context, instance, vdis, network_info): + def _create_vm(self, context, instance, vdis, network_info, image_meta): """Create VM instance.""" instance_name = instance.name vm_ref = VMHelper.lookup(self._session, instance_name) @@ -233,7 +234,7 @@ class VMOps(object): if not VMHelper.ensure_free_mem(self._session, instance): raise exception.InsufficientFreeMemory(uuid=instance.uuid) - disk_image_type = VMHelper.determine_disk_image_type(instance, context) + disk_image_type = VMHelper.determine_disk_image_type(image_meta) kernel = None ramdisk = None try: diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 47554e757..ab9c3e368 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -193,10 +193,10 @@ class XenAPIConnection(driver.ComputeDriver): def list_instances_detail(self): return self._vmops.list_instances_detail() - def spawn(self, context, instance, + def spawn(self, context, instance, image_meta, network_info=None, block_device_info=None): """Create VM instance""" - self._vmops.spawn(context, instance, network_info) + self._vmops.spawn(context, instance, image_meta, network_info) def confirm_migration(self, migration, instance, network_info): """Confirms a resize, destroying the source VM""" @@ -208,10 +208,10 @@ class XenAPIConnection(driver.ComputeDriver): self._vmops.finish_revert_migration(instance) def finish_migration(self, context, migration, instance, disk_info, - network_info, resize_instance=False): + network_info, image_meta, resize_instance=False): """Completes a resize, turning on the migrated instance""" self._vmops.finish_migration(context, migration, instance, disk_info, - network_info, resize_instance) + network_info, image_meta, resize_instance) def snapshot(self, context, instance, image_id): """ Create snapshot from a running VM instance """ -- cgit