def _apply_router_gateway_info(evt, objmap):
    ''' Get the router gateways, network, and subnets'''
    if hasattr(evt, 'trait_external_gateway_info'):

        ext_gw_info = ast.literal_eval(evt.trait_external_gateway_info)
        if ext_gw_info:
            gateways = set()
            subnets = set()
            (network, subnets, gateways) = getNetSubnetsGws_from_GwInfo(ext_gw_info)

            net_id = make_id('network', network)
            subnet_ids = ['subnet-{0}'.format(x) for x in subnets]

            setattr(objmap, 'gateways', list(gateways))
            setattr(objmap, 'set_network', net_id)
            setattr(objmap, 'set_subnets', subnet_ids)
Beispiel #2
0
def _apply_router_gateway_info(evt, objmap):
    ''' Get the router gateways, network, and subnets'''
    if 'trait_external_gateway_info' in evt:

        ext_gw_info = ast.literal_eval(evt['trait_external_gateway_info'])
        if ext_gw_info:
            gateways = set()
            subnets = set()
            (network, subnets,
             gateways) = getNetSubnetsGws_from_GwInfo(ext_gw_info)

            net_id = make_id('network', network)
            subnet_ids = ['subnet-{0}'.format(x) for x in subnets]

            setattr(objmap, 'gateways', list(gateways))
            setattr(objmap, 'set_network', net_id)
            setattr(objmap, 'set_subnets', subnet_ids)
        # ---------------------------------------------------------------------
        # Insert the l3_agents -> (routers, networks, subnets, gateways) data
        # ---------------------------------------------------------------------
        for _agent in results["agents"]:
            _agent["l3_agent_routers"] = []
            _routers = set()
            _subnets = set()
            _gateways = set()
            _networks = set()

            if _agent["agent_type"].lower() == "l3 agent":
                router_data = yield neutron_client.api_call("/v2.0/agents/%s/l3-routers" % str(_agent["id"]))

                for r in router_data["routers"]:
                    _routers.add(r.get("id"))
                    (net, snets, gws) = getNetSubnetsGws_from_GwInfo(r["external_gateway_info"])
                    if net:
                        _networks.add(net)
                    _subnets = _subnets.union(snets)
                    _gateways = _gateways.union(gws)

                _agent["l3_agent_networks"] = list(_networks)
                _agent["l3_agent_subnets"] = list(_subnets)
                _agent["l3_agent_gateways"] = list(_gateways)  # Not used yet
                _agent["l3_agent_routers"] = list(_routers)

        # ---------------------------------------------------------------------
        # Insert the DHCP agents-subnets info
        # ---------------------------------------------------------------------
        for _agent in results["agents"]:
            _agent["dhcp_agent_subnets"] = []