Added type description for volume type client
This patch added client handling and unit tests for volume type description: * Added 2 client methods for volume type. default: to get the default volume type update: to upate an existing volume type to update description * Added 2 new command-line operations. type-update (adminitrator only) type-default * type-list should display description. * type-create should have an option for entering the description. The corresponding cinder APIs change volume-type-description: https://review.openstack.org/#/c/131871/ Implements: blueprint volume-type-description Change-Id: I2735d7050d90589d19f45e21096577febdcca8bb
This commit is contained in:
@@ -189,9 +189,11 @@ class Manager(utils.HookableMixin):
|
|||||||
def _delete(self, url):
|
def _delete(self, url):
|
||||||
resp, body = self.api.client.delete(url)
|
resp, body = self.api.client.delete(url)
|
||||||
|
|
||||||
def _update(self, url, body, **kwargs):
|
def _update(self, url, body, response_key=None, **kwargs):
|
||||||
self.run_hooks('modify_body_for_update', body, **kwargs)
|
self.run_hooks('modify_body_for_update', body, **kwargs)
|
||||||
resp, body = self.api.client.put(url, body=body)
|
resp, body = self.api.client.put(url, body=body)
|
||||||
|
if response_key:
|
||||||
|
return self.resource_class(self, body[response_key], loaded=True)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -578,9 +578,13 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
'name': 'test-type-2',
|
'name': 'test-type-2',
|
||||||
'extra_specs': {}}})
|
'extra_specs': {}}})
|
||||||
|
|
||||||
|
def get_types_default(self, **kw):
|
||||||
|
return self.get_types_1()
|
||||||
|
|
||||||
def post_types(self, body, **kw):
|
def post_types(self, body, **kw):
|
||||||
return (202, {}, {'volume_type': {'id': 3,
|
return (202, {}, {'volume_type': {'id': 3,
|
||||||
'name': 'test-type-3',
|
'name': 'test-type-3',
|
||||||
|
'description': 'test_type-3-desc',
|
||||||
'extra_specs': {}}})
|
'extra_specs': {}}})
|
||||||
|
|
||||||
def post_types_1_extra_specs(self, body, **kw):
|
def post_types_1_extra_specs(self, body, **kw):
|
||||||
@@ -593,6 +597,9 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
def delete_types_1(self, **kw):
|
def delete_types_1(self, **kw):
|
||||||
return (202, {}, None)
|
return (202, {}, None)
|
||||||
|
|
||||||
|
def put_types_1(self, **kw):
|
||||||
|
return self.get_types_1()
|
||||||
|
|
||||||
#
|
#
|
||||||
# VolumeEncryptionTypes
|
# VolumeEncryptionTypes
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -33,6 +33,21 @@ class TypesTest(utils.TestCase):
|
|||||||
cs.assert_called('POST', '/types')
|
cs.assert_called('POST', '/types')
|
||||||
self.assertIsInstance(t, volume_types.VolumeType)
|
self.assertIsInstance(t, volume_types.VolumeType)
|
||||||
|
|
||||||
|
def test_update(self):
|
||||||
|
t = cs.volume_types.update('1', 'test_desc_1')
|
||||||
|
cs.assert_called('PUT', '/types/1')
|
||||||
|
self.assertIsInstance(t, volume_types.VolumeType)
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
t = cs.volume_types.get('1')
|
||||||
|
cs.assert_called('GET', '/types/1')
|
||||||
|
self.assertIsInstance(t, volume_types.VolumeType)
|
||||||
|
|
||||||
|
def test_default(self):
|
||||||
|
t = cs.volume_types.default()
|
||||||
|
cs.assert_called('GET', '/types/default')
|
||||||
|
self.assertIsInstance(t, volume_types.VolumeType)
|
||||||
|
|
||||||
def test_set_key(self):
|
def test_set_key(self):
|
||||||
t = cs.volume_types.get(1)
|
t = cs.volume_types.get(1)
|
||||||
t.set_keys({'k': 'v'})
|
t.set_keys({'k': 'v'})
|
||||||
|
|||||||
@@ -696,7 +696,7 @@ def do_snapshot_reset_state(cs, args):
|
|||||||
|
|
||||||
|
|
||||||
def _print_volume_type_list(vtypes):
|
def _print_volume_type_list(vtypes):
|
||||||
utils.print_list(vtypes, ['ID', 'Name'])
|
utils.print_list(vtypes, ['ID', 'Name', 'Description'])
|
||||||
|
|
||||||
|
|
||||||
@utils.service_type('volumev2')
|
@utils.service_type('volumev2')
|
||||||
@@ -706,6 +706,26 @@ def do_type_list(cs, args):
|
|||||||
_print_volume_type_list(vtypes)
|
_print_volume_type_list(vtypes)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.service_type('volumev2')
|
||||||
|
def do_type_default(cs, args):
|
||||||
|
"""List the default volume type."""
|
||||||
|
vtype = cs.volume_types.default()
|
||||||
|
_print_volume_type_list([vtype])
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('id',
|
||||||
|
metavar='<id>',
|
||||||
|
help="ID of the volume type.")
|
||||||
|
@utils.arg('description',
|
||||||
|
metavar='<description>',
|
||||||
|
help="Description of the volume type.")
|
||||||
|
@utils.service_type('volumev2')
|
||||||
|
def do_type_update(cs, args):
|
||||||
|
"""Updates volume type description."""
|
||||||
|
vtype = cs.volume_types.update(args.id, args.description)
|
||||||
|
_print_volume_type_list([vtype])
|
||||||
|
|
||||||
|
|
||||||
@utils.service_type('volumev2')
|
@utils.service_type('volumev2')
|
||||||
def do_extra_specs_list(cs, args):
|
def do_extra_specs_list(cs, args):
|
||||||
"""Lists current volume types and extra specs."""
|
"""Lists current volume types and extra specs."""
|
||||||
@@ -716,10 +736,13 @@ def do_extra_specs_list(cs, args):
|
|||||||
@utils.arg('name',
|
@utils.arg('name',
|
||||||
metavar='<name>',
|
metavar='<name>',
|
||||||
help="Name of new volume type.")
|
help="Name of new volume type.")
|
||||||
|
@utils.arg('--description',
|
||||||
|
metavar='<description>',
|
||||||
|
help="Description of new volume type.")
|
||||||
@utils.service_type('volumev2')
|
@utils.service_type('volumev2')
|
||||||
def do_type_create(cs, args):
|
def do_type_create(cs, args):
|
||||||
"""Creates a volume type."""
|
"""Creates a volume type."""
|
||||||
vtype = cs.volume_types.create(args.name)
|
vtype = cs.volume_types.create(args.name, args.description)
|
||||||
_print_volume_type_list([vtype])
|
_print_volume_type_list([vtype])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,13 @@ class VolumeTypeManager(base.ManagerWithFind):
|
|||||||
"""
|
"""
|
||||||
return self._get("/types/%s" % base.getid(volume_type), "volume_type")
|
return self._get("/types/%s" % base.getid(volume_type), "volume_type")
|
||||||
|
|
||||||
|
def default(self):
|
||||||
|
"""Get the default volume type.
|
||||||
|
|
||||||
|
:rtype: :class:`VolumeType`
|
||||||
|
"""
|
||||||
|
return self._get("/types/default", "volume_type")
|
||||||
|
|
||||||
def delete(self, volume_type):
|
def delete(self, volume_type):
|
||||||
"""Deletes a specific volume_type.
|
"""Deletes a specific volume_type.
|
||||||
|
|
||||||
@@ -92,17 +99,36 @@ class VolumeTypeManager(base.ManagerWithFind):
|
|||||||
"""
|
"""
|
||||||
self._delete("/types/%s" % base.getid(volume_type))
|
self._delete("/types/%s" % base.getid(volume_type))
|
||||||
|
|
||||||
def create(self, name):
|
def create(self, name, description=None):
|
||||||
"""Creates a volume type.
|
"""Creates a volume type.
|
||||||
|
|
||||||
:param name: Descriptive name of the volume type
|
:param name: Descriptive name of the volume type
|
||||||
|
:param description: Description of the the volume type
|
||||||
:rtype: :class:`VolumeType`
|
:rtype: :class:`VolumeType`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"volume_type": {
|
"volume_type": {
|
||||||
"name": name,
|
"name": name,
|
||||||
|
"description": description
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self._create("/types", body, "volume_type")
|
return self._create("/types", body, "volume_type")
|
||||||
|
|
||||||
|
def update(self, volume_type, description):
|
||||||
|
"""Update the description for a volume type.
|
||||||
|
|
||||||
|
:param volume_type: The ID of the :class:`VolumeType` to update.
|
||||||
|
:param description: Description of the the volume type.
|
||||||
|
:rtype: :class:`VolumeType`
|
||||||
|
"""
|
||||||
|
|
||||||
|
body = {
|
||||||
|
"volume_type": {
|
||||||
|
"description": description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self._update("/types/%s" % base.getid(volume_type),
|
||||||
|
body, response_key="volume_type")
|
||||||
|
|||||||
Reference in New Issue
Block a user