Add "--remote-source" option to "volume snapshot create" command
Add "--remote-source" option to "volume snapshot create" command to support creating snapshot from an existing remote snapshot in volume v2 (v2 only), also add the doc, unit tests and release note. Change-Id: I9e5fad4f0db5b44d528eb6b930edbc816e392c3a Implements: bp cinder-command-support Closes-Bug: #1618676 Co-Authored-By: Sheel Rana <ranasheel2000@gmail.com>
This commit is contained in:
parent
29587eaa66
commit
7357b24d3a
@ -17,6 +17,7 @@ Create new volume snapshot
|
|||||||
[--description <description>]
|
[--description <description>]
|
||||||
[--force]
|
[--force]
|
||||||
[--property <key=value> [...] ]
|
[--property <key=value> [...] ]
|
||||||
|
[--remote-source <key=value> [...]]
|
||||||
<snapshot-name>
|
<snapshot-name>
|
||||||
|
|
||||||
.. option:: --volume <volume>
|
.. option:: --volume <volume>
|
||||||
@ -37,6 +38,14 @@ Create new volume snapshot
|
|||||||
|
|
||||||
*Volume version 2 only*
|
*Volume version 2 only*
|
||||||
|
|
||||||
|
.. option:: --remote-source <key=value>
|
||||||
|
|
||||||
|
The attribute(s) of the exsiting remote volume snapshot
|
||||||
|
(admin required) (repeat option to specify multiple attributes)
|
||||||
|
e.g.: '--remote-source source-name=test_name --remote-source source-id=test_id'
|
||||||
|
|
||||||
|
*Volume version 2 only*
|
||||||
|
|
||||||
.. _volume_snapshot_create-snapshot-name:
|
.. _volume_snapshot_create-snapshot-name:
|
||||||
.. describe:: <snapshot-name>
|
.. describe:: <snapshot-name>
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ class TestSnapshotCreate(TestSnapshot):
|
|||||||
|
|
||||||
self.volumes_mock.get.return_value = self.volume
|
self.volumes_mock.get.return_value = self.volume
|
||||||
self.snapshots_mock.create.return_value = self.new_snapshot
|
self.snapshots_mock.create.return_value = self.new_snapshot
|
||||||
|
self.snapshots_mock.manage.return_value = self.new_snapshot
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = volume_snapshot.CreateVolumeSnapshot(self.app, None)
|
self.cmd = volume_snapshot.CreateVolumeSnapshot(self.app, None)
|
||||||
|
|
||||||
@ -152,6 +153,33 @@ class TestSnapshotCreate(TestSnapshot):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
|
def test_snapshot_create_without_remote_source(self):
|
||||||
|
arglist = [
|
||||||
|
'--remote-source', 'source-name=test_source_name',
|
||||||
|
'--remote-source', 'source-id=test_source_id',
|
||||||
|
'--volume', self.new_snapshot.volume_id,
|
||||||
|
]
|
||||||
|
ref_dict = {'source-name': 'test_source_name',
|
||||||
|
'source-id': 'test_source_id'}
|
||||||
|
verifylist = [
|
||||||
|
('remote_source', ref_dict),
|
||||||
|
('volume', self.new_snapshot.volume_id),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.snapshots_mock.manage.assert_called_with(
|
||||||
|
volume_id=self.new_snapshot.volume_id,
|
||||||
|
ref=ref_dict,
|
||||||
|
name=None,
|
||||||
|
description=None,
|
||||||
|
metadata=None,
|
||||||
|
)
|
||||||
|
self.snapshots_mock.create.assert_not_called()
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
|
|
||||||
class TestSnapshotDelete(TestSnapshot):
|
class TestSnapshotDelete(TestSnapshot):
|
||||||
|
|
||||||
|
@ -65,6 +65,15 @@ class CreateVolumeSnapshot(command.ShowOne):
|
|||||||
help=_("Set a property to this snapshot "
|
help=_("Set a property to this snapshot "
|
||||||
"(repeat option to set multiple properties)"),
|
"(repeat option to set multiple properties)"),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--remote-source",
|
||||||
|
metavar="<key=value>",
|
||||||
|
action=parseractions.KeyValueAction,
|
||||||
|
help=_("The attribute(s) of the exsiting remote volume snapshot "
|
||||||
|
"(admin required) (repeat option to specify multiple "
|
||||||
|
"attributes) e.g.: '--remote-source source-name=test_name "
|
||||||
|
"--remote-source source-id=test_id'"),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -74,6 +83,22 @@ class CreateVolumeSnapshot(command.ShowOne):
|
|||||||
volume = parsed_args.snapshot_name
|
volume = parsed_args.snapshot_name
|
||||||
volume_id = utils.find_resource(
|
volume_id = utils.find_resource(
|
||||||
volume_client.volumes, volume).id
|
volume_client.volumes, volume).id
|
||||||
|
if parsed_args.remote_source:
|
||||||
|
# Create a new snapshot from an existing remote snapshot source
|
||||||
|
if parsed_args.force:
|
||||||
|
msg = (_("'--force' option will not work when you create "
|
||||||
|
"new volume snapshot from an existing remote "
|
||||||
|
"volume snapshot"))
|
||||||
|
LOG.warning(msg)
|
||||||
|
snapshot = volume_client.volume_snapshots.manage(
|
||||||
|
volume_id=volume_id,
|
||||||
|
ref=parsed_args.remote_source,
|
||||||
|
name=parsed_args.snapshot_name,
|
||||||
|
description=parsed_args.description,
|
||||||
|
metadata=parsed_args.property,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# create a new snapshot from scratch
|
||||||
snapshot = volume_client.volume_snapshots.create(
|
snapshot = volume_client.volume_snapshots.create(
|
||||||
volume_id,
|
volume_id,
|
||||||
force=parsed_args.force,
|
force=parsed_args.force,
|
||||||
|
5
releasenotes/notes/bug-1618676-04ff0f335b670567.yaml
Normal file
5
releasenotes/notes/bug-1618676-04ff0f335b670567.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add ``--remote-source`` option to ``volume snapshot create`` command to support
|
||||||
|
creating volume snapshot from an existing remote volume snapshot in volume v2.
|
||||||
|
[Bug `1618676 <https://bugs.launchpad.net/python-openstackclient/+bug/1618676>`_]
|
Loading…
Reference in New Issue
Block a user