Skip to content

Commit 2642b07

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "compute: Add 'server create --server-group' option"
2 parents 2957f28 + 7708106 commit 2642b07

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,19 @@ def get_parser(self, prog_name):
13381338
'(supported by --os-compute-api-version 2.74 or above)'
13391339
),
13401340
)
1341+
parser.add_argument(
1342+
'--server-group',
1343+
metavar='<server-group>',
1344+
help=_(
1345+
"Server group to create the server within "
1346+
"(this is an alias for '--hint group=<server-group-id>')"
1347+
),
1348+
)
13411349
parser.add_argument(
13421350
'--hint',
13431351
metavar='<key=value>',
13441352
action=parseractions.KeyValueAppendAction,
1353+
dest='hints',
13451354
default={},
13461355
help=_('Hints for the scheduler'),
13471356
)
@@ -1860,13 +1869,20 @@ def _match_image(image_api, wanted_properties):
18601869
security_group_names.append(sg['name'])
18611870

18621871
hints = {}
1863-
for key, values in parsed_args.hint.items():
1872+
for key, values in parsed_args.hints.items():
18641873
# only items with multiple values will result in a list
18651874
if len(values) == 1:
18661875
hints[key] = values[0]
18671876
else:
18681877
hints[key] = values
18691878

1879+
if parsed_args.server_group:
1880+
server_group_obj = utils.find_resource(
1881+
compute_client.server_groups,
1882+
parsed_args.server_group,
1883+
)
1884+
hints['group'] = server_group_obj.id
1885+
18701886
if isinstance(parsed_args.config_drive, bool):
18711887
# NOTE(stephenfin): The API doesn't accept False as a value :'(
18721888
config_drive = parsed_args.config_drive or None

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,8 @@ def test_server_create_with_options(self):
14461446
'a=b',
14471447
'--hint',
14481448
'a=c',
1449+
'--server-group',
1450+
'servergroup',
14491451
self.new_server.name,
14501452
]
14511453
verifylist = [
@@ -1454,22 +1456,26 @@ def test_server_create_with_options(self):
14541456
('key_name', 'keyname'),
14551457
('properties', {'Beta': 'b'}),
14561458
('security_group', ['securitygroup']),
1457-
('hint', {'a': ['b', 'c']}),
1459+
('hints', {'a': ['b', 'c']}),
1460+
('server_group', 'servergroup'),
14581461
('config_drive', True),
14591462
('password', 'passw0rd'),
14601463
('server_name', self.new_server.name),
14611464
]
14621465
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
14631466

1464-
# In base command class ShowOne in cliff, abstract method take_action()
1465-
# returns a two-part tuple with a tuple of column names and a tuple of
1466-
# data to be shown.
1467+
fake_server_group = compute_fakes.create_one_server_group()
1468+
self.compute_client.server_groups.get.return_value = fake_server_group
1469+
14671470
fake_sg = network_fakes.FakeSecurityGroup.create_security_groups()
14681471
mock_find_sg = network_fakes.FakeSecurityGroup.get_security_groups(
14691472
fake_sg
14701473
)
14711474
self.app.client_manager.network.find_security_group = mock_find_sg
14721475

1476+
# In base command class ShowOne in cliff, abstract method take_action()
1477+
# returns a two-part tuple with a tuple of column names and a tuple of
1478+
# data to be shown.
14731479
columns, data = self.cmd.take_action(parsed_args)
14741480

14751481
mock_find_sg.assert_called_once_with(
@@ -1489,7 +1495,7 @@ def test_server_create_with_options(self):
14891495
admin_pass='passw0rd',
14901496
block_device_mapping_v2=[],
14911497
nics=[],
1492-
scheduler_hints={'a': ['b', 'c']},
1498+
scheduler_hints={'a': ['b', 'c'], 'group': fake_server_group.id},
14931499
config_drive=True,
14941500
)
14951501
# ServerManager.create(name, image, flavor, **kwargs)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
The ``server create`` command now accepts a new option, ``--server-group``,
5+
which is a shortcut for configuring the ``group`` scheduler hint.

0 commit comments

Comments
 (0)