diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index e6c855b59..262fd6668 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -2075,6 +2075,13 @@ class ShellTest(utils.TestCase): self.run_command('keypair-delete test') self.assert_called('DELETE', '/os-keypairs/test') + def test_create_server_group(self): + self.run_command('server-group-create wjsg affinity') + self.assert_called('POST', '/os-server-groups', + {'server_group': + {'name': 'wjsg', + 'policies': ['affinity']}}) + def test_delete_multi_server_groups(self): self.run_command('server-group-delete 12345 56789') self.assert_called('DELETE', '/os-server-groups/56789') diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index db8393b3d..92025182d 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -3568,13 +3568,33 @@ def do_server_group_list(cs, args): @utils.arg('name', metavar='', help='Server group name.') -@utils.arg('--policy', metavar='', action='append', - dest='policies', default=[], type=str, - help='Policies for the server groups') +# NOTE(wingwj): The '--policy' way is still reserved here for preserving +# the backwards compatibility of CLI, even if a user won't get this usage +# in '--help' description. It will be deprecated after an suitable deprecation +# period(probably 2 coordinated releases or so). +# +# Moreover, we imagine that a given user will use only positional parameters or +# only the "--policy" option. So we don't need to properly handle +# the possibility that they might mix them here. That usage is unsupported. +# The related discussion can be found in +# https://review.openstack.org/#/c/96382/2/. +@utils.arg('policy', + metavar='', + default=argparse.SUPPRESS, + nargs='*', + help='Policies for the server groups ' + '("affinity" or "anti-affinity")') +@utils.arg('--policy', + default=[], + action='append', + help=argparse.SUPPRESS) def do_server_group_create(cs, args): """Create a new server group with the specified details.""" + if not args.policy: + raise exceptions.CommandError(_("at least one policy must be " + "specified")) kwargs = {'name': args.name, - 'policies': args.policies} + 'policies': args.policy} server_group = cs.server_groups.create(**kwargs) _print_server_group_details([server_group])