Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
'ocp_date',
'timeout',
'client_request_id',
'return_client_request_id'
'return_client_request_id',
'max_results'
}
IGNORE_PARAMETERS = {'callback'}
FLATTEN_OPTIONS = { # Options to be flattened into multiple arguments.
Expand Down Expand Up @@ -103,7 +104,7 @@ def find_param_type(model, param):
# Search for the :type param_name: in the docstring
pattern = r":type {}:(.*?)\n(\s*:param |\s*:rtype:|\s*:raises:|\"\"\")".format(param)
param_type = re.search(pattern, model.__doc__, re.DOTALL)
return re.sub(r"\n\s*", "", param_type.group(1).strip())
return re.sub(r"\n\s*", " ", param_type.group(1).strip())


def find_param_help(model, param):
Expand Down Expand Up @@ -352,6 +353,11 @@ def parse(self, namespace):
:param namespace: The namespace object.
:raises: ValueError if a require argument was not set.
"""
if self._custom_validator:
try:
self._custom_validator(namespace, self)
except TypeError:
raise ValueError("Custom validator must be a function that takes two arguments.")
try:
if namespace.json_file:
try:
Expand All @@ -365,15 +371,10 @@ def parse(self, namespace):
if other_values:
message = "--json-file cannot be combined with:\n"
raise ValueError(message + '\n'.join(other_values))
self.done = True
return
except AttributeError:
pass
if self._custom_validator:
try:
self._custom_validator(namespace, self)
except TypeError:
raise ValueError("Custom validator must be a function that takes two arguments.")

required_args = self._parse(namespace, self._request_param['name'], True)
missing_args = [n for n in required_args if not getattr(namespace, n)]
if missing_args:
Expand All @@ -396,7 +397,8 @@ def __init__(self, module_name, name, operation, factory, transform_result, #pyl
self.ignore = list(IGNORE_PARAMETERS) # Parameters to ignore
if ignore:
self.ignore.extend(ignore)
self.parser = BatchArgumentTree(validator)
self.parser = None
self.validator = validator

# The name of the request options parameter
self._options_param = format_options_name(operation)
Expand All @@ -420,9 +422,7 @@ def _execute_command(kwargs):

# Build the request parameters from command line arguments
if json_file:
with open(json_file) as file_handle:
json_obj = json.load(file_handle)
self.parser.deserialize_json(client, kwargs, json_obj)
self.parser.deserialize_json(client, kwargs, json_file)
for arg, _ in self.parser:
del kwargs[arg]
else:
Expand Down Expand Up @@ -647,6 +647,7 @@ def _load_transformed_arguments(self, handler):
"""Load all the command line arguments from the request parameters.
:param func handler: The operation function.
"""
self.parser = BatchArgumentTree(self.validator)
self._load_options_model(handler)
for arg in extract_args_from_signature(handler):
arg_type = find_param_type(handler, arg[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ def validate_pool_settings(ns, parser):
"""Custom parsing to enfore that either PaaS or IaaS instances are configured
in the add pool request body.
"""
groups = ['pool.cloud_service_configuration', 'pool.virtual_machine_configuration']
parser.parse_mutually_exclusive(ns, True, groups)

paas_sizes = ['small', 'medium', 'large', 'extralarge']
if ns.vm_size and ns.vm_size.lower() in paas_sizes and not ns.os_family:
message = ("The selected VM size in incompatible with Virtual Machine Configuration. "
"Please swap for the IaaS equivalent: Standard_A1 (small), Standard_A2 "
"(medium), Standard_A3 (large), or Standard_A4 (extra large).")
raise ValueError(message)
if not ns.json_file:
groups = ['pool.cloud_service_configuration', 'pool.virtual_machine_configuration']
parser.parse_mutually_exclusive(ns, True, groups)

paas_sizes = ['small', 'medium', 'large', 'extralarge']
if ns.vm_size and ns.vm_size.lower() in paas_sizes and not ns.os_family:
message = ("The selected VM size in incompatible with Virtual Machine Configuration. "
"Please swap for the IaaS equivalent: Standard_A1 (small), Standard_A2 "
"(medium), Standard_A3 (large), or Standard_A4 (extra large).")
raise ValueError(message)