コード例 #1
0
ファイル: vo_yaml_to_xml.py プロジェクト: bbockelm/topology
def expand_contacttypes(contacts: Dict) -> Dict:
    """Expand
    {"Submitter Contact": ["a", "b"],
     "Miscellaneous Contact": ["c", "d"]}
    to
    {"ContactType": [{"Type": "Submitter Contact", {"Contacts": {"Contact": [{"Name": "a"}, {"Name": "b"}]}}},
                     {"Type": "Miscellaneous Contact", {"Contacts": {"Contact": [{"Name": "a"}, {"Name": "b"}]}}}
                    ]
    }
    """
    new_contacttypes = []
    for type_, list_ in contacts.items():
        contact_data = singleton_list_to_value([{"Name": x} for x in list_])
        new_contacttypes.append({
            "Type": type_,
            "Contacts": {
                "Contact": contact_data
            }
        })
    return {"ContactType": singleton_list_to_value(new_contacttypes)}
コード例 #2
0
ファイル: vo_yaml_to_xml.py プロジェクト: bbockelm/topology
def expand_fields_of_science(fields_of_science):
    """Turn
    {"PrimaryFields": ["P1", "P2", ...],
     "SecondaryFields": ["S1", "S2", ...]}
    into
    {"PrimaryFields": {"Field": ["P1", "P2", ...]},
     "SecondaryFields": {"Field": ["S1", "S2", ...]}}
    """
    if is_null(fields_of_science, "PrimaryFields"):
        return None
    new_fields = OrderedDict()
    new_fields["PrimaryFields"] = {
        "Field": singleton_list_to_value(fields_of_science["PrimaryFields"])
    }
    if not is_null(fields_of_science, "SecondaryFields"):
        new_fields["SecondaryFields"] = {
            "Field":
            singleton_list_to_value(fields_of_science["SecondaryFields"])
        }
    return new_fields
コード例 #3
0
ファイル: vo_yaml_to_xml.py プロジェクト: bbockelm/topology
def expand_reportinggroups(reportinggroups_list: List,
                           reportinggroups_data: Dict) -> Dict:
    """Expand
    ["XXX", "YYY", "ZZZ"]
    using data from reportinggroups_data into
    {"ReportingGroup": [{"Contacts": {"Contact": [{"Name": "a"},
                                                 {"Name": "b"}
                                     },
                         "FQANs": {"FQAN": [{"GroupName": "...",
                                             "Role": "..."}]
                                  }
                         "Name": "XXX"
                       }]
    }
    """
    new_reportinggroups = {}
    for name, data in reportinggroups_data.items():
        if name not in reportinggroups_list: continue
        new_reportinggroups[name] = {}
        newdata = new_reportinggroups[name]
        if not is_null(data, "Contacts"):
            new_contact = [{"Name": x} for x in data["Contacts"]]
            newdata["Contacts"] = {
                "Contact": singleton_list_to_value(new_contact)
            }
        else:
            newdata["Contacts"] = None
        if not is_null(data, "FQANs"):
            fqans = []
            for fqan in data["FQANs"]:
                fqans.append(
                    OrderedDict([("GroupName", fqan["GroupName"]),
                                 ("Role", fqan["Role"])]))
            newdata["FQANs"] = {"FQAN": singleton_list_to_value(fqans)}
        else:
            newdata["FQANs"] = None
    new_reportinggroups = expand_attr_list(
        new_reportinggroups, "Name", ordering=["Name", "FQANs", "Contacts"])
    return {"ReportingGroup": new_reportinggroups}
コード例 #4
0
def expand_contactlists(contactlists: Dict) -> Dict:
    """Return the data structure for an expanded ContactLists for a single Resource."""
    new_contactlists = []
    for contact_type, contact_data in contactlists.items():
        contact_data = expand_attr_list_single(contact_data,
                                               "ContactRank",
                                               "Name",
                                               name_first=False)
        new_contactlists.append(
            OrderedDict([("ContactType", contact_type),
                         ("Contacts", {
                             "Contact": contact_data
                         })]))
    return {"ContactList": singleton_list_to_value(new_contactlists)}
コード例 #5
0
def expand_resource(name: str, res: Dict,
                    service_name_to_id: Dict[str, int]) -> OrderedDict:
    """Expand a single Resource from the format in a yaml file to the xml format.

    Services, VOOwnership, FQDNAliases, ContactLists are expanded;
    ``name`` is inserted into the Resource as the "Name" attribute;
    Defaults are added for VOOwnership, FQDNAliases, and WLCGInformation if they're missing from the yaml file.

    Return the data structure for the expanded Resource as an OrderedDict to fit the xml schema.
    """
    defaults = {
        "ContactLists": None,
        "FQDNAliases": None,
        "Services": "no applicable service exists",
        "VOOwnership": "(Information not available)",
        "WLCGInformation": "(Information not available)",
    }

    res = dict(res)

    if not is_null(res, "Services"):
        res["Services"] = expand_services(res["Services"], service_name_to_id)
    else:
        res.pop("Services", None)
    if "VOOwnership" in res:
        res["VOOwnership"] = expand_voownership(res["VOOwnership"])
    if "FQDNAliases" in res:
        res["FQDNAliases"] = {
            "FQDNAlias": singleton_list_to_value(res["FQDNAliases"])
        }
    if not is_null(res, "ContactLists"):
        res["ContactLists"] = expand_contactlists(res["ContactLists"])
    res["Name"] = name
    if "WLCGInformation" in res and isinstance(res["WLCGInformation"], dict):
        res["WLCGInformation"] = expand_wlcginformation(res["WLCGInformation"])
    new_res = OrderedDict()
    for elem in [
            "ID", "Name", "Active", "Disable", "Services", "Description",
            "FQDN", "FQDNAliases", "VOOwnership", "WLCGInformation",
            "ContactLists"
    ]:
        if elem in res:
            new_res[elem] = res[elem]
        elif elem in defaults:
            new_res[elem] = defaults[elem]

    return new_res
コード例 #6
0
ファイル: vo_yaml_to_xml.py プロジェクト: bbockelm/topology
def expand_oasis_managers(managers):
    """Expand
    {"a": {"DNs": [...]}}
    into
    {"Manager": [{"Name": "a", "DNs": {"DN": [...]}}]}
    """
    new_managers = managers.copy()
    for name, data in managers.items():
        if not is_null(data, "DNs"):
            new_managers[name]["DNs"] = {
                "DN": singleton_list_to_value(data["DNs"])
            }
        else:
            new_managers[name]["DNs"] = None
    return {
        "Manager":
        expand_attr_list(new_managers,
                         "Name",
                         ordering=["ContactID", "Name", "DNs"],
                         ignore_missing=True)
    }
コード例 #7
0
def expand_resourcegroup(
        rg: Dict, service_name_to_id: Dict[str, int],
        support_center_name_to_id: Dict[str, int]) -> OrderedDict:
    """Expand a single ResourceGroup from the format in a yaml file to the xml format.

    {"SupportCenterName": ...} and {"SupportCenterID": ...} are turned into
    {"SupportCenter": {"Name": ...}, {"ID": ...}} and each individual Resource is expanded and collected in a
    <Resources> block.

    Return the data structure for the expanded ResourceGroup, as an OrderedDict,
    with the ordering to fit the xml schema for rgsummary.
    """
    rg = dict(rg)  # copy

    scname, scid = rg["SupportCenter"], support_center_name_to_id[
        rg["SupportCenter"]]
    rg["SupportCenter"] = OrderedDict([("ID", scid), ("Name", scname)])

    new_resources = []
    for name, res in rg["Resources"].items():
        try:
            res = expand_resource(name, res, service_name_to_id)
            new_resources.append(res)
        except Exception:
            pprint.pprint(res, stream=sys.stderr)
            raise
    new_resources.sort(key=lambda x: x["Name"])
    rg["Resources"] = {"Resource": singleton_list_to_value(new_resources)}

    new_rg = OrderedDict()

    for elem in [
            "GridType", "GroupID", "GroupName", "Disable", "Facility", "Site",
            "SupportCenter", "GroupDescription", "Resources"
    ]:
        if elem in rg:
            new_rg[elem] = rg[elem]

    return new_rg
コード例 #8
0
ファイル: vo_yaml_to_xml.py プロジェクト: bbockelm/topology
def expand_vo(vo, reportinggroups_data):
    vo = vo.copy()

    if is_null(vo, "Contacts"):
        vo["ContactTypes"] = None
    else:
        vo["ContactTypes"] = expand_contacttypes(vo["Contacts"])
    vo.pop("Contacts", None)
    if is_null(vo, "ReportingGroups"):
        vo["ReportingGroups"] = None
    else:
        vo["ReportingGroups"] = expand_reportinggroups(vo["ReportingGroups"],
                                                       reportinggroups_data)
    if is_null(vo, "OASIS"):
        vo["OASIS"] = None
    else:
        oasis = OrderedDict()
        oasis["UseOASIS"] = vo["OASIS"].get("UseOASIS", False)
        if is_null(vo["OASIS"], "Managers"):
            oasis["Managers"] = None
        else:
            oasis["Managers"] = expand_oasis_managers(vo["OASIS"]["Managers"])
        if is_null(vo["OASIS"], "OASISRepoURLs"):
            oasis["OASISRepoURLs"] = None
        else:
            oasis["OASISRepoURLs"] = {
                "URL": singleton_list_to_value(vo["OASIS"]["OASISRepoURLs"])
            }
        vo["OASIS"] = oasis
    if is_null(vo, "FieldsOfScience"):
        vo["FieldsOfScience"] = None
    else:
        vo["FieldsOfScience"] = expand_fields_of_science(vo["FieldsOfScience"])

    # Restore ordering
    if not is_null(vo, "ParentVO"):
        parentvo = OrderedDict()
        for elem in ["ID", "Name"]:
            if elem in vo["ParentVO"]:
                parentvo[elem] = vo["ParentVO"][elem]
        vo["ParentVO"] = parentvo
    else:
        vo["ParentVO"] = None

    for key in [
            "MembershipServicesURL", "PrimaryURL", "PurposeURL", "SupportURL"
    ]:
        if key not in vo:
            vo[key] = None

    # TODO: Recreate <MemeberResources> [sic]
    #  should look like
    #  <MemeberResources>
    #    <Resource><ID>75</ID><Name>NERSC-PDSF</Name></Resource>
    #    ...
    #  </MemeberResources>

    # Restore ordering
    new_vo = OrderedDict()
    for elem in [
            "ID",
            "Name",
            "LongName",
            "CertificateOnly",
            "PrimaryURL",
            "MembershipServicesURL",
            "PurposeURL",
            "SupportURL",
            "AppDescription",
            "Community",
            # TODO "MemeberResources",
            "FieldsOfScience",
            "ParentVO",
            "ReportingGroups",
            "Active",
            "Disable",
            "ContactTypes",
            "OASIS"
    ]:
        if elem in vo:
            new_vo[elem] = vo[elem]

    return new_vo