]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Call driver for attach/detach_volume.
authorCory Stone <corystone@gmail.com>
Fri, 17 Aug 2012 14:18:52 +0000 (09:18 -0500)
committerCory Stone <corystone@gmail.com>
Fri, 17 Aug 2012 14:18:52 +0000 (09:18 -0500)
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

cinder/volume/driver.py
cinder/volume/manager.py

index 177d413a400e8163d0ec26d3f207bc03a57bc76e..bcc1b3b2fe1927f79eb96329d2242d5d1c1fe265 100644 (file)
@@ -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."""
index eee3d86317ae27c17d3afc836da642fa8c004b84..2ba2d0ffd6f4825290c3c5cac45c2d0ef96c4a90 100644 (file)
@@ -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):