Create Consistency Group from CG Snapshot CLI
This patch addressed the following: * Added a new CLI to support creating a CG from a CG snapshot. cinder consisgroup-create-from-src [--cgsnapshot <cgsnapshot>] [--name <name>] [--description <description>] API patch: https://review.openstack.org/#/c/145952/ Partial-Implements: blueprint consistency-groups-kilo-update Change-Id: I03cce04e1d43ea72fc53a8bf614ba4f969f6e32e
This commit is contained in:
@@ -493,6 +493,12 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
def post_consistencygroups_1234_delete(self, **kw):
|
def post_consistencygroups_1234_delete(self, **kw):
|
||||||
return (202, {}, {})
|
return (202, {}, {})
|
||||||
|
|
||||||
|
def post_consistencygroups_create_from_src(self, **kw):
|
||||||
|
return (200,
|
||||||
|
{},
|
||||||
|
{'consistencygroup': _stub_consistencygroup(
|
||||||
|
id='1234', cgsnapshot_id='1234')})
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cgsnapshots
|
# Cgsnapshots
|
||||||
#
|
#
|
||||||
|
@@ -94,6 +94,21 @@ class ConsistencygroupsTest(utils.TestCase):
|
|||||||
def test_update_consistencygroup_no_props(self):
|
def test_update_consistencygroup_no_props(self):
|
||||||
cs.consistencygroups.update('1234')
|
cs.consistencygroups.update('1234')
|
||||||
|
|
||||||
|
def test_create_consistencygroup_from_src(self):
|
||||||
|
cs.consistencygroups.create_from_src('5678', name='cg')
|
||||||
|
expected = {
|
||||||
|
'consistencygroup-from-src': {
|
||||||
|
'status': 'creating',
|
||||||
|
'description': None,
|
||||||
|
'user_id': None,
|
||||||
|
'name': 'cg',
|
||||||
|
'cgsnapshot_id': '5678',
|
||||||
|
'project_id': None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cs.assert_called('POST', '/consistencygroups/create_from_src',
|
||||||
|
body=expected)
|
||||||
|
|
||||||
def test_list_consistencygroup(self):
|
def test_list_consistencygroup(self):
|
||||||
cs.consistencygroups.list()
|
cs.consistencygroups.list()
|
||||||
cs.assert_called('GET', '/consistencygroups/detail')
|
cs.assert_called('GET', '/consistencygroups/detail')
|
||||||
|
@@ -819,3 +819,26 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.BadRequest,
|
self.assertRaises(exceptions.BadRequest,
|
||||||
self.run_command,
|
self.run_command,
|
||||||
'consisgroup-update 1234')
|
'consisgroup-update 1234')
|
||||||
|
|
||||||
|
def test_consistencygroup_create_from_src(self):
|
||||||
|
self.run_command('consisgroup-create-from-src '
|
||||||
|
'--name cg '
|
||||||
|
'--cgsnapshot 1234')
|
||||||
|
expected = {
|
||||||
|
'consistencygroup-from-src': {
|
||||||
|
'name': 'cg',
|
||||||
|
'cgsnapshot_id': '1234',
|
||||||
|
'description': None,
|
||||||
|
'user_id': None,
|
||||||
|
'project_id': None,
|
||||||
|
'status': 'creating'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.assert_called('POST', '/consistencygroups/create_from_src',
|
||||||
|
expected)
|
||||||
|
|
||||||
|
def test_consistencygroup_create_from_src_bad_request(self):
|
||||||
|
self.assertRaises(exceptions.BadRequest,
|
||||||
|
self.run_command,
|
||||||
|
'consisgroup-create-from-src '
|
||||||
|
'--name cg')
|
||||||
|
@@ -67,6 +67,32 @@ class ConsistencygroupManager(base.ManagerWithFind):
|
|||||||
|
|
||||||
return self._create('/consistencygroups', body, 'consistencygroup')
|
return self._create('/consistencygroups', body, 'consistencygroup')
|
||||||
|
|
||||||
|
def create_from_src(self, cgsnapshot_id, name=None,
|
||||||
|
description=None, user_id=None,
|
||||||
|
project_id=None):
|
||||||
|
"""Creates a consistencygroup from a cgsnapshot.
|
||||||
|
|
||||||
|
:param cgsnapshot_id: UUID of a CGSnapshot
|
||||||
|
:param name: Name of the ConsistencyGroup
|
||||||
|
:param description: Description of the ConsistencyGroup
|
||||||
|
:param user_id: User id derived from context
|
||||||
|
:param project_id: Project id derived from context
|
||||||
|
:rtype: :class:`Consistencygroup`
|
||||||
|
"""
|
||||||
|
body = {'consistencygroup-from-src': {'name': name,
|
||||||
|
'description': description,
|
||||||
|
'cgsnapshot_id': cgsnapshot_id,
|
||||||
|
'user_id': user_id,
|
||||||
|
'project_id': project_id,
|
||||||
|
'status': "creating",
|
||||||
|
}}
|
||||||
|
|
||||||
|
self.run_hooks('modify_body_for_update', body,
|
||||||
|
'consistencygroup-from-src')
|
||||||
|
resp, body = self.api.client.post(
|
||||||
|
"/consistencygroups/create_from_src", body=body)
|
||||||
|
return body['consistencygroup']
|
||||||
|
|
||||||
def get(self, group_id):
|
def get(self, group_id):
|
||||||
"""Get a consistencygroup.
|
"""Get a consistencygroup.
|
||||||
|
|
||||||
|
@@ -1945,6 +1945,32 @@ def do_consisgroup_create(cs, args):
|
|||||||
utils.print_dict(info)
|
utils.print_dict(info)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--cgsnapshot',
|
||||||
|
metavar='<cgsnapshot>',
|
||||||
|
help='Name or ID of a cgsnapshot. Default=None.')
|
||||||
|
@utils.arg('--name',
|
||||||
|
metavar='<name>',
|
||||||
|
help='Name of a consistency group. Default=None.')
|
||||||
|
@utils.arg('--description',
|
||||||
|
metavar='<description>',
|
||||||
|
help='Description of a consistency group. Default=None.')
|
||||||
|
@utils.service_type('volumev2')
|
||||||
|
def do_consisgroup_create_from_src(cs, args):
|
||||||
|
"""Creates a consistency group from a cgsnapshot."""
|
||||||
|
if not args.cgsnapshot:
|
||||||
|
msg = ('Cannot create consistency group because the source '
|
||||||
|
'cgsnapshot is not provided.')
|
||||||
|
raise exceptions.BadRequest(code=400, message=msg)
|
||||||
|
cgsnapshot = _find_cgsnapshot(cs, args.cgsnapshot)
|
||||||
|
info = cs.consistencygroups.create_from_src(
|
||||||
|
cgsnapshot.id,
|
||||||
|
args.name,
|
||||||
|
args.description)
|
||||||
|
|
||||||
|
info.pop('links', None)
|
||||||
|
utils.print_dict(info)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('consistencygroup',
|
@utils.arg('consistencygroup',
|
||||||
metavar='<consistencygroup>', nargs='+',
|
metavar='<consistencygroup>', nargs='+',
|
||||||
help='Name or ID of one or more consistency groups '
|
help='Name or ID of one or more consistency groups '
|
||||||
|
Reference in New Issue
Block a user