+ def create_parser_command(self, command):
+ if command not in commands_dict:
+ msg = "Invalid command\n"
+ msg += "Commands: "
+ msg += ','.join(commands_list)
+ logger.critical(msg)
+ sys.exit(2)
+
+ # retrieve args_string
+ (_, args_string, __, canonical) = commands_dict[command]
+
+ parser = OptionParser(add_help_option=False,
+ usage="sfi [sfi_options] {} [cmd_options] {}"
+ .format(command, args_string))
+ parser.add_option("-h", "--help", dest='help', action='store_true', default=False,
+ help="Summary of one command usage")
+
+ if canonical in ("config"):
+ parser.add_option('-m', '--myslice', dest='myslice', action='store_true', default=False,
+ help='how myslice config variables as well')
+
+ if canonical in ("version"):
+ parser.add_option("-l", "--local",
+ action="store_true", dest="version_local", default=False,
+ help="display version of the local client")
+
+ if canonical in ("version", "trusted", "introspect"):
+ parser.add_option("-R", "--registry_interface",
+ action="store_true", dest="registry_interface", default=False,
+ help="target the registry interface instead of slice interface")
+
+ if canonical in ("register", "update"):
+ parser.add_option('-x', '--xrn', dest='xrn',
+ metavar='<xrn>', help='object hrn/urn (mandatory)')
+ parser.add_option('-t', '--type', dest='type', metavar='<type>',
+ help='object type (2 first chars is enough)', default=None)
+ parser.add_option('-e', '--email', dest='email',
+ default="", help="email (mandatory for users)")
+ parser.add_option('-n', '--name', dest='name',
+ default="", help="name (optional for authorities)")
+ parser.add_option('-k', '--key', dest='key', metavar='<key>', help='public key string or file',
+ default=None)
+ parser.add_option('-s', '--slices', dest='slices', metavar='<slices>', help='Set/replace slice xrns',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ parser.add_option('-r', '--researchers', dest='reg_researchers', metavar='<researchers>',
+ help='Set/replace slice researchers - use -r none to reset', default=None, type="str", action='callback',
+ callback=optparse_listvalue_callback)
+ parser.add_option('-p', '--pis', dest='reg_pis', metavar='<PIs>', help='Set/replace Principal Investigators/Project Managers',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ parser.add_option('-X', '--extra', dest='extras', default={}, type='str', metavar="<EXTRA_ASSIGNS>",
+ action="callback", callback=optparse_dictvalue_callback, nargs=1,
+ help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
+
+ # user specifies remote aggregate/sm/component
+ if canonical in ("resources", "describe", "allocate", "provision", "delete", "allocate", "provision",
+ "action", "shutdown", "renew", "status"):
+ parser.add_option("-d", "--delegate", dest="delegate", default=None,
+ action="store_true",
+ help="Include a credential delegated to the user's root" +
+ "authority in set of credentials for this call")
+
+ # show_credential option
+ if canonical in ("list", "resources", "describe", "provision", "allocate", "register",
+ "update", "remove", "delete", "status", "renew"):
+ parser.add_option("-C", "--credential", dest='show_credential', action='store_true', default=False,
+ help="show credential(s) used in human-readable form")
+ if canonical in ("renew"):
+ parser.add_option("-l", "--as-long-as-possible", dest='alap', action='store_true', default=False,
+ help="renew as long as possible")
+ # registy filter option
+ if canonical in ("list", "show", "remove"):
+ parser.add_option("-t", "--type", dest="type", metavar="<type>",
+ default="all",
+ help="type filter - 2 first chars is enough ([all]|user|slice|authority|node|aggregate)")
+ if canonical in ("show"):
+ parser.add_option("-k", "--key", dest="keys", action="append", default=[],
+ help="specify specific keys to be displayed from record")
+ parser.add_option("-n", "--no-details", dest="no_details", action="store_true", default=False,
+ help="call Resolve without the 'details' option")
+ if canonical in ("resources", "describe"):
+ # rspec version
+ parser.add_option("-r", "--rspec-version", dest="rspec_version", default=DEFAULT_RSPEC_VERSION,
+ help="schema type and version of resulting RSpec (default:{})".format(DEFAULT_RSPEC_VERSION))
+ # disable/enable cached rspecs
+ parser.add_option("-c", "--current", dest="current", default=False,
+ action="store_true",
+ help="Request the current rspec bypassing the cache. Cached rspecs are returned by default")
+ # display formats
+ parser.add_option("-f", "--format", dest="format", type="choice",
+ help="display format ([xml]|dns|ip)", default="xml",
+ choices=("xml", "dns", "ip"))
+ # panos: a new option to define the type of information about
+ # resources a user is interested in
+ parser.add_option("-i", "--info", dest="info",
+ help="optional component information", default=None)
+ # a new option to retrieve or not reservation-oriented RSpecs
+ # (leases)
+ parser.add_option("-l", "--list_leases", dest="list_leases", type="choice",
+ help="Retrieve or not reservation-oriented RSpecs ([resources]|leases|all)",
+ choices=("all", "resources", "leases"), default="resources")
+
+ if canonical in ("resources", "describe", "allocate", "provision", "show", "list", "gid"):
+ parser.add_option("-o", "--output", dest="file",
+ help="output XML to file", metavar="FILE", default=None)
+
+ if canonical in ("show", "list"):
+ parser.add_option("-f", "--format", dest="format", type="choice",
+ help="display format ([text]|xml)", default="text",
+ choices=("text", "xml"))
+
+ parser.add_option("-F", "--fileformat", dest="fileformat", type="choice",
+ help="output file format ([xml]|xmllist|hrnlist)", default="xml",
+ choices=("xml", "xmllist", "hrnlist"))
+ if canonical == 'list':
+ parser.add_option("-r", "--recursive", dest="recursive", action='store_true',
+ help="list all child records", default=False)
+ parser.add_option("-v", "--verbose", dest="verbose", action='store_true',
+ help="gives details, like user keys", default=False)
+ if canonical in ("delegate"):
+ parser.add_option("-u", "--user",
+ action="store_true", dest="delegate_user", default=False,
+ help="delegate your own credentials; default if no other option is provided")
+ parser.add_option("-s", "--slice", dest="delegate_slices", action='append', default=[],
+ metavar="slice_hrn", help="delegate cred. for slice HRN")
+ parser.add_option("-a", "--auths", dest='delegate_auths', action='append', default=[],
+ metavar='auth_hrn', help="delegate cred for auth HRN")
+ # this primarily is a shorthand for -A my_hrn^
+ parser.add_option("-p", "--pi", dest='delegate_pi', default=None, action='store_true',
+ help="delegate your PI credentials, so s.t. like -A your_hrn^")
+ parser.add_option("-A", "--to-authority", dest='delegate_to_authority', action='store_true', default=False,
+ help="""by default the mandatory argument is expected to be a user,
+use this if you mean an authority instead""")
+
+ if canonical in ("myslice"):
+ parser.add_option("-p", "--password", dest='password', action='store', default=None,
+ help="specify mainfold password on the command line")
+ parser.add_option("-s", "--slice", dest="delegate_slices", action='append', default=[],
+ metavar="slice_hrn", help="delegate cred. for slice HRN")
+ parser.add_option("-a", "--auths", dest='delegate_auths', action='append', default=[],
+ metavar='auth_hrn', help="delegate PI cred for auth HRN")
+ parser.add_option('-d', '--delegate', dest='delegate',
+ help="Override 'delegate' from the config file")
+ parser.add_option('-b', '--backend', dest='backend',
+ help="Override 'backend' from the config file")
+
+ return parser