Adding Read-Only volume attaching support to Cinder client
Adding mode argument to volume manager attach function. Allow Nova using read-write or read-only mode to attach a volume to an instance. blueprint read-only-volumes Change-Id: Ib20c7802304d83f4aafef522171ebd47f672d883 Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
This commit is contained in:
@@ -321,6 +321,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
action = list(body)[0]
|
||||
if action == 'os-attach':
|
||||
assert sorted(list(body[action])) == ['instance_uuid',
|
||||
'mode',
|
||||
'mountpoint']
|
||||
elif action == 'os-detach':
|
||||
assert body[action] is None
|
||||
|
@@ -35,7 +35,7 @@ class VolumesTest(utils.TestCase):
|
||||
|
||||
def test_attach(self):
|
||||
v = cs.volumes.get('1234')
|
||||
cs.volumes.attach(v, 1, '/dev/vdc')
|
||||
cs.volumes.attach(v, 1, '/dev/vdc', mode='rw')
|
||||
cs.assert_called('POST', '/volumes/1234/action')
|
||||
|
||||
def test_detach(self):
|
||||
|
@@ -328,6 +328,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
action = list(body)[0]
|
||||
if action == 'os-attach':
|
||||
assert sorted(list(body[action])) == ['instance_uuid',
|
||||
'mode',
|
||||
'mountpoint']
|
||||
elif action == 'os-detach':
|
||||
assert body[action] is None
|
||||
|
@@ -38,7 +38,7 @@ class VolumesTest(utils.TestCase):
|
||||
|
||||
def test_attach(self):
|
||||
v = cs.volumes.get('1234')
|
||||
cs.volumes.attach(v, 1, '/dev/vdc')
|
||||
cs.volumes.attach(v, 1, '/dev/vdc', mode='ro')
|
||||
cs.assert_called('POST', '/volumes/1234/action')
|
||||
|
||||
def test_detach(self):
|
||||
|
@@ -38,13 +38,14 @@ class Volume(base.Resource):
|
||||
"""Update the display_name or display_description for this volume."""
|
||||
self.manager.update(self, **kwargs)
|
||||
|
||||
def attach(self, instance_uuid, mountpoint):
|
||||
def attach(self, instance_uuid, mountpoint, mode='rw'):
|
||||
"""Set attachment metadata.
|
||||
|
||||
:param instance_uuid: uuid of the attaching instance.
|
||||
:param mountpoint: mountpoint on the attaching instance.
|
||||
:param mode: the access mode
|
||||
"""
|
||||
return self.manager.attach(self, instance_uuid, mountpoint)
|
||||
return self.manager.attach(self, instance_uuid, mountpoint, mode)
|
||||
|
||||
def detach(self):
|
||||
"""Clear attachment metadata."""
|
||||
@@ -240,7 +241,7 @@ class VolumeManager(base.ManagerWithFind):
|
||||
url = '/volumes/%s/action' % base.getid(volume)
|
||||
return self.api.client.post(url, body=body)
|
||||
|
||||
def attach(self, volume, instance_uuid, mountpoint):
|
||||
def attach(self, volume, instance_uuid, mountpoint, mode='rw'):
|
||||
"""
|
||||
Set attachment metadata.
|
||||
|
||||
@@ -248,11 +249,13 @@ class VolumeManager(base.ManagerWithFind):
|
||||
you would like to attach.
|
||||
:param instance_uuid: uuid of the attaching instance.
|
||||
:param mountpoint: mountpoint on the attaching instance.
|
||||
:param mode: the access mode.
|
||||
"""
|
||||
return self._action('os-attach',
|
||||
volume,
|
||||
{'instance_uuid': instance_uuid,
|
||||
'mountpoint': mountpoint})
|
||||
'mountpoint': mountpoint,
|
||||
'mode': mode})
|
||||
|
||||
def detach(self, volume):
|
||||
"""
|
||||
|
@@ -37,13 +37,14 @@ class Volume(base.Resource):
|
||||
"""Update the name or description for this volume."""
|
||||
self.manager.update(self, **kwargs)
|
||||
|
||||
def attach(self, instance_uuid, mountpoint):
|
||||
def attach(self, instance_uuid, mountpoint, mode='rw'):
|
||||
"""Set attachment metadata.
|
||||
|
||||
:param instance_uuid: uuid of the attaching instance.
|
||||
:param mountpoint: mountpoint on the attaching instance.
|
||||
:param mode: the access mode.
|
||||
"""
|
||||
return self.manager.attach(self, instance_uuid, mountpoint)
|
||||
return self.manager.attach(self, instance_uuid, mountpoint, mode)
|
||||
|
||||
def detach(self):
|
||||
"""Clear attachment metadata."""
|
||||
@@ -233,18 +234,20 @@ class VolumeManager(base.ManagerWithFind):
|
||||
url = '/volumes/%s/action' % base.getid(volume)
|
||||
return self.api.client.post(url, body=body)
|
||||
|
||||
def attach(self, volume, instance_uuid, mountpoint):
|
||||
def attach(self, volume, instance_uuid, mountpoint, mode='rw'):
|
||||
"""Set attachment metadata.
|
||||
|
||||
:param volume: The :class:`Volume` (or its ID)
|
||||
you would like to attach.
|
||||
:param instance_uuid: uuid of the attaching instance.
|
||||
:param mountpoint: mountpoint on the attaching instance.
|
||||
:param mode: the access mode.
|
||||
"""
|
||||
return self._action('os-attach',
|
||||
volume,
|
||||
{'instance_uuid': instance_uuid,
|
||||
'mountpoint': mountpoint})
|
||||
'mountpoint': mountpoint,
|
||||
'mode': mode})
|
||||
|
||||
def detach(self, volume):
|
||||
"""Clear attachment metadata.
|
||||
|
Reference in New Issue
Block a user