Skip to content

Commit

Permalink
Merge pull request #548 from softlayer/validate-create
Browse files Browse the repository at this point in the history
Adds argument validation for vs/hardware create CLI commands
  • Loading branch information
sudorandom committed Jun 3, 2015
2 parents 43008f4 + 2ead9e8 commit b35c98d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
19 changes: 19 additions & 0 deletions SoftLayer/CLI/server/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def cli(env, **args):
"""Order/create a dedicated server."""

template.update_with_template_args(args, list_args=['key'])
_validate_args(args)

mgr = SoftLayer.HardwareManager(env.client)

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

return output


def _validate_args(args):
"""Raises an ArgumentError if the given arguments are not valid."""
missing = []
for arg in ['size',
'datacenter',
'os',
'port_speed',
'hostname',
'domain']:
if not args.get(arg):
missing.append(arg)

if missing:
raise exceptions.ArgumentError('Missing required options: %s'
% ', '.join(missing))
8 changes: 8 additions & 0 deletions SoftLayer/CLI/virt/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ def cli(env, **args):

def _validate_args(args):
"""Raises an ArgumentError if the given arguments are not valid."""
missing = []
for arg in ['cpu', 'memory', 'hostname', 'domain']:
if not args.get(arg):
missing.append(arg)

if missing:
raise exceptions.ArgumentError('Missing required options: %s'
% ', '.join(missing))

if all([args['userdata'], args['userfile']]):
raise exceptions.ArgumentError(
Expand Down
11 changes: 5 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ commands =
pylint SoftLayer \
-r n \ # Don't show the long report
--ignore=tests,fixtures \
-d too-many-locals \ # Too many local variables
-d star-args \ # Used * or ** magic
-d I0011 \ # Locally Disabling
-d too-many-locals \
-d star-args \
-d locally-disabled \
--max-args=20 \
--max-branches=40 \
--max-statements=87 \
--max-returns=8 \
--max-branches=20 \
--max-statements=60 \
--min-public-methods=0 \
--min-similarity-lines=30
pylint SoftLayer/testing/fixtures \
Expand Down

0 comments on commit b35c98d

Please sign in to comment.