From 1e7ad37b8a842094963d3296cf127614f49e10fe Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Mon, 28 Apr 2014 22:17:50 +0000 Subject: [PATCH] Deprecate num-instances in favor of min/max count For 'nova boot', num_instances only set max_count, which will try to launch up to max_count instances. But sometimes users want to either launch min_count instances or nothing. So deprecate --num-instances and use --min-count and --max-count instead. DocImpact: deprecate '--num-instances' for 'nova boot' Change-Id: If0088aef554a528258799b22c6e793541474cb0d Closes-bug: #1309244 --- novaclient/tests/v1_1/test_shell.py | 45 +++++++++++++++++++++++++++++ novaclient/tests/v3/test_shell.py | 45 +++++++++++++++++++++++++++++ novaclient/v1_1/shell.py | 29 +++++++++++++++++-- novaclient/v3/shell.py | 29 +++++++++++++++++-- 4 files changed, 144 insertions(+), 4 deletions(-) diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index 564b55ec5..d01155b24 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -590,6 +590,51 @@ class ShellTest(utils.TestCase): cmd = 'boot --image 1 --flavor 1 --num-instances 0 server' self.assertRaises(exceptions.CommandError, self.run_command, cmd) + def test_boot_num_instances_and_count(self): + cmd = 'boot --image 1 --flavor 1 --num-instances 3 --min-count 3 serv' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + cmd = 'boot --image 1 --flavor 1 --num-instances 3 --max-count 3 serv' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + + def test_boot_min_max_count(self): + self.run_command('boot --image 1 --flavor 1 --max-count 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavorRef': '1', + 'name': 'server', + 'imageRef': '1', + 'min_count': 1, + 'max_count': 3, + } + }) + self.run_command('boot --image 1 --flavor 1 --min-count 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavorRef': '1', + 'name': 'server', + 'imageRef': '1', + 'min_count': 3, + 'max_count': 3, + } + }) + self.run_command('boot --image 1 --flavor 1 ' + '--min-count 3 --max-count 5 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavorRef': '1', + 'name': 'server', + 'imageRef': '1', + 'min_count': 3, + 'max_count': 5, + } + }) + @mock.patch('novaclient.v1_1.shell._poll_for_status') def test_boot_with_poll(self, poll_method): self.run_command('boot --flavor 1 --image 1 some-server --poll') diff --git a/novaclient/tests/v3/test_shell.py b/novaclient/tests/v3/test_shell.py index 144e85712..a18d97d10 100644 --- a/novaclient/tests/v3/test_shell.py +++ b/novaclient/tests/v3/test_shell.py @@ -489,6 +489,51 @@ class ShellTest(utils.TestCase): cmd = 'boot --image 1 --flavor 1 --num-instances 0 server' self.assertRaises(exceptions.CommandError, self.run_command, cmd) + def test_boot_num_instances_and_count(self): + cmd = 'boot --image 1 --flavor 1 --num-instances 3 --min-count 3 serv' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + cmd = 'boot --image 1 --flavor 1 --num-instances 3 --max-count 3 serv' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + + def test_boot_min_max_count(self): + self.run_command('boot --image 1 --flavor 1 --max-count 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavor_ref': '1', + 'name': 'server', + 'image_ref': '1', + 'os-multiple-create:min_count': 1, + 'os-multiple-create:max_count': 3, + } + }) + self.run_command('boot --image 1 --flavor 1 --min-count 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavor_ref': '1', + 'name': 'server', + 'image_ref': '1', + 'os-multiple-create:min_count': 3, + 'os-multiple-create:max_count': 3, + } + }) + self.run_command('boot --image 1 --flavor 1 ' + '--min-count 3 --max-count 5 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavor_ref': '1', + 'name': 'server', + 'image_ref': '1', + 'os-multiple-create:min_count': 3, + 'os-multiple-create:max_count': 5, + } + }) + @mock.patch('novaclient.v3.shell._poll_for_status') def test_boot_with_poll(self, poll_method): self.run_command('boot --flavor 1 --image 1 some-server --poll') diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index df1e2ac62..54774b6c4 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -148,10 +148,25 @@ def _boot(cs, args): min_count = 1 max_count = 1 - if args.num_instances is not None: + # Don't let user mix num_instances and max_count/min_count. + if (args.num_instances is not None and + args.min_count is None and args.max_count is None): if args.num_instances <= 1: raise exceptions.CommandError(_("num_instances should be > 1")) max_count = args.num_instances + elif (args.num_instances is not None and + (args.min_count is not None or args.max_count is not None)): + raise exceptions.CommandError(_("Don't mix num-instances and " + "max/min-count")) + if args.min_count is not None: + if args.min_count <= 1: + raise exceptions.CommandError(_("min_count should be > 1")) + min_count = args.min_count + max_count = min_count + if args.max_count is not None: + if args.max_count <= 1: + raise exceptions.CommandError(_("max_count should be > 1")) + max_count = args.max_count flavor = _find_flavor(cs, args.flavor) @@ -312,7 +327,17 @@ def _boot(cs, args): default=None, type=int, metavar='', - help=_("boot multiple servers at a time (limited by quota).")) + help=argparse.SUPPRESS) +@utils.arg('--min-count', + default=None, + type=int, + metavar='', + help=_("Boot at least servers (limited by quota).")) +@utils.arg('--max-count', + default=None, + type=int, + metavar='', + help=_("Boot up to servers (limited by quota).")) @utils.arg('--meta', metavar="", action='append', diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index 2b8ac5acf..1d9c76c6d 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -84,10 +84,25 @@ def _boot(cs, args): min_count = 1 max_count = 1 - if args.num_instances is not None: + # Don't let user mix num_instances and max_count/min_count. + if (args.num_instances is not None and + args.min_count is None and args.max_count is None): if args.num_instances <= 1: raise exceptions.CommandError("num_instances should be > 1") max_count = args.num_instances + elif (args.num_instances is not None and + (args.min_count is not None or args.max_count is not None)): + raise exceptions.CommandError("Don't mix num-instances and " + "max/min-count") + if args.min_count is not None: + if args.min_count <= 1: + raise exceptions.CommandError("min_count should be > 1") + min_count = args.min_count + max_count = min_count + if args.max_count is not None: + if args.max_count <= 1: + raise exceptions.CommandError("max_count should be > 1") + max_count = args.max_count flavor = _find_flavor(cs, args.flavor) @@ -214,7 +229,17 @@ def _boot(cs, args): default=None, type=int, metavar='', - help="boot multiple servers at a time (limited by quota).") + help=argparse.SUPPRESS) +@utils.arg('--min-count', + default=None, + type=int, + metavar='', + help="Boot at least servers (limited by quota).") +@utils.arg('--max-count', + default=None, + type=int, + metavar='', + help="Boot up to servers (limited by quota).") @utils.arg('--meta', metavar="", action='append',