add disk bus and device type to volume attach

This change adds the optional parameters: disk bus and device type
to the volume-attach command for the V3 API.

DocImpact
Closes-Bug: #1303875

Change-Id: I4fd07726887d08e5b669139b559bdb2c2d21826e
This commit is contained in:
vagrant 2014-06-12 06:45:55 +00:00 committed by melanie witt
parent 37f02bde12
commit 2b54bbc8bb
4 changed files with 44 additions and 4 deletions

View File

@ -211,9 +211,10 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
'create_image': ['name', 'metadata'],
'migrate_live': ['host', 'block_migration', 'disk_over_commit'],
'create_backup': ['name', 'backup_type', 'rotation'],
'attach': ['volume_id', 'device'],
'detach': ['volume_id'],
'swap_volume_attachment': ['old_volume_id', 'new_volume_id']}
body_params_check_superset = {
'attach': ['volume_id', 'device']}
assert len(body.keys()) == 1
action = list(body)[0]
@ -231,6 +232,9 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
if action in body_params_check_exact:
assert set(body[action]) == set(body_params_check_exact[action])
if action in body_params_check_superset:
assert set(body[action]) >= set(body_params_check_superset[action])
if action == 'reboot':
assert body[action]['type'] in ['HARD', 'SOFT']
elif action == 'confirm_resize':
@ -241,7 +245,8 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
if action not in set.union(set(body_is_none_list),
set(body_params_check_exact.keys()),
set(body_param_check_exists.keys())):
set(body_param_check_exists.keys()),
set(body_params_check_superset.keys())):
raise AssertionError("Unexpected server action: %s" % action)
return (resp, _headers, _body)

View File

@ -33,6 +33,23 @@ class VolumesTest(utils.TestCase):
)
self.cs.assert_called('POST', '/servers/1234/action')
def test_attach_server_volume_disk_bus_device_type(self):
volume_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
device = '/dev/vdb'
disk_bus = 'ide'
device_type = 'cdrom'
self.cs.volumes.attach_server_volume(server=1234,
volume_id=volume_id,
device=device,
disk_bus=disk_bus,
device_type=device_type)
body_params = {'volume_id': volume_id,
'device': device,
'disk_bus': disk_bus,
'device_type': device_type}
body = {'attach': body_params}
self.cs.assert_called('POST', '/servers/1234/action', body)
def test_update_server_volume(self):
vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
self.cs.volumes.update_server_volume(

View File

@ -1432,13 +1432,24 @@ def _translate_availability_zone_keys(collection):
@utils.arg('device', metavar='<device>', default=None, nargs='?',
help='Name of the device e.g. /dev/vdb. '
'Use "auto" for autoassign (if supported)')
@utils.arg('disk_bus',
metavar='<disk-bus>',
default=None,
nargs='?',
help='The disk bus e.g. ide of the volume (optional).')
@utils.arg('device_type',
metavar='<device-type>',
default=None,
nargs='?',
help='The device type e.g. cdrom of the volume (optional).')
def do_volume_attach(cs, args):
"""Attach a volume to a server."""
if args.device == 'auto':
args.device = None
cs.volumes.attach_server_volume(_find_server(cs, args.server).id,
args.volume, args.device)
args.volume, args.device, args.disk_bus,
args.device_type)
@utils.arg('server',

View File

@ -24,16 +24,23 @@ class VolumeManager(base.Manager):
Manage :class:`Volume` resources.
"""
def attach_server_volume(self, server, volume_id, device):
def attach_server_volume(self, server, volume_id, device,
disk_bus=None, device_type=None):
"""
Attach a volume identified by the volume ID to the given server ID
:param server: The server (or it's ID)
:param volume_id: The ID of the volume to attach.
:param device: The device name
:param disk_bus: The disk bus of the volume
:param device_type: The device type of the volume
:rtype: :class:`Volume`
"""
body = {'volume_id': volume_id, 'device': device}
if disk_bus:
body['disk_bus'] = disk_bus
if device_type:
body['device_type'] = device_type
return self._action('attach', server, body)
def update_server_volume(self, server, old_volume_id, new_volume_id):