summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCory Stone <corystone@gmail.com>2012-08-17 09:18:52 -0500
committerMark McLoughlin <markmc@redhat.com>2012-09-07 14:39:07 +0100
commit6fba30c8a979e2d85b5bcc4687f2ba00d2af329e (patch)
treec2d5f5ee10c3bb057dfe92c5dfa33ce888b1bf08
parent37cc45b8fdaa199b248a7ef5f683d514733b8387 (diff)
downloadnova-6fba30c8a979e2d85b5bcc4687f2ba00d2af329e.tar.gz
nova-6fba30c8a979e2d85b5bcc4687f2ba00d2af329e.tar.xz
nova-6fba30c8a979e2d85b5bcc4687f2ba00d2af329e.zip
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. (cherry picked from cinder commit 17538890) Change-Id: I084c2d09a1871fa158312f9ba479abb474da1d28
-rw-r--r--nova/volume/driver.py8
-rw-r--r--nova/volume/manager.py19
2 files changed, 27 insertions, 0 deletions
diff --git a/nova/volume/driver.py b/nova/volume/driver.py
index d03ad7cdc..f8562430e 100644
--- a/nova/volume/driver.py
+++ b/nova/volume/driver.py
@@ -239,6 +239,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/nova/volume/manager.py b/nova/volume/manager.py
index a45ae0d65..920494f42 100644
--- a/nova/volume/manager.py
+++ b/nova/volume/manager.py
@@ -262,6 +262,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,
volume_id,
instance_uuid,
@@ -270,6 +281,14 @@ class VolumeManager(manager.SchedulerDependentManager):
def detach_volume(self, context, volume_id):
"""Updates db to show volume is detached"""
# TODO(vish): refactor this into a more general "unreserve"
+ 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, volume_id)
def initialize_connection(self, context, volume_id, connector):