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
This commit is contained in:
Joe Gordon 2014-04-28 22:17:50 +00:00
parent 02ee4fc79e
commit 1e7ad37b8a
4 changed files with 144 additions and 4 deletions

View File

@ -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')

View File

@ -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')

View File

@ -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='<number>',
help=_("boot multiple servers at a time (limited by quota)."))
help=argparse.SUPPRESS)
@utils.arg('--min-count',
default=None,
type=int,
metavar='<number>',
help=_("Boot at least <number> servers (limited by quota)."))
@utils.arg('--max-count',
default=None,
type=int,
metavar='<number>',
help=_("Boot up to <number> servers (limited by quota)."))
@utils.arg('--meta',
metavar="<key=value>",
action='append',

View File

@ -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='<number>',
help="boot multiple servers at a time (limited by quota).")
help=argparse.SUPPRESS)
@utils.arg('--min-count',
default=None,
type=int,
metavar='<number>',
help="Boot at least <number> servers (limited by quota).")
@utils.arg('--max-count',
default=None,
type=int,
metavar='<number>',
help="Boot up to <number> servers (limited by quota).")
@utils.arg('--meta',
metavar="<key=value>",
action='append',