diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 77743deaa..b3fe46b1a 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -48,6 +48,11 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None): if not args.flavor: raise exceptions.CommandError("you need to specify a Flavor ID ") + if args.num_instances: + if args.num_instances <= 1: + raise exceptions.CommandError("num_instances should be > 1") + max_count = args.num_instances + flavor = _find_flavor(cs, args.flavor) if args.image: @@ -149,6 +154,11 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None): default=None, metavar='<image>', help="Image ID (see 'nova image-list'). ") +@utils.arg('--num-instances', + default=None, + type=int, + metavar='<number>', + help="boot multi instances at a time") @utils.arg('--meta', metavar="<key=value>", action='append', diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index 12b13c907..de85a3e57 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -224,6 +224,24 @@ class ShellTest(utils.TestCase): cmd = 'boot some-server --image 1 --file /foo=%s' % invalid_file self.assertRaises(exceptions.CommandError, self.run_command, cmd) + def test_boot_num_instances(self): + self.run_command('boot --image 1 --flavor 1 --num-instances 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavorRef': '1', + 'name': 'server', + 'imageRef': '1', + 'min_count': 1, + 'max_count': 3, + } + }) + + def test_boot_invalid_num_instances(self): + cmd = 'boot --image 1 --flavor 1 --num-instances 1 server' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + def test_flavor_list(self): self.run_command('flavor-list') self.assert_called('GET', '/flavors/aa1/os-extra_specs')