Skip to content

Commit

Permalink
Call driver for attach/detach_volume.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
corystone committed Aug 17, 2012
1 parent d2babbf commit 1753889
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cinder/volume/driver.py
Expand Up @@ -234,6 +234,14 @@ def terminate_connection(self, volume, connector):
"""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."""
Expand Down
19 changes: 19 additions & 0 deletions cinder/volume/manager.py
Expand Up @@ -257,6 +257,17 @@ def attach_volume(self, context, volume_id, instance_uuid, mountpoint):
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,
Expand All @@ -266,6 +277,14 @@ def detach_volume(self, context, volume_id):
"""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):
Expand Down

0 comments on commit 1753889

Please sign in to comment.