summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin L. Mitchell <kevin.mitchell@rackspace.com>2011-07-26 20:58:33 +0000
committerKevin L. Mitchell <kevin.mitchell@rackspace.com>2011-07-26 20:58:33 +0000
commitb18754473785611112ae54523677da83dff24075 (patch)
treed9962925e2a6701b687e7c8ee093a016d1df26e4
parentab8c3d5e334b582a206ec2766f0adb409a013fe0 (diff)
First pass at converting this stuff--pass context down into vmops. Still need to fix unit tests and actually use auth_token from the context...
-rw-r--r--nova/compute/manager.py9
-rw-r--r--nova/virt/xenapi/vm_utils.py22
-rw-r--r--nova/virt/xenapi/vmops.py29
3 files changed, 31 insertions, 29 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 31627fe3b..667d231ae 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -326,7 +326,7 @@ class ComputeManager(manager.SchedulerDependentManager):
self._update_state(context, instance_id, power_state.BUILDING)
try:
- self.driver.spawn(instance, network_info, bd_mapping)
+ self.driver.spawn(context, instance, network_info, bd_mapping)
except Exception as ex: # pylint: disable=W0702
msg = _("Instance '%(instance_id)s' failed to spawn. Is "
"virtualization enabled in the BIOS? Details: "
@@ -430,7 +430,7 @@ class ComputeManager(manager.SchedulerDependentManager):
image_ref = kwargs.get('image_ref')
instance_ref.image_ref = image_ref
instance_ref.injected_files = kwargs.get('injected_files', [])
- self.driver.spawn(instance_ref, network_info)
+ self.driver.spawn(context, instance_ref, network_info)
self._update_image_ref(context, instance_id, image_ref)
self._update_launched_at(context, instance_id)
@@ -498,7 +498,7 @@ class ComputeManager(manager.SchedulerDependentManager):
'instance: %(instance_id)s (state: %(state)s '
'expected: %(running)s)') % locals())
- self.driver.snapshot(instance_ref, image_id)
+ self.driver.snapshot(context, instance_ref, image_id)
if image_type == 'snapshot':
if rotation:
@@ -855,7 +855,8 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_ref = self.db.instance_get_by_uuid(context,
instance_ref.uuid)
network_info = self._get_instance_nw_info(context, instance_ref)
- self.driver.finish_resize(instance_ref, disk_info, network_info)
+ self.driver.finish_resize(context, instance_ref, disk_info,
+ network_info)
self.db.migration_update(context, migration_id,
{'status': 'finished', })
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index 62863c6d8..aa0e4c2df 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -359,7 +359,7 @@ class VMHelper(HelperBase):
return os.path.join(FLAGS.xenapi_sr_base_path, sr_uuid)
@classmethod
- def upload_image(cls, session, instance, vdi_uuids, image_id):
+ def upload_image(cls, context, session, instance, vdi_uuids, image_id):
""" Requests that the Glance plugin bundle the specified VDIs and
push them into Glance using the specified human-friendly name.
"""
@@ -384,7 +384,7 @@ class VMHelper(HelperBase):
session.wait_for_task(task, instance.id)
@classmethod
- def fetch_image(cls, session, instance_id, image, user, project,
+ def fetch_image(cls, context, session, instance_id, image, user, project,
image_type):
"""
image_type is interpreted as an ImageType instance
@@ -399,16 +399,16 @@ class VMHelper(HelperBase):
access = AuthManager().get_access_key(user, project)
if FLAGS.xenapi_image_service == 'glance':
- return cls._fetch_image_glance(session, instance_id, image,
- access, image_type)
+ return cls._fetch_image_glance(context, session, instance_id,
+ image, access, image_type)
else:
return cls._fetch_image_objectstore(session, instance_id, image,
access, user.secret,
image_type)
@classmethod
- def _fetch_image_glance_vhd(cls, session, instance_id, image, access,
- image_type):
+ def _fetch_image_glance_vhd(cls, context, session, instance_id, image,
+ access, image_type):
"""Tell glance to download an image and put the VHDs into the SR
Returns: A list of dictionaries that describe VDIs
@@ -455,8 +455,8 @@ class VMHelper(HelperBase):
return vdis
@classmethod
- def _fetch_image_glance_disk(cls, session, instance_id, image, access,
- image_type):
+ def _fetch_image_glance_disk(cls, context, session, instance_id, image,
+ access, image_type):
"""Fetch the image from Glance
NOTE:
@@ -589,7 +589,7 @@ class VMHelper(HelperBase):
return image_type
@classmethod
- def _fetch_image_glance(cls, session, instance_id, image, access,
+ def _fetch_image_glance(cls, context, session, instance_id, image, access,
image_type):
"""Fetch image from glance based on image type.
@@ -597,10 +597,10 @@ class VMHelper(HelperBase):
A list of dictionaries that describe VDIs, otherwise
"""
if image_type == ImageType.DISK_VHD:
- return cls._fetch_image_glance_vhd(
+ return cls._fetch_image_glance_vhd(context,
session, instance_id, image, access, image_type)
else:
- return cls._fetch_image_glance_disk(
+ return cls._fetch_image_glance_disk(context,
session, instance_id, image, access, image_type)
@classmethod
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 0473abb97..1c6604836 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -114,10 +114,10 @@ class VMOps(object):
vm_ref = VMHelper.lookup(self._session, instance.name)
self._start(instance, vm_ref)
- def finish_resize(self, instance, disk_info, network_info):
+ def finish_resize(self, context, instance, disk_info, network_info):
vdi_uuid = self.link_disks(instance, disk_info['base_copy'],
disk_info['cow'])
- vm_ref = self._create_vm(instance,
+ vm_ref = self._create_vm(context, instance,
[dict(vdi_type='os', vdi_uuid=vdi_uuid)],
network_info)
self.resize_instance(instance, vdi_uuid)
@@ -133,20 +133,20 @@ class VMOps(object):
LOG.debug(_("Starting instance %s"), instance.name)
self._session.call_xenapi('VM.start', vm_ref, False, False)
- def _create_disks(self, instance):
+ def _create_disks(self, context, instance):
user = AuthManager().get_user(instance.user_id)
project = AuthManager().get_project(instance.project_id)
disk_image_type = VMHelper.determine_disk_image_type(instance)
- vdis = VMHelper.fetch_image(self._session,
+ vdis = VMHelper.fetch_image(context, self._session,
instance.id, instance.image_ref, user, project,
disk_image_type)
return vdis
- def spawn(self, instance, network_info):
+ def spawn(self, context, instance, network_info):
vdis = None
try:
- vdis = self._create_disks(instance)
- vm_ref = self._create_vm(instance, vdis, network_info)
+ vdis = self._create_disks(context, instance)
+ vm_ref = self._create_vm(context, instance, vdis, network_info)
self._spawn(instance, vm_ref)
except (self.XenAPI.Failure, OSError, IOError) as spawn_error:
LOG.exception(_("instance %s: Failed to spawn"),
@@ -160,7 +160,7 @@ class VMOps(object):
"""Spawn a rescue instance."""
self.spawn(instance)
- def _create_vm(self, instance, vdis, network_info):
+ def _create_vm(self, context, instance, vdis, network_info):
"""Create VM instance."""
instance_name = instance.name
vm_ref = VMHelper.lookup(self._session, instance_name)
@@ -184,12 +184,12 @@ class VMOps(object):
ramdisk = None
try:
if instance.kernel_id:
- kernel = VMHelper.fetch_image(self._session, instance.id,
- instance.kernel_id, user, project,
+ kernel = VMHelper.fetch_image(context, self._session,
+ instance.id, instance.kernel_id, user, project,
ImageType.KERNEL)[0]
if instance.ramdisk_id:
- ramdisk = VMHelper.fetch_image(self._session, instance.id,
- instance.ramdisk_id, user, project,
+ ramdisk = VMHelper.fetch_image(context, self._session,
+ instance.id, instance.ramdisk_id, user, project,
ImageType.RAMDISK)[0]
# Create the VM ref and attach the first disk
first_vdi_ref = self._session.call_xenapi('VDI.get_by_uuid',
@@ -440,9 +440,10 @@ class VMOps(object):
vm,
"start")
- def snapshot(self, instance, image_id):
+ def snapshot(self, context, instance, image_id):
"""Create snapshot from a running VM instance.
+ :param context: request context
:param instance: instance to be snapshotted
:param image_id: id of image to upload to
@@ -467,7 +468,7 @@ class VMOps(object):
try:
template_vm_ref, template_vdi_uuids = self._get_snapshot(instance)
# call plugin to ship snapshot off to glance
- VMHelper.upload_image(
+ VMHelper.upload_image(context,
self._session, instance, template_vdi_uuids, image_id)
finally:
if template_vm_ref: