Example #1
0
def concretize_networks(resources, vlans, subnets):
    # avoid any non-determinism
    s_vlans = sorted(vlans, key=lambda v: (v["site"], v["vlan_id"]))
    s_subnets = sorted(subnets, key=lambda s: (s["site"], s["ip_prefix"]))
    pools = mk_pools(s_vlans, lambda n:
                     (n["site"], to_vlan_type(n["vlan_id"])))
    pools_subnets = mk_pools(
        s_subnets, lambda n: (n["site"], to_subnet_type(n["ip_prefix"])))

    for desc in resources["networks"]:
        site = desc["site"]
        site_info = ex5.get_resource_attributes('/sites/%s' % site)
        n_type = desc["type"]
        if n_type == PROD:
            desc["_c_network"] = {"site": site, "vlan_id": None}
            desc["_c_network"].update(site_info["kavlans"]["default"])
        elif n_type in KAVLAN_TYPE:
            networks = pick_things(pools, (site, n_type), 1)
            if len(networks) < 1:
                raise MissingNetworkError(site, n_type)
            # concretize the network
            desc["_c_network"] = networks[0]
            vlan_id = desc["_c_network"]["vlan_id"]
            desc["_c_network"].update(site_info["kavlans"][str(vlan_id)])
        elif n_type in SUBNET_TYPE:
            networks = pick_things(pools_subnets, (site, n_type), 1)
            if len(networks) < 1:
                raise MissingNetworkError(site, n_type)
            desc["_c_network"] = networks[0]

    return resources
Example #2
0
def concretize_networks(resources, vlans):
    s_vlans = sorted(vlans, key=lambda v: (v["site"], v["vlan_id"]))
    pools = mk_pools(s_vlans, lambda n:
                     (n["site"], to_vlan_type(n["vlan_id"])))
    for desc in resources["networks"]:
        site = desc["site"]
        site_info = ex5.get_resource_attributes('/sites/%s' % site)
        n_type = desc["type"]
        if n_type == PROD:
            desc["_c_network"] = {"site": site, "vlan_id": None}
            desc["_c_network"].update(site_info["kavlans"]["default"])
        else:
            networks = pick_things(pools, (site, n_type), 1)
            if len(networks) < 1:
                raise MissingNetworkError(site, n_type)
            # concretize the network
            desc["_c_network"] = networks[0]
            vlan_id = desc["_c_network"]["vlan_id"]
            desc["_c_network"].update(site_info["kavlans"][str(vlan_id)])
Example #3
0
def concretize_networks(resources, networks):
    """Maps abstract to concrete networks.

    Warning:
        Side effect on resources
    """
    s_networks = sorted(networks, key=lambda n: (n.site, n.nature, n.network))
    pools = mk_pools(s_networks, lambda n: (n.site, n.nature))
    for desc in resources["networks"]:
        site = desc["site"]
        n_type = desc["type"]
        # On grid'5000 a slash_16 is 64 slash_22
        # So if we ask for a slash_16 we return 64 sash_22
        # yes, this smells
        if n_type == SLASH_16:
            _networks = pick_things(pools, (site, SLASH_22), 64)
        else:
            _networks = pick_things(pools, (site, n_type), 1)
        if len(_networks) < 1:
            raise MissingNetworkError(site, n_type)
        desc["_c_network"] = _networks

    return resources