diff options
| -rw-r--r-- | nova/volume/driver.py | 8 | ||||
| -rw-r--r-- | nova/volume/manager.py | 19 |
2 files changed, 27 insertions, 0 deletions
diff --git a/nova/volume/driver.py b/nova/volume/driver.py index 8aa7fd595..bc577db26 100644 --- a/nova/volume/driver.py +++ b/nova/volume/driver.py @@ -240,6 +240,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 eed73e212..77f4aee23 100644 --- a/nova/volume/manager.py +++ b/nova/volume/manager.py @@ -263,6 +263,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, @@ -271,6 +282,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): |
