Merge "compute: Add 'server create --server-group' option"
This commit is contained in:
commit
2642b070db
openstackclient
releasenotes/notes
@ -1338,10 +1338,19 @@ class CreateServer(command.ShowOne):
|
|||||||
'(supported by --os-compute-api-version 2.74 or above)'
|
'(supported by --os-compute-api-version 2.74 or above)'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--server-group',
|
||||||
|
metavar='<server-group>',
|
||||||
|
help=_(
|
||||||
|
"Server group to create the server within "
|
||||||
|
"(this is an alias for '--hint group=<server-group-id>')"
|
||||||
|
),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--hint',
|
'--hint',
|
||||||
metavar='<key=value>',
|
metavar='<key=value>',
|
||||||
action=parseractions.KeyValueAppendAction,
|
action=parseractions.KeyValueAppendAction,
|
||||||
|
dest='hints',
|
||||||
default={},
|
default={},
|
||||||
help=_('Hints for the scheduler'),
|
help=_('Hints for the scheduler'),
|
||||||
)
|
)
|
||||||
@ -1860,13 +1869,20 @@ class CreateServer(command.ShowOne):
|
|||||||
security_group_names.append(sg['name'])
|
security_group_names.append(sg['name'])
|
||||||
|
|
||||||
hints = {}
|
hints = {}
|
||||||
for key, values in parsed_args.hint.items():
|
for key, values in parsed_args.hints.items():
|
||||||
# only items with multiple values will result in a list
|
# only items with multiple values will result in a list
|
||||||
if len(values) == 1:
|
if len(values) == 1:
|
||||||
hints[key] = values[0]
|
hints[key] = values[0]
|
||||||
else:
|
else:
|
||||||
hints[key] = values
|
hints[key] = values
|
||||||
|
|
||||||
|
if parsed_args.server_group:
|
||||||
|
server_group_obj = utils.find_resource(
|
||||||
|
compute_client.server_groups,
|
||||||
|
parsed_args.server_group,
|
||||||
|
)
|
||||||
|
hints['group'] = server_group_obj.id
|
||||||
|
|
||||||
if isinstance(parsed_args.config_drive, bool):
|
if isinstance(parsed_args.config_drive, bool):
|
||||||
# NOTE(stephenfin): The API doesn't accept False as a value :'(
|
# NOTE(stephenfin): The API doesn't accept False as a value :'(
|
||||||
config_drive = parsed_args.config_drive or None
|
config_drive = parsed_args.config_drive or None
|
||||||
|
@ -1446,6 +1446,8 @@ class TestServerCreate(TestServer):
|
|||||||
'a=b',
|
'a=b',
|
||||||
'--hint',
|
'--hint',
|
||||||
'a=c',
|
'a=c',
|
||||||
|
'--server-group',
|
||||||
|
'servergroup',
|
||||||
self.new_server.name,
|
self.new_server.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
@ -1454,22 +1456,26 @@ class TestServerCreate(TestServer):
|
|||||||
('key_name', 'keyname'),
|
('key_name', 'keyname'),
|
||||||
('properties', {'Beta': 'b'}),
|
('properties', {'Beta': 'b'}),
|
||||||
('security_group', ['securitygroup']),
|
('security_group', ['securitygroup']),
|
||||||
('hint', {'a': ['b', 'c']}),
|
('hints', {'a': ['b', 'c']}),
|
||||||
|
('server_group', 'servergroup'),
|
||||||
('config_drive', True),
|
('config_drive', True),
|
||||||
('password', 'passw0rd'),
|
('password', 'passw0rd'),
|
||||||
('server_name', self.new_server.name),
|
('server_name', self.new_server.name),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
# In base command class ShowOne in cliff, abstract method take_action()
|
fake_server_group = compute_fakes.create_one_server_group()
|
||||||
# returns a two-part tuple with a tuple of column names and a tuple of
|
self.compute_client.server_groups.get.return_value = fake_server_group
|
||||||
# data to be shown.
|
|
||||||
fake_sg = network_fakes.FakeSecurityGroup.create_security_groups()
|
fake_sg = network_fakes.FakeSecurityGroup.create_security_groups()
|
||||||
mock_find_sg = network_fakes.FakeSecurityGroup.get_security_groups(
|
mock_find_sg = network_fakes.FakeSecurityGroup.get_security_groups(
|
||||||
fake_sg
|
fake_sg
|
||||||
)
|
)
|
||||||
self.app.client_manager.network.find_security_group = mock_find_sg
|
self.app.client_manager.network.find_security_group = mock_find_sg
|
||||||
|
|
||||||
|
# In base command class ShowOne in cliff, abstract method take_action()
|
||||||
|
# returns a two-part tuple with a tuple of column names and a tuple of
|
||||||
|
# data to be shown.
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
mock_find_sg.assert_called_once_with(
|
mock_find_sg.assert_called_once_with(
|
||||||
@ -1489,7 +1495,7 @@ class TestServerCreate(TestServer):
|
|||||||
admin_pass='passw0rd',
|
admin_pass='passw0rd',
|
||||||
block_device_mapping_v2=[],
|
block_device_mapping_v2=[],
|
||||||
nics=[],
|
nics=[],
|
||||||
scheduler_hints={'a': ['b', 'c']},
|
scheduler_hints={'a': ['b', 'c'], 'group': fake_server_group.id},
|
||||||
config_drive=True,
|
config_drive=True,
|
||||||
)
|
)
|
||||||
# ServerManager.create(name, image, flavor, **kwargs)
|
# ServerManager.create(name, image, flavor, **kwargs)
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The ``server create`` command now accepts a new option, ``--server-group``,
|
||||||
|
which is a shortcut for configuring the ``group`` scheduler hint.
|
Loading…
x
Reference in New Issue
Block a user