diff options
| author | zhangbailin <zhangbailin@inspur.com> | 2019-07-31 12:24:04 +0800 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2019-11-19 21:07:20 +0000 |
| commit | 874a726f522dae3a08832f32230e2590a787d45c (patch) | |
| tree | 8faadf72d1f59fad6108f573046157993f257e9c /openstackclient/compute | |
| parent | c6a171f0106714bc42045bcfdc308fe99ba6a275 (diff) | |
| download | python-openstackclient-874a726f522dae3a08832f32230e2590a787d45c.tar.gz | |
Microversion 2.79: Add delete_on_termination to volume-attach API
Added ``--disable-delete-on-termination`` and
``--enable-delete-on-termination`` options to the
``openstack server add volume`` command that enables users to mark
whether to delete the attached volume when the server is destroyed.
Depends-On: https://review.opendev.org/#/c/681267/
Part of blueprint support-delete-on-termination-in-server-attach-volume
Change-Id: I6b5cd54b82a1135335a71b9768a1a2c2012f755b
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/server.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index fb7596a9..414abb62 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -446,6 +446,21 @@ class AddServerVolume(command.Command): metavar='<device>', help=_('Server internal device name for volume'), ) + termination_group = parser.add_mutually_exclusive_group() + termination_group.add_argument( + '--enable-delete-on-termination', + action='store_true', + help=_("Specify if the attached volume should be deleted when " + "the server is destroyed. (Supported with " + "``--os-compute-api-version`` 2.79 or greater.)"), + ) + termination_group.add_argument( + '--disable-delete-on-termination', + action='store_true', + help=_("Specify if the attached volume should not be deleted " + "when the server is destroyed. (Supported with " + "``--os-compute-api-version`` 2.79 or greater.)"), + ) return parser def take_action(self, parsed_args): @@ -461,10 +476,34 @@ class AddServerVolume(command.Command): parsed_args.volume, ) + support_set_delete_on_termination = (compute_client.api_version >= + api_versions.APIVersion('2.79')) + + if not support_set_delete_on_termination: + if parsed_args.enable_delete_on_termination: + msg = _('--os-compute-api-version 2.79 or greater ' + 'is required to support the ' + '--enable-delete-on-termination option.') + raise exceptions.CommandError(msg) + if parsed_args.disable_delete_on_termination: + msg = _('--os-compute-api-version 2.79 or greater ' + 'is required to support the ' + '--disable-delete-on-termination option.') + raise exceptions.CommandError(msg) + + kwargs = { + "device": parsed_args.device + } + + if parsed_args.enable_delete_on_termination: + kwargs['delete_on_termination'] = True + if parsed_args.disable_delete_on_termination: + kwargs['delete_on_termination'] = False + compute_client.volumes.create_server_volume( server.id, volume.id, - parsed_args.device, + **kwargs ) |
