Ignore:
Timestamp:
Jun 3, 2014 4:29:31 PM (10 years ago)
Author:
Ted Faber <faber@…>
Branches:
master
Children:
0b217d1
Parents:
ba07149
Message:

Service info in xml files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_create.py

    rba07149 rc259a77  
    1717from federation.client_lib import client_opts, exit_with_fault, RPCException, \
    1818        wrangle_standard_options, do_rpc, get_experiment_names, save_certfile,\
    19         get_abac_certs, log_authentication
     19        get_abac_certs, log_authentication, parse_service,\
     20        service_dict_to_line, ns_service_re, extract_services_from_xml
    2021from federation.util import abac_split_cert, abac_context_to_creds
    2122
     
    5859        self.set_defaults(delegate=True)
    5960
    60 def parse_service(svc):
    61     """
    62     Pasre a service entry into a hash representing a service entry in a
    63     message.  The format is:
    64         svc_name:exporter(s):importer(s):attr=val,attr=val
    65     The svc_name is teh service name, exporter is the exporting testbeds
    66     (comma-separated) importer is the importing testbeds (if any) and the rest
    67     are attr=val pairs that will become attributes of the service.  These
    68     include parameters and other such stuff.
    69     """
    70 
    71     terms = svc.split(':')
    72     svcd = { }
    73     if len(terms) < 2 or len(terms[0]) == 0 or len(terms[1]) == 0:
    74         sys.exit("Bad service description '%s': Not enough terms" % svc)
    75    
    76     svcd['name'] = terms[0]
    77     svcd['export'] = terms[1].split(",")
    78     if len(terms) > 2 and len(terms[2]) > 0:
    79         svcd['import'] = terms[2].split(",")
    80     if len(terms) > 3 and len(terms[3]) > 0:
    81         svcd['fedAttr'] = [ ]
    82         for t in terms[3].split(";"):
    83             i = t.find("=")
    84             if i != -1 :
    85                 svcd['fedAttr'].append(
    86                         {'attribute': t[0:i], 'value': t[i+1:]})
    87             else:
    88                 sys.exit("Bad service attribute '%s': no equals sign" % t)
    89     return svcd
    90 
    9161def project_export_service(master, project):
    9262    """
     
    156126
    157127# Main line
    158 service_re = re.compile('^\\s*#\\s*SERVICE:\\s*([\\S]+)')
    159128parser = fedd_create_opts()
    160129(opts, args) = parser.parse_args()
     
    173142    try:
    174143        top = topdl.topology_from_xml(filename=opts.file, top='experiment')
     144        # Pull any service descriptions from the file as well
     145        svcs = extract_services_from_xml(filename=opts.file)
    175146    except EnvironmentError:
    176147        # Can't read the file, fail now
     
    186157            # Parse all the strings that we can pull out of the file using the
    187158            # service_re.
    188             svcs.extend([parse_service(service_re.match(l).group(1)) \
    189                     for l in lines if service_re.match(l)])
     159            svcs.extend([parse_service(ns_service_re.match(l).group(1)) \
     160                    for l in lines if ns_service_re.match(l)])
    190161        except EnvironmentError:
    191162            sys.exit("Cannot read description file (%s)" %opts.file)
Note: See TracChangeset for help on using the changeset viewer.