From: Cory Stone Date: Fri, 17 Aug 2012 14:18:52 +0000 (-0500) Subject: Call driver for attach/detach_volume. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=17538890dc9d005652b2d912cea4a0307e5d6e18;p=openstack-build%2Fcinder-build.git Call driver for attach/detach_volume. The volume driver may want to know which guest is going to be attached to a volume. The manager now calls down into the driver on attach_volume and detach_volume. Fixes bug 1038109. Change-Id: I084c2d09a1871fa158312f9ba479abb474da1d28 --- diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 177d413a4..bcc1b3b2f 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -234,6 +234,14 @@ class VolumeDriver(object): """Disallow connection from connector""" raise NotImplementedError() + def attach_volume(self, context, volume_id, instance_uuid, mountpoint): + """ Callback for volume attached to instance.""" + pass + + def detach_volume(self, context, volume_id): + """ Callback for volume detached.""" + pass + def get_volume_stats(self, refresh=False): """Return the current state of the volume service. If 'refresh' is True, run the update first.""" diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index eee3d8631..2ba2d0ffd 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -257,6 +257,17 @@ class VolumeManager(manager.SchedulerDependentManager): if not utils.is_uuid_like(instance_uuid): raise exception.InvalidUUID(instance_uuid) + try: + self.driver.attach_volume(context, + volume_id, + instance_uuid, + mountpoint) + except Exception: + with excutils.save_and_reraise_exception(): + self.db.volume_update(context, + volume_id, + {'status': 'error_attaching'}) + self.db.volume_attached(context.elevated(), volume_id, instance_uuid, @@ -266,6 +277,14 @@ class VolumeManager(manager.SchedulerDependentManager): """Updates db to show volume is detached""" # TODO(vish): refactor this into a more general "unreserve" # TODO(sleepsonthefloor): Is this 'elevated' appropriate? + try: + self.driver.detach_volume(context, volume_id) + except Exception: + with excutils.save_and_reraise_exception(): + self.db.volume_update(context, + volume_id, + {'status': 'error_detaching'}) + self.db.volume_detached(context.elevated(), volume_id) def _copy_image_to_volume(self, context, volume, image_id):