X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fclient%2Fsfi.py;h=25f81f2222e31a004dc424e739afbd2638a95707;hb=0943c9135dade2921b6d0ca0f9266bb81182438f;hp=3699d55586f0bc2c5c717302241c543075b9890d;hpb=27e30f7854884928bd4850afa3c6ce5c7f93f7f4;p=sfa.git diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index 3699d555..25f81f22 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -184,8 +184,22 @@ def check_ssh_key (key): return re.match(good_ssh_key, key, re.IGNORECASE) # load methods +def normalize_type (type): + if type.startswith('au'): + return 'authority' + elif type.startswith('us'): + return 'user' + elif type.startswith('sl'): + return 'slice' + elif type.startswith('no'): + return 'node' + else: + return None + def load_record_from_opts(options): record_dict = {} + if hasattr(options, 'type'): + options.type = normalize_type(options.type) if hasattr(options, 'xrn') and options.xrn: if hasattr(options, 'type') and options.type: xrn = Xrn(options.xrn, options.type) @@ -208,6 +222,9 @@ def load_record_from_opts(options): record_dict['reg-researchers'] = options.reg_researchers if hasattr(options, 'email') and options.email: record_dict['email'] = options.email + # authorities can have a name for standalone deployment + if hasattr(options, 'name') and options.name: + record_dict['name'] = options.name if hasattr(options, 'reg_pis') and options.reg_pis: record_dict['reg-pis'] = options.reg_pis @@ -423,6 +440,7 @@ class Sfi: parser.add_option('-x', '--xrn', dest='xrn', metavar='', help='object hrn/urn (mandatory)') parser.add_option('-t', '--type', dest='type', metavar='', help='object type', 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='', help='public key string or file', default=None) parser.add_option('-s', '--slices', dest='slices', metavar='', help='Set/replace slice xrns', @@ -1056,7 +1074,7 @@ use this if you mean an authority instead""") if options: record_dict.update(load_record_from_opts(options).todict()) # at the very least we need 'type' here - if 'type' not in record_dict: + if 'type' not in record_dict or record_dict['type'] is None: self.print_help() sys.exit(1) @@ -1082,7 +1100,7 @@ use this if you mean an authority instead""") elif record_dict['type'] in ['node']: cred = self.my_authority_credential_string() else: - raise "unknown record type" + record_dict['type'] + raise Exception("unknown record type {}".format(record_dict['type'])) if options.show_credential: show_credentials(cred) update = self.registry().Update(record_dict, cred)