Commit ab71c903 authored by David Johnson's avatar David Johnson

Improve eval-based CLI param handling.

parent 3f75620c
......@@ -309,6 +309,30 @@ def parse_rspec_arg(_rspec):
" but assuming it is indeed XML!")
return _rspec
pass
def parse_safe_eval(value):
retval = None
try:
retval = eval(value)
return retval
except:
LOG.exception("Argument must be Python code")
raise Exception("Argument must be Python code")
pass
def parse_safe_list_or_eval(value):
retval = None
try:
retval = eval(value)
return retval
except:
pass
try:
_list = value.split(',')
return _list
except:
pass
raise Exception("Argument must be Python code, or a list of strings")
#
# By default, adjust our credential caching time by this much to give a
......@@ -2537,12 +2561,12 @@ class ProtoGeniServer(object):
@ApplicableMethod(
excluded=['selfcredential','URI'],
kwargs=[dict(name='nodes',type=eval,required=True)])
kwargs=[dict(name='nodes',type=parse_safe_eval,required=True)])
def add_nodes(self,nodes={},slicename=None,cm=None,URI=None,selfcredential=None):
"""
Add nodes to a sliver at a CM.
:param nodes: Specify a dictionary of CMv2::AddNodes arguments
:param nodes: A Python dictionary where each key/val pair comforms to the specifications for the 'nodes' parameter to the CMv2::AddNodes method.
:param slicename: Specify a slice URN
:param cm: Specify a CM; otherwise the default CM will be used
"""
......@@ -2588,15 +2612,15 @@ class ProtoGeniServer(object):
pass
self.__put_lock()
return manifest
@ApplicableMethod(
excluded=['selfcredential','URI'],
kwargs=[dict(name='nodes',type=eval,required=True)])
kwargs=[dict(name='nodes',type=parse_safe_list_or_eval,required=True)])
def delete_nodes(self,nodes=[],slicename=None,cm=None,URI=None,selfcredential=None):
"""
Delete nodes from a sliver at a CM.
:param nodes: Specify a list of CMv2::DeleteNodes arguments
:param nodes: A list of logical or physical node IDs that are in your slice.
:param slicename: Specify a slice URN
:param cm: Specify a CM; otherwise the default CM will be used
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment