Skip to content

Commit 303cb47

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add --attached / --detached parameter to volume set"
2 parents 3599ebe + e776a4f commit 303cb47

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

doc/source/cli/command-objects/volume.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Set volume properties
262262
[--property <key=value> [...] ]
263263
[--image-property <key=value> [...] ]
264264
[--state <state>]
265+
[--attached | --detached ]
265266
[--type <volume-type>]
266267
[--retype-policy <retype-policy>]
267268
[--bootable | --non-bootable]
@@ -341,6 +342,22 @@ Set volume properties
341342
342343
*Volume version 2 only*
343344
345+
.. option:: --attached
346+
347+
Set volume attachment status to "attached" (admin only)
348+
(This option simply changes the state of the volume in the database with
349+
no regard to actual status, exercise caution when using)
350+
351+
*Volume version 2 only*
352+
353+
.. option:: --deattach
354+
355+
Set volume attachment status to "detached" (admin only)
356+
(This option simply changes the state of the volume in the database with
357+
no regard to actual status, exercise caution when using)
358+
359+
*Volume version 2 only*
360+
344361
.. _volume_set-volume:
345362
.. describe:: <volume>
346363

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,42 @@ def test_volume_set_state_failed(self):
13271327
self.volumes_mock.reset_state.assert_called_with(
13281328
self.new_volume.id, 'error')
13291329

1330+
def test_volume_set_attached(self):
1331+
arglist = [
1332+
'--attached',
1333+
self.new_volume.id
1334+
]
1335+
verifylist = [
1336+
('attached', True),
1337+
('detached', False),
1338+
('volume', self.new_volume.id)
1339+
]
1340+
1341+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1342+
1343+
result = self.cmd.take_action(parsed_args)
1344+
self.volumes_mock.reset_state.assert_called_with(
1345+
self.new_volume.id, attach_status='attached', state=None)
1346+
self.assertIsNone(result)
1347+
1348+
def test_volume_set_detached(self):
1349+
arglist = [
1350+
'--detached',
1351+
self.new_volume.id
1352+
]
1353+
verifylist = [
1354+
('attached', False),
1355+
('detached', True),
1356+
('volume', self.new_volume.id)
1357+
]
1358+
1359+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1360+
1361+
result = self.cmd.take_action(parsed_args)
1362+
self.volumes_mock.reset_state.assert_called_with(
1363+
self.new_volume.id, attach_status='detached', state=None)
1364+
self.assertIsNone(result)
1365+
13301366
def test_volume_set_bootable(self):
13311367
arglist = [
13321368
['--bootable', self.new_volume.id],

openstackclient/volume/v2/volume.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,25 @@ def get_parser(self, prog_name):
559559
'in the database with no regard to actual status, '
560560
'exercise caution when using)'),
561561
)
562+
attached_group = parser.add_mutually_exclusive_group()
563+
attached_group.add_argument(
564+
"--attached",
565+
action="store_true",
566+
help=_('Set volume attachment status to "attached" '
567+
'(admin only) '
568+
'(This option simply changes the state of the volume '
569+
'in the database with no regard to actual status, '
570+
'exercise caution when using)'),
571+
)
572+
attached_group.add_argument(
573+
"--detached",
574+
action="store_true",
575+
help=_('Set volume attachment status to "detached" '
576+
'(admin only) '
577+
'(This option simply changes the state of the volume '
578+
'in the database with no regard to actual status, '
579+
'exercise caution when using)'),
580+
)
562581
parser.add_argument(
563582
'--type',
564583
metavar='<volume-type>',
@@ -645,6 +664,22 @@ def take_action(self, parsed_args):
645664
except Exception as e:
646665
LOG.error(_("Failed to set volume state: %s"), e)
647666
result += 1
667+
if parsed_args.attached:
668+
try:
669+
volume_client.volumes.reset_state(
670+
volume.id, state=None,
671+
attach_status="attached")
672+
except Exception as e:
673+
LOG.error(_("Failed to set volume attach-status: %s"), e)
674+
result += 1
675+
if parsed_args.detached:
676+
try:
677+
volume_client.volumes.reset_state(
678+
volume.id, state=None,
679+
attach_status="detached")
680+
except Exception as e:
681+
LOG.error(_("Failed to set volume attach-status: %s"), e)
682+
result += 1
648683
if parsed_args.bootable or parsed_args.non_bootable:
649684
try:
650685
volume_client.volumes.set_bootable(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add ``--attached`` and ``--detached`` options to ``volume set`` command to set the
5+
volume status in the database. This is the functional equivalent to
6+
``cinder reset-state --attach-status``.
7+
[`bug 1745699 <https://bugs.launchpad.net/python-openstackclient/+bug/1745699>`_

0 commit comments

Comments
 (0)