CM_PORT=12346
-# utility methods here
-def optparse_listvalue_callback(option, option_string, value, parser):
- setattr(parser.values, option.dest, value.split(','))
-
-# a code fragment that could be helpful for argparse which unfortunately is
-# available with 2.7 only, so this feels like too strong a requirement for the client side
-#class ExtraArgAction (argparse.Action):
-# def __call__ (self, parser, namespace, values, option_string=None):
-# would need a try/except of course
-# (k,v)=values.split('=')
-# d=getattr(namespace,self.dest)
-# d[k]=v
-#####
-#parser.add_argument ("-X","--extra",dest='extras', default={}, action=ExtraArgAction,
-# help="set extra flags, testbed dependent, e.g. --extra enabled=true")
-
-def optparse_dictvalue_callback (option, option_string, value, parser):
- try:
- (k,v)=value.split('=',1)
- d=getattr(parser.values, option.dest)
- d[k]=v
- except:
- parser.print_help()
- sys.exit(1)
+from sfa.client.common import optparse_listvalue_callback, optparse_dictvalue_callback, \
+ terminal_render, filter_records
# display methods
def display_rspec(rspec, format='rspec'):
return
-def filter_records(type, records):
- filtered_records = []
- for record in records:
- if (record['type'] == type) or (type == "all"):
- filtered_records.append(record)
- return filtered_records
-
-
def credential_printable (credential_string):
credential=Credential(string=credential_string)
result=""
f.close()
return
-# used in sfi list
-def terminal_render (records,options):
- # sort records by type
- grouped_by_type={}
- for record in records:
- type=record['type']
- if type not in grouped_by_type: grouped_by_type[type]=[]
- grouped_by_type[type].append(record)
- group_types=grouped_by_type.keys()
- group_types.sort()
- for type in group_types:
- group=grouped_by_type[type]
-# print 20 * '-', type
- try: renderer=eval('terminal_render_'+type)
- except: renderer=terminal_render_default
- for record in group: renderer(record,options)
-
-def render_plural (how_many, name,names=None):
- if not names: names="%ss"%name
- if how_many<=0: return "No %s"%name
- elif how_many==1: return "1 %s"%name
- else: return "%d %s"%(how_many,names)
-
-def terminal_render_default (record,options):
- print "%s (%s)" % (record['hrn'], record['type'])
-def terminal_render_user (record, options):
- print "%s (User)"%record['hrn'],
- if record.get('reg-pi-authorities',None): print " [PI at %s]"%(" and ".join(record['reg-pi-authorities'])),
- if record.get('reg-slices',None): print " [IN slices %s]"%(" and ".join(record['reg-slices'])),
- user_keys=record.get('reg-keys',[])
- if not options.verbose:
- print " [has %s]"%(render_plural(len(user_keys),"key"))
- else:
- print ""
- for key in user_keys: print 8*' ',key.strip("\n")
-
-def terminal_render_slice (record, options):
- print "%s (Slice)"%record['hrn'],
- if record.get('reg-researchers',None): print " [USERS %s]"%(" and ".join(record['reg-researchers'])),
-# print record.keys()
- print ""
-def terminal_render_authority (record, options):
- print "%s (Authority)"%record['hrn'],
- if record.get('reg-pis',None): print " [PIS %s]"%(" and ".join(record['reg-pis'])),
- print ""
-def terminal_render_node (record, options):
- print "%s (Node)"%record['hrn']
-
# minimally check a key argument
def check_ssh_key (key):
good_ssh_key = r'^.*(?:ssh-dss|ssh-rsa)[ ]+[A-Za-z0-9+/=]+(?: .*)?$'
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', default=None)
parser.add_option('-e', '--email', dest='email', default="", help="email (mandatory for users)")
-# use --extra instead
-# parser.add_option('-u', '--url', dest='url', metavar='<url>', default=None, help="URL, useful for slices")
-# parser.add_option('-d', '--description', dest='description', metavar='<description>',
-# help='Description, useful for slices', default=None)
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='slice xrns',
callback=optparse_listvalue_callback)
parser.add_option('-p', '--pis', dest='pis', metavar='<PIs>', help='Principal Investigators/Project Managers',
default='', type="str", action='callback', callback=optparse_listvalue_callback)
-# use --extra instead
-# parser.add_option('-f', '--firstname', dest='firstname', metavar='<firstname>', help='user first name')
-# parser.add_option('-l', '--lastname', dest='lastname', metavar='<lastname>', help='user last name')
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")
if options.show_credential:
show_credentials(auth_cred)
record_dict = {}
- if len(args) > 0:
- record_filepath = args[0]
- rec_file = self.get_record_file(record_filepath)
- record_dict.update(load_record_from_file(rec_file).todict())
+ if len(args) > 1:
+ self.print_help()
+ sys.exit(1)
+ if len(args)==1:
+ try:
+ record_filepath = args[0]
+ rec_file = self.get_record_file(record_filepath)
+ record_dict.update(load_record_from_file(rec_file).todict())
+ except:
+ print "Cannot load record file %s"%record_filepath
+ sys.exit(1)
if options:
record_dict.update(load_record_from_opts(options).todict())
# we should have a type by now
self.print_help()
sys.exit(1)
target_hrn = args[0]
- gid = self.registry().CreateGid(self.my_credential_string, target_hrn, self.client_bootstrap.my_gid_string())
+ my_gid_string = open(self.client_bootstrap.my_gid()).read()
+ gid = self.registry().CreateGid(self.my_credential_string, target_hrn, my_gid_string)
if options.file:
filename = options.file
else: