diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py index c195da50d..d16714c7c 100644 --- a/novaclient/tests/unit/v2/test_servers.py +++ b/novaclient/tests/unit/v2/test_servers.py @@ -205,6 +205,21 @@ class ServersTest(utils.FixturedTestCase): self.assert_called('POST', '/servers') self.assertIsInstance(s, servers.Server) + def test_create_server_admin_pass(self): + test_password = "test-pass" + test_key = "fakekey" + s = self.cs.servers.create( + name="My server", + image=1, + flavor=1, + admin_pass=test_password, + key_name=test_key + ) + self.assert_called('POST', '/servers') + self.assertIsInstance(s, servers.Server) + body = jsonutils.loads(self.requests.last_request.body) + self.assertEqual(test_password, body['server']['adminPass']) + def test_create_server_userdata_bin(self): with tempfile.TemporaryFile(mode='wb+') as bin_file: original_data = os.urandom(1024) diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py index f10d85aa1..a8848154f 100644 --- a/novaclient/v2/servers.py +++ b/novaclient/v2/servers.py @@ -849,7 +849,7 @@ class ServerManager(base.BootingManagerWithFind): key_name=None, availability_zone=None, block_device_mapping=None, block_device_mapping_v2=None, nics=None, scheduler_hints=None, - config_drive=None, disk_config=None, **kwargs): + config_drive=None, disk_config=None, admin_pass=None, **kwargs): # TODO(anthony): indicate in doc string if param is an extension # and/or optional """ @@ -892,6 +892,8 @@ class ServerManager(base.BootingManagerWithFind): :param disk_config: (optional extension) control how the disk is partitioned when the server is created. possible values are 'AUTO' or 'MANUAL'. + :param admin_pass: (optional extension) add a user supplied admin + password. """ if not min_count: min_count = 1 @@ -908,7 +910,7 @@ class ServerManager(base.BootingManagerWithFind): max_count=max_count, security_groups=security_groups, key_name=key_name, availability_zone=availability_zone, scheduler_hints=scheduler_hints, config_drive=config_drive, - disk_config=disk_config, **kwargs) + disk_config=disk_config, admin_pass=admin_pass, **kwargs) if block_device_mapping: resource_url = "/os-volumes_boot" diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index d7112b751..a9234cb70 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -319,7 +319,8 @@ def _boot(cs, args): block_device_mapping_v2=block_device_mapping_v2, nics=nics, scheduler_hints=hints, - config_drive=config_drive) + config_drive=config_drive, + admin_pass=args.admin_pass) return boot_args, boot_kwargs @@ -502,6 +503,12 @@ def _boot(cs, args): action="store_true", default=False, help=_('Report the new server boot progress until it completes.')) +@cliutils.arg( + '--admin-pass', + dest='admin_pass', + metavar='<value>', + default=None, + help='Admin password for the instance') def do_boot(cs, args): """Boot a new server.""" boot_args, boot_kwargs = _boot(cs, args)