diff --git a/novaclient/tests/unit/fixture_data/servers.py b/novaclient/tests/unit/fixture_data/servers.py index 7232fb589..9822fa5b0 100644 --- a/novaclient/tests/unit/fixture_data/servers.py +++ b/novaclient/tests/unit/fixture_data/servers.py @@ -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: diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py index b750e1264..863368574 100644 --- a/novaclient/tests/unit/v2/test_servers.py +++ b/novaclient/tests/unit/v2/test_servers.py @@ -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) diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py index ef94b8c92..4c38ed700 100644 --- a/novaclient/v2/servers.py +++ b/novaclient/v2/servers.py @@ -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) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 670c717a7..708a649bf 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -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 '), 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'])