From 6fba30c8a979e2d85b5bcc4687f2ba00d2af329e Mon Sep 17 00:00:00 2001 From: Cory Stone Date: Fri, 17 Aug 2012 09:18:52 -0500 Subject: 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 --- nova/volume/driver.py | 8 ++++++++ nova/volume/manager.py | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'nova/volume') 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): -- cgit