Add volume retype command
Add volume retype to Cinder client. Cinder code: https://review.openstack.org/#/c/44881/ Change-Id: Ied4902da531386f744403962e4a8ddfb7587c4ef
This commit is contained in:

committed by
john-griffith

parent
36a92e1286
commit
58d8a00a57
@@ -360,6 +360,8 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
assert 'force_host_copy' in body[action]
|
||||
elif action == 'os-update_readonly_flag':
|
||||
assert list(body[action]) == ['readonly']
|
||||
elif action == 'os-retype':
|
||||
assert 'new_type' in body[action]
|
||||
else:
|
||||
raise AssertionError("Unexpected action: %s" % action)
|
||||
return (resp, {}, _body)
|
||||
|
@@ -325,7 +325,19 @@ class ShellTest(utils.TestCase):
|
||||
self.assert_called('PUT', '/os-services/disable',
|
||||
{"binary": "cinder-volume", "host": "host"})
|
||||
|
||||
def test_service_disable(self):
|
||||
def test_service_enable(self):
|
||||
self.run_command('service-enable host cinder-volume')
|
||||
self.assert_called('PUT', '/os-services/enable',
|
||||
{"binary": "cinder-volume", "host": "host"})
|
||||
|
||||
def test_retype_with_policy(self):
|
||||
self.run_command('retype 1234 foo --migration-policy=on-demand')
|
||||
expected = {'os-retype': {'new_type': 'foo',
|
||||
'migration_policy': 'on-demand'}}
|
||||
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
||||
|
||||
def test_retype_default_policy(self):
|
||||
self.run_command('retype 1234 foo')
|
||||
expected = {'os-retype': {'new_type': 'foo',
|
||||
'migration_policy': 'never'}}
|
||||
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
||||
|
@@ -109,3 +109,10 @@ class VolumesTest(utils.TestCase):
|
||||
v = cs.volumes.get('1234')
|
||||
cs.volumes.update_readonly_flag(v, True)
|
||||
cs.assert_called('POST', '/volumes/1234/action')
|
||||
|
||||
def test_retype(self):
|
||||
v = cs.volumes.get('1234')
|
||||
cs.volumes.retype(v, 'foo', 'on-demand')
|
||||
cs.assert_called('POST', '/volumes/1234/action',
|
||||
{'os-retype': {'new_type': 'foo',
|
||||
'migration_policy': 'on-demand'}})
|
||||
|
@@ -899,6 +899,19 @@ def do_migrate(cs, args):
|
||||
volume.migrate_volume(args.host, args.force_host_copy)
|
||||
|
||||
|
||||
@utils.arg('volume', metavar='<volume>',
|
||||
help='Name or ID of the volume to retype')
|
||||
@utils.arg('new_type', metavar='<volume-type>', help='New volume type')
|
||||
@utils.arg('--migration-policy', metavar='<never|on-demand>', required=False,
|
||||
choices=['never', 'on-demand'], default='never',
|
||||
help='Policy on migrating the volume during the retype.')
|
||||
@utils.service_type('volumev2')
|
||||
def do_retype(cs, args):
|
||||
"""Change the volume's type."""
|
||||
volume = utils.find_volume(cs, args.volume)
|
||||
volume.retype(args.new_type, args.migration_policy)
|
||||
|
||||
|
||||
@utils.arg('volume', metavar='<volume>',
|
||||
help='Name or ID of the volume to backup.')
|
||||
@utils.arg('--container', metavar='<container>',
|
||||
|
@@ -117,10 +117,9 @@ class Volume(base.Resource):
|
||||
"""Migrate the volume to a new host."""
|
||||
self.manager.migrate_volume(self, host, force_host_copy)
|
||||
|
||||
# def migrate_volume_completion(self, old_volume, new_volume, error):
|
||||
# """Complete the migration of the volume."""
|
||||
# self.manager.migrate_volume_completion(self, old_volume,
|
||||
# new_volume, error)
|
||||
def retype(self, volume_type, policy):
|
||||
"""Change a volume's type."""
|
||||
self.manager.retype(self, volume_type, policy)
|
||||
|
||||
def update_all_metadata(self, metadata):
|
||||
"""Update all metadata of this volume."""
|
||||
@@ -408,3 +407,15 @@ class VolumeManager(base.ManagerWithFind):
|
||||
return self._action('os-update_readonly_flag',
|
||||
base.getid(volume),
|
||||
{'readonly': flag})
|
||||
|
||||
def retype(self, volume, volume_type, policy):
|
||||
"""Change a volume's type.
|
||||
|
||||
:param volume: The :class:`Volume` to retype
|
||||
:param volume_type: New volume type
|
||||
:param policy: Policy for migration during the retype
|
||||
"""
|
||||
return self._action('os-retype',
|
||||
volume,
|
||||
{'new_type': volume_type,
|
||||
'migration_policy': policy})
|
||||
|
Reference in New Issue
Block a user