Skip to content

Commit b35c98d

Browse files
committed
Merge pull request softlayer#548 from softlayer/validate-create
Adds argument validation for vs/hardware create CLI commands
2 parents 43008f4 + 2ead9e8 commit b35c98d

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

SoftLayer/CLI/server/create.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def cli(env, **args):
5252
"""Order/create a dedicated server."""
5353

5454
template.update_with_template_args(args, list_args=['key'])
55+
_validate_args(args)
56+
5557
mgr = SoftLayer.HardwareManager(env.client)
5658

5759
# Get the SSH keys
@@ -125,3 +127,20 @@ def cli(env, **args):
125127
output = table
126128

127129
return output
130+
131+
132+
def _validate_args(args):
133+
"""Raises an ArgumentError if the given arguments are not valid."""
134+
missing = []
135+
for arg in ['size',
136+
'datacenter',
137+
'os',
138+
'port_speed',
139+
'hostname',
140+
'domain']:
141+
if not args.get(arg):
142+
missing.append(arg)
143+
144+
if missing:
145+
raise exceptions.ArgumentError('Missing required options: %s'
146+
% ', '.join(missing))

SoftLayer/CLI/virt/create.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ def cli(env, **args):
154154

155155
def _validate_args(args):
156156
"""Raises an ArgumentError if the given arguments are not valid."""
157+
missing = []
158+
for arg in ['cpu', 'memory', 'hostname', 'domain']:
159+
if not args.get(arg):
160+
missing.append(arg)
161+
162+
if missing:
163+
raise exceptions.ArgumentError('Missing required options: %s'
164+
% ', '.join(missing))
157165

158166
if all([args['userdata'], args['userfile']]):
159167
raise exceptions.ArgumentError(

tox.ini

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ commands =
2828
pylint SoftLayer \
2929
-r n \ # Don't show the long report
3030
--ignore=tests,fixtures \
31-
-d too-many-locals \ # Too many local variables
32-
-d star-args \ # Used * or ** magic
33-
-d I0011 \ # Locally Disabling
31+
-d too-many-locals \
32+
-d star-args \
33+
-d locally-disabled \
3434
--max-args=20 \
35-
--max-branches=40 \
36-
--max-statements=87 \
37-
--max-returns=8 \
35+
--max-branches=20 \
36+
--max-statements=60 \
3837
--min-public-methods=0 \
3938
--min-similarity-lines=30
4039
pylint SoftLayer/testing/fixtures \

0 commit comments

Comments
 (0)