Fix network passing for cluster-template-create
The fix adds the following: * Support neutron_management_network in cluster-template-create * Client prints a warning message if user passed an unrecogizable parameter into node group or cluster template, or in cluster. Closes-bug: #1325609 Closes-bug: #1271147 Change-Id: I38f131897396bf0ab1e42cd06a1dc3d50ba624c6
This commit is contained in:
@@ -26,6 +26,31 @@ def _print_list_field(field):
|
||||
return lambda obj: ', '.join(getattr(obj, field))
|
||||
|
||||
|
||||
def _filter_call_args(args, func, remap={}):
|
||||
"""Filter args according to func's parameter list.
|
||||
|
||||
Take three arguments:
|
||||
* args - a dictionary
|
||||
* func - a function
|
||||
* remap - a dictionary
|
||||
Remove from dct all the keys which are not among the parameters
|
||||
of func. Before filtering, remap the keys in the args dict
|
||||
according to remap dict.
|
||||
"""
|
||||
|
||||
for name, new_name in remap.items():
|
||||
if name in args:
|
||||
args[new_name] = args[name]
|
||||
del args[name]
|
||||
|
||||
valid_args = inspect.getargspec(func).args
|
||||
for name in args.keys():
|
||||
if name not in valid_args:
|
||||
print('WARNING: "%s" is not a valid parameter and will be '
|
||||
'discarded from the request' % name)
|
||||
del args[name]
|
||||
|
||||
|
||||
def _print_node_group_field(cluster):
|
||||
return ', '.join(map(lambda x: ': '.join(x),
|
||||
[(node_group['name'],
|
||||
@@ -295,12 +320,9 @@ def do_cluster_create(cs, args):
|
||||
# called net_id. Therefore, we must translate before invoking
|
||||
# create w/ **template. It may be desirable to simple change
|
||||
# clusters.create in the future.
|
||||
template['net_id'] = template.get('neutron_management_network', None)
|
||||
valid_args = inspect.getargspec(cs.clusters.create).args
|
||||
for name in template.keys():
|
||||
if name not in valid_args:
|
||||
# TODO(mattf): make this verbose - bug/1271147
|
||||
del template[name]
|
||||
remap = {'neutron_management_network': 'net_id'}
|
||||
_filter_call_args(template, cs.clusters.create, remap)
|
||||
|
||||
_show_cluster(cs.clusters.create(**template))
|
||||
|
||||
|
||||
@@ -363,11 +385,8 @@ def do_node_group_template_create(cs, args):
|
||||
"""Create a node group template."""
|
||||
# TODO(mattf): improve template validation, e.g. template w/o name key
|
||||
template = json.loads(args.json.read())
|
||||
valid_args = inspect.getargspec(cs.node_group_templates.create).args
|
||||
for name in template.keys():
|
||||
if name not in valid_args:
|
||||
# TODO(mattf): make this verbose - bug/1271147
|
||||
del template[name]
|
||||
_filter_call_args(template, cs.node_group_templates.create)
|
||||
|
||||
_show_node_group_template(cs.node_group_templates.create(**template))
|
||||
|
||||
|
||||
@@ -431,11 +450,9 @@ def do_cluster_template_create(cs, args):
|
||||
"""Create a cluster template."""
|
||||
# TODO(mattf): improve template validation, e.g. template w/o name key
|
||||
template = json.loads(args.json.read())
|
||||
valid_args = inspect.getargspec(cs.cluster_templates.create).args
|
||||
for name in template.keys():
|
||||
if name not in valid_args:
|
||||
# TODO(mattf): make this verbose - bug/1271147
|
||||
del template[name]
|
||||
remap = {'neutron_management_network': 'net_id'}
|
||||
_filter_call_args(template, cs.cluster_templates.create, remap)
|
||||
|
||||
_show_cluster_template(cs.cluster_templates.create(**template))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user