Skip to content

Instantly share code, notes, and snippets.

@WaltHP
Created December 9, 2015 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaltHP/7676c5c6d23c8b84e247 to your computer and use it in GitHub Desktop.
Save WaltHP/7676c5c6d23c8b84e247 to your computer and use it in GitHub Desktop.
diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py
index c6e0c71..7bc7c2a 100644
--- a/cinder/api/contrib/volume_actions.py
+++ b/cinder/api/contrib/volume_actions.py
@@ -98,15 +98,16 @@ class VolumeActionsController(wsgi.Controller):
else:
mode = 'rw'
- if instance_uuid and host_name:
- msg = _("Invalid request to attach volume to an "
- "instance %(instance_uuid)s and a "
- "host %(host_name)s simultaneously") % {
- 'instance_uuid': instance_uuid,
- 'host_name': host_name,
- }
- raise webob.exc.HTTPBadRequest(explanation=msg)
- elif instance_uuid is None and host_name is None:
+ #if instance_uuid and host_name:
+ # msg = _("Invalid request to attach volume to an "
+ # "instance %(instance_uuid)s and a "
+ # "host %(host_name)s simultaneously") % {
+ # 'instance_uuid': instance_uuid,
+ # 'host_name': host_name,
+ # }
+ # raise webob.exc.HTTPBadRequest(explanation=msg)
+ #elif instance_uuid is None and host_name is None:
+ if instance_uuid is None and host_name is None:
msg = _("Invalid request to attach volume to an invalid target")
raise webob.exc.HTTPBadRequest(explanation=msg)
diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py
index 1cfa322..ebf4372 100644
--- a/cinder/volume/drivers/lvm.py
+++ b/cinder/volume/drivers/lvm.py
@@ -35,6 +35,10 @@ from cinder import utils
from cinder.volume import driver
from cinder.volume import utils as volutils
+
+from cinder import context
+from cinder.db.sqlalchemy import api
+
LOG = logging.getLogger(__name__)
# FIXME(jdg): We'll put the lvm_ prefix back on these when we
@@ -744,5 +748,24 @@ class LVMVolumeDriver(driver.VolumeDriver):
return self.target_driver.validate_connector(connector)
def terminate_connection(self, volume, connector, **kwargs):
+ LOG.warning("terminate for %s" % volume['id'])
+ LOG.warning("connector %s" % connector)
+ host = connector['host']
+ attaches = volume.volume_attachment
+ host_attaches = 0
+ for attach in attaches:
+ if host in attach.attached_host:
+ host_attaches = host_attaches + 1
+ LOG.warning("attachment %s" % vars(attach))
+
+ if host_attaches == 1:
+ # we can safely remove
+ LOG.warning("We can safely remote the target")
+ else:
+ LOG.warning("There are %s attaches still on host %s" %
+ (host_attaches, host))
+
+ #LOG.warning("vol %s attachments %s" %
+ # (volume['id'], volume.volume_attachment))
return self.target_driver.terminate_connection(volume, connector,
**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment