X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=cmdline%2Fsfi.py;h=c7998bf3825b40356cc5671e55c23147e3267e43;hb=744c63627c2e0e3d7977d5c9cb4cc99e8976ac1e;hp=f8f8c566921baad979713f9996895cb30342d127;hpb=cf9f514821bbd91f0bd34af2b7a1a9616386306f;p=sfa.git diff --git a/cmdline/sfi.py b/cmdline/sfi.py index f8f8c566..c7998bf3 100755 --- a/cmdline/sfi.py +++ b/cmdline/sfi.py @@ -9,7 +9,7 @@ import tempfile from optparse import OptionParser from geni.util.cert import Keypair, Certificate from geni.util.credential import Credential -from geni.util.geniclient import GeniClient +from geni.util.geniclient import GeniClient, ServerException from geni.util.gid import create_uuid from geni.util.record import GeniRecord @@ -227,9 +227,8 @@ def create_cmd_parser(command, additional_cmdargs = None): "remove": "name", "add": "record", "update": "record", - "nodes": "[name]", "slices": "", - "resources": "name", + "resources": "[name]", "create": "name rspec", "delete": "name", "reset": "name", @@ -250,7 +249,7 @@ def create_cmd_parser(command, additional_cmdargs = None): parser = OptionParser(usage="sfi [sfi_options] %s [options] %s" \ % (command, cmdargs[command])) - if command in ("nodes", "resources"): + if command in ("resources"): parser.add_option("-f", "--format", dest="format",type="choice", help="display format (dns|ip|rspec)",default="rspec", choices=("dns","ip","rspec")) @@ -259,7 +258,7 @@ def create_cmd_parser(command, additional_cmdargs = None): help="type filter (user|slice|sa|ma|node|aggregate)", choices=("user","slice","sa","ma","node","aggregate", "all"), default="all") - if command in ("show", "list", "nodes", "resources"): + if command in ("show", "list", "resources"): parser.add_option("-o", "--output", dest="file", help="output XML to file", metavar="FILE", default=None) return parser @@ -305,14 +304,17 @@ def main(): (cmd_opts, cmd_args) = create_cmd_parser(command).parse_args(args[1:]) verbose = options.verbose if verbose : - print options.registry, options.sm, options.dir, options.verbose,\ - options.user, options.auth - print command - if command in ("nodes", "resources"): - print cmd_opts.format + print "Resgistry %s, sm %s, dir %s, user %s, auth %s" % (options.registry, + options.sm, + options.dir, + options.user, + options.auth) + print "Command %s" %command + if command in ("resources"): + print "resources cmd_opts %s" %cmd_opts.format elif command in ("list","show","remove"): - print cmd_opts.type - print cmd_args + print "cmd_opts.type %s" %cmd_opts.type + print "cmd_args %s" %cmd_args set_servers(options) @@ -335,6 +337,8 @@ def list(opts, args): global registry user_cred = get_user_cred() list = registry.list(user_cred, args[0]) + # filter on person, slice, site, node, etc. + # THis really should be in the filter_records funct def comment... list = filter_records(opts.type, list) display_records(list) if opts.file: @@ -390,37 +394,46 @@ def update(opts, args): user_cred = get_user_cred() rec_file = get_record_file(args[0]) record = load_record_from_file(rec_file) - if record.get_type() == "user": - cred = user_cred - elif record.get_type() in ["sa", "ma", "slice", "node"]: + if record.get_name() == user_cred.get_gid_object().get_hrn(): + cred = user_cred + else: + create = get_auth_cred() + elif record.get_type() in ["slice"]: + try: + cred = get_slice_cred(record.get_name()) + except ServerException, e: + if "PermissionError" in e.args[0]: + cred = get_auth_cred() + else: + raise + elif record.get_type() in ["sa", "ma", "node"]: cred = get_auth_cred() else: raise "unknown record type" + record.get_type() - return registry.update(cred, record) # # Slice-related commands # -# list available nodes -def nodes(opts, args): - global slicemgr - user_cred = get_user_cred() - if not opts.format: - context = None - else: - context = opts.format - results = slicemgr.list_nodes(user_cred, context) - if opts.format in ['rspec']: - display_rspec(results) - else: - display_list(results) - if (opts.file is not None): - rspec = slicemgr.list_nodes(user_cred, 'rspec') - save_rspec_to_file(rspec, opts.file) - return +# list available nodes -- now use 'resources' w/ no argument instead +#def nodes(opts, args): +# global slicemgr +# user_cred = get_user_cred() +# if not opts.format: +# context = None +# else: +# context = opts.format +# results = slicemgr.list_nodes(user_cred) +# if opts.format in ['rspec']: +# display_rspec(results) +# else: +# display_list(results) +# if (opts.file is not None): +# rspec = slicemgr.list_nodes(user_cred) +# save_rspec_to_file(rspec, opts.file) +# return # list instantiated slices def slices(opts, args): @@ -433,8 +446,12 @@ def slices(opts, args): # show rspec for named slice def resources(opts, args): global slicemgr - slice_cred = get_slice_cred(args[0]) - result = slicemgr.list_resources(slice_cred, args[0]) + if args: + slice_cred = get_slice_cred(args[0]) + result = slicemgr.get_resources(slice_cred, args[0]) + else: + user_cred = get_user_cred() + result = slicemgr.get_resources(user_cred) display_rspec(result) if (opts.file is not None): save_rspec_to_file(opts.file, result) @@ -503,12 +520,13 @@ def save_rspec_to_file(rspec, filename): return def display_records(recordList, dump = False): + ''' Print all fields in the record''' for record in recordList: display_record(record, dump) def display_record(record, dump = False): if dump: - record.dump(False) + record.dump() else: info = record.getdict() print "%s (%s)" % (info['hrn'], info['type']) @@ -533,7 +551,6 @@ def save_records_to_file(filename, recordList): def save_record_to_file(filename, record): if not filename.startswith(os.sep): filename = sfi_dir + filename - print "saving record", record.name, "to file", filename str = record.save_to_string() file(filename, "w").write(str) return