FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Better ec2 run-instances --cli-input-json support · 22monkey/aws-cli@6cf993d · GitHub

forked from aws/aws-cli

Commit 6cf993d

Browse files
committed
Better ec2 run-instances --cli-input-json support
Now the MaxCount and MinCount setting in --cli-input-json will NOT be overridden by a default value. This fixes aws#1524
1 parent 0388773 commit 6cf993d

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎awscli/customizations/ec2addcount.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
logger = logging.getLogger(__name__)
2121

2222

23+
DEFAULT = 1
2324
HELP = """
2425
<p>Number of instances to launch. If a single number is provided, it
25-
is assumed to be the minimum to launch (defaults to 1). If a range is
26+
is assumed to be the minimum to launch (defaults to %d). If a range is
2627
provided in the form <code>min:max</code> then the first number is
2728
interpreted as the minimum number of instances to launch and the second
28-
is interpreted as the maximum number of instances to launch.</p>"""
29+
is interpreted as the maximum number of instances to launch.</p>""" % DEFAULT
2930

3031

3132
def ec2_add_count(argument_table, **kwargs):
@@ -64,9 +65,15 @@ def documentation(self):
6465
def add_to_parser(self, parser):
6566
parser.add_argument(self.cli_name, metavar=self.py_name,
6667
help='Number of instances to launch',
67-
default='1')
68+
## We will delegate the default value logic to
69+
## ec2runinstances.py:_fix_args()
70+
# default=str(DEFAULT)
71+
)
6872

6973
def add_to_params(self, parameters, value):
74+
if value is None:
75+
# NO-OP if value is not explicitly set by user
76+
return
7077
try:
7178
if ':' in value:
7279
minstr, maxstr = value.split(':')

‎awscli/customizations/ec2runinstances.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
the most commonly used features available more easily.
2424
"""
2525
from awscli.arguments import CustomArgument
26+
from awscli.customizations.ec2addcount import DEFAULT
2627

2728
# --secondary-private-ip-address
2829
SECONDARY_PRIVATE_IP_ADDRESSES_DOCS = (
@@ -105,6 +106,8 @@ def _fix_args(params, **kwargs):
105106
'Primary': True}
106107
ni[0]['PrivateIpAddresses'] = [ip_addr]
107108
del params['PrivateIpAddress']
109+
params.setdefault('MaxCount', DEFAULT)
110+
params.setdefault('MinCount', DEFAULT)
108111

109112

110113
EVENTS = [

‎tests/functional/ec2/test_run_instances.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ def test_count_range(self):
6868
}
6969
self.assert_params_for_cmd(args_list, result)
7070

71+
def test_count_in_json_only(self):
72+
input_json = '{"ImageId":"ami-xxxx","MaxCount":9,"MinCount":5}'
73+
args_list = (self.prefix + ' --cli-input-json ' + input_json).split()
74+
result = {'ImageId': 'ami-xxxx', 'MaxCount': 9, 'MinCount': 5}
75+
self.assert_params_for_cmd(args_list, result)
76+
77+
def test_count_in_cli_and_in_json(self):
78+
input_json = '{"ImageId":"ami-xxxx","MaxCount":9,"MinCount":5}'
79+
args_list = (
80+
self.prefix + ' --count 3 --cli-input-json ' + input_json).split()
81+
result = {'ImageId': 'ami-xxxx', 'MaxCount': 3, 'MinCount': 3}
82+
self.assert_params_for_cmd(args_list, result)
83+
7184
def test_block_device_mapping(self):
7285
args = ' --image-id ami-foobar --count 1'
7386
args_list = (self.prefix + args).split()

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL