diff options
| author | John Griffith <john.griffith8@gmail.com> | 2018-04-06 12:51:24 -0600 |
|---|---|---|
| committer | Sean McGinnis <sean.mcginnis@gmail.com> | 2018-07-17 15:58:46 -0500 |
| commit | 90727008876ef35d3135d494aeb45bdf2f63e8fc (patch) | |
| tree | 876df9b96f2425aef73b44b9c1e767d12031c3c1 /cinderclient | |
| parent | 8f933a9a341cec9cf87b4a4d3bf7da80b24c18ef (diff) | |
| download | python-cinderclient-90727008876ef35d3135d494aeb45bdf2f63e8fc.tar.gz | |
Add mode option to attachment-create
We introduce a mode option in attachment-create starting with
microversion 3.54. The mode option is the new/preferred way of
setting ro mode (as opposed to admin-metadata).
This patch adds the support for the mode option to the client for
endpoints that support 3.54.
Depends-on: https://review.openstack.org/532702/
Change-Id: I22cfddd0192c4a72b8f844f23d1fa51b96c57e06
Diffstat (limited to 'cinderclient')
| -rw-r--r-- | cinderclient/tests/unit/v3/test_attachments.py | 3 | ||||
| -rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 43 | ||||
| -rw-r--r-- | cinderclient/v3/attachments.py | 5 | ||||
| -rw-r--r-- | cinderclient/v3/shell.py | 12 |
4 files changed, 60 insertions, 3 deletions
diff --git a/cinderclient/tests/unit/v3/test_attachments.py b/cinderclient/tests/unit/v3/test_attachments.py index 2ac6486..1802334 100644 --- a/cinderclient/tests/unit/v3/test_attachments.py +++ b/cinderclient/tests/unit/v3/test_attachments.py @@ -26,7 +26,8 @@ class AttachmentsTest(utils.TestCase): att = cs.attachments.create( 'e84fda45-4de4-4ce4-8f39-fc9d3b0aa05e', {}, - '557ad76c-ce54-40a3-9e91-c40d21665cc3') + '557ad76c-ce54-40a3-9e91-c40d21665cc3', + 'null') cs.assert_called('POST', '/attachments') self.assertEqual(fakes.fake_attachment['attachment'], att) diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 43fb097..cdf1f36 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -324,6 +324,49 @@ class ShellTest(utils.TestCase): self.assertTrue(mock_find_volume.called) self.assert_called('POST', '/attachments', body=expected) + @ddt.data({'cmd': '1234 1233', + 'body': {'instance_uuid': '1233', + 'connector': {}, + 'volume_uuid': '1234', + 'mode': 'ro'}}, + {'cmd': '1234 1233 ' + '--connect True ' + '--ip 10.23.12.23 --host server01 ' + '--platform x86_xx ' + '--ostype 123 ' + '--multipath true ' + '--mountpoint /123 ' + '--initiator aabbccdd', + 'body': {'instance_uuid': '1233', + 'connector': {'ip': '10.23.12.23', + 'host': 'server01', + 'os_type': '123', + 'multipath': 'true', + 'mountpoint': '/123', + 'initiator': 'aabbccdd', + 'platform': 'x86_xx'}, + 'volume_uuid': '1234', + 'mode': 'ro'}}, + {'cmd': 'abc 1233', + 'body': {'instance_uuid': '1233', + 'connector': {}, + 'volume_uuid': '1234', + 'mode': 'ro'}}) + @mock.patch('cinderclient.utils.find_resource') + @ddt.unpack + def test_attachment_create_with_mode(self, mock_find_volume, cmd, body): + mock_find_volume.return_value = volumes.Volume(self, + {'id': '1234'}, + loaded=True) + command = ('--os-volume-api-version 3.54 ' + 'attachment-create ' + '--mode ro ') + command += cmd + self.run_command(command) + expected = {'attachment': body} + self.assertTrue(mock_find_volume.called) + self.assert_called('POST', '/attachments', body=expected) + @mock.patch.object(volumes.VolumeManager, 'findall') def test_attachment_create_duplicate_name_vol(self, mock_findall): found = [volumes.Volume(self, {'id': '7654', 'name': 'abc'}, diff --git a/cinderclient/v3/attachments.py b/cinderclient/v3/attachments.py index e18bf98..a0732a3 100644 --- a/cinderclient/v3/attachments.py +++ b/cinderclient/v3/attachments.py @@ -27,11 +27,14 @@ class VolumeAttachmentManager(base.ManagerWithFind): resource_class = VolumeAttachment @api_versions.wraps('3.27') - def create(self, volume_id, connector, instance_id): + def create(self, volume_id, connector, instance_id, mode='null'): """Create a attachment for specified volume.""" body = {'attachment': {'volume_uuid': volume_id, 'instance_uuid': instance_id, 'connector': connector}} + if self.api_version >= api_versions.APIVersion("3.54"): + if mode and mode != 'null': + body['attachment']['mode'] = mode retval = self._create('/attachments', body, 'attachment') return retval.to_dict() diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index fc74399..d5114e1 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -2164,6 +2164,13 @@ def do_attachment_show(cs, args): metavar='<mountpoint>', default=None, help='Mountpoint volume will be attached at. Default=None.') +@utils.arg('--mode', + metavar='<mode>', + default='null', + start_version='3.54', + help='Mode of attachment, rw, ro and null, where null ' + 'indicates we want to honor any existing ' + 'admin-metadata settings. Default=null.') def do_attachment_create(cs, args): """Create an attachment for a cinder volume.""" @@ -2178,9 +2185,12 @@ def do_attachment_create(cs, args): 'multipath': args.multipath, 'mountpoint': args.mountpoint} volume = utils.find_volume(cs, args.volume) + mode = getattr(args, 'mode', 'null') attachment = cs.attachments.create(volume.id, connector, - args.server_id) + args.server_id, + mode) + connector_dict = attachment.pop('connection_info', None) utils.print_dict(attachment) if connector_dict: |
