Fix reservation_id not supported by Nova API

Nova API accepts "return_reservation_id" instead of "reservation_id" when
creating instances [1]. This patch fixed that.

[1] https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/schemas/multiple_create.py#L19

Change-Id: Ie58248aa1cd981b877c7e592db698faffcd01d9a
Closes-bug: #1693818
This commit is contained in:
Jeremy Liu 2017-05-26 22:54:15 +08:00 committed by yushangbin
parent 0fe136a9e0
commit da44174c54
4 changed files with 35 additions and 7 deletions

View File

@ -417,6 +417,9 @@ class V1(Base):
if 'personality' in body['server']:
for pfile in body['server']['personality']:
fakes.assert_has_keys(pfile, required=['path', 'contents'])
if ('return_reservation_id' in body['server'].keys() and
body['server']['return_reservation_id']):
return {'reservation_id': 'r-3fhpjulh'}
if body['server']['name'] == 'some-bad-server':
body = self.server_1235
else:

View File

@ -390,6 +390,17 @@ class ServersTest(utils.FixturedTestCase):
def test_create_server_disk_config_manual(self):
self._create_disk_config('MANUAL')
def test_create_server_return_reservation_id(self):
s = self.cs.servers.create(
name="My server",
image=1,
flavor=1,
reservation_id=True,
nics=self._get_server_create_default_nics()
)
self.assert_request_id(s, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('POST', '/servers')
def test_update_server(self):
s = self.cs.servers.get(1234)

View File

@ -657,7 +657,7 @@ class ServerManager(base.BootingManagerWithFind):
def _boot(self, resource_url, response_key, name, image, flavor,
meta=None, files=None, userdata=None,
reservation_id=None, return_raw=False, min_count=None,
reservation_id=False, return_raw=False, min_count=None,
max_count=None, security_groups=None, key_name=None,
availability_zone=None, block_device_mapping=None,
block_device_mapping_v2=None, nics=None, scheduler_hints=None,
@ -695,7 +695,8 @@ class ServerManager(base.BootingManagerWithFind):
if meta:
body["server"]["metadata"] = meta
if reservation_id:
body["server"]["reservation_id"] = reservation_id
body["server"]["return_reservation_id"] = reservation_id
return_raw = True
if key_name:
body["server"]["key_name"] = key_name
if scheduler_hints:
@ -1278,7 +1279,7 @@ class ServerManager(base.BootingManagerWithFind):
type(nics))
def create(self, name, image, flavor, meta=None, files=None,
reservation_id=None, min_count=None,
reservation_id=False, min_count=None,
max_count=None, security_groups=None, userdata=None,
key_name=None, availability_zone=None,
block_device_mapping=None, block_device_mapping_v2=None,
@ -1300,7 +1301,8 @@ class ServerManager(base.BootingManagerWithFind):
are the file contents (either as a string or as a
file-like object). A maximum of five entries is allowed,
and each file must be 10k or less.
:param reservation_id: a UUID for the set of servers being requested.
:param reservation_id: return a reservation_id for the set of
servers being requested, boolean.
:param min_count: (optional extension) The minimum number of
servers to launch.
:param max_count: (optional extension) The maximum number of
@ -1399,7 +1401,7 @@ class ServerManager(base.BootingManagerWithFind):
if nics:
boot_kwargs['nics'] = nics
response_key = "server"
response_key = "server" if not reservation_id else "reservation_id"
return self._boot(resource_url, response_key, *boot_args,
**boot_kwargs)

View File

@ -525,7 +525,8 @@ def _boot(cs, args):
config_drive=config_drive,
admin_pass=args.admin_pass,
access_ip_v4=args.access_ip_v4,
access_ip_v6=args.access_ip_v6)
access_ip_v6=args.access_ip_v6,
reservation_id=args.return_reservation_id)
if 'description' in args:
boot_kwargs["description"] = args.description
@ -887,6 +888,12 @@ def _boot(cs, args):
help=_('Tags for the server.'
'Tags must be separated by commas: --tags <tag1,tag2>'),
start_version="2.52")
@utils.arg(
'--return-reservation-id',
dest='return_reservation_id',
action="store_true",
default=False,
help=_("Return a reservation id bound to created servers."))
def do_boot(cs, args):
"""Boot a new server."""
boot_args, boot_kwargs = _boot(cs, args)
@ -895,7 +902,12 @@ def do_boot(cs, args):
boot_kwargs.update(extra_boot_kwargs)
server = cs.servers.create(*boot_args, **boot_kwargs)
_print_server(cs, args, server)
if boot_kwargs['reservation_id']:
new_server = {'reservation_id': server}
utils.print_dict(new_server)
return
else:
_print_server(cs, args, server)
if args.poll:
_poll_for_status(cs.servers.get, server.id, 'building', ['active'])