コード例 #1
0
def get_nsx_router_id(session, cluster, neutron_router_id):
    """Return the NSX router uuid for a given neutron router.

    First, look up the Neutron database. If not found, execute
    a query on NSX platform as the mapping might be missing.
    """
    nsx_router_id = nsx_db.get_nsx_router_id(
        session, neutron_router_id)
    if not nsx_router_id:
        # Find logical router from backend.
        # This is a rather expensive query, but it won't be executed
        # more than once for each router in Neutron's lifetime
        nsx_routers = routerlib.query_lrouters(
            cluster, '*',
            filters={'tag': neutron_router_id,
                     'tag_scope': 'q_router_id'})
        # Only one result expected
        # NOTE(salv-orlando): Not handling the case where more than one
        # port is found with the same neutron port tag
        if not nsx_routers:
            LOG.warn(_LW("Unable to find NSX router for Neutron router %s"),
                     neutron_router_id)
            return
        nsx_router = nsx_routers[0]
        nsx_router_id = nsx_router['uuid']
        with session.begin(subtransactions=True):
            # Create DB mapping
            nsx_db.add_neutron_nsx_router_mapping(
                session,
                neutron_router_id,
                nsx_router_id)
    return nsx_router_id
コード例 #2
0
ファイル: nsx_utils.py プロジェクト: 50infivedays/neutron
def get_nsx_router_id(session, cluster, neutron_router_id):
    """Return the NSX router uuid for a given neutron router.

    First, look up the Neutron database. If not found, execute
    a query on NSX platform as the mapping might be missing.
    """
    nsx_router_id = nsx_db.get_nsx_router_id(
        session, neutron_router_id)
    if not nsx_router_id:
        # Find logical router from backend.
        # This is a rather expensive query, but it won't be executed
        # more than once for each router in Neutron's lifetime
        nsx_routers = routerlib.query_lrouters(
            cluster, '*',
            filters={'tag': neutron_router_id,
                     'tag_scope': 'q_router_id'})
        # Only one result expected
        # NOTE(salv-orlando): Not handling the case where more than one
        # port is found with the same neutron port tag
        if not nsx_routers:
            LOG.warn(_("Unable to find NSX router for Neutron router %s"),
                     neutron_router_id)
            return
        nsx_router = nsx_routers[0]
        nsx_router_id = nsx_router['uuid']
        with session.begin(subtransactions=True):
            # Create DB mapping
            nsx_db.add_neutron_nsx_router_mapping(
                session,
                neutron_router_id,
                nsx_router_id)
    return nsx_router_id
コード例 #3
0
ファイル: test_nsx_plugin.py プロジェクト: B-Rich/neutron
 def _nsx_validate_ext_gw(self, router_id, l3_gw_uuid, vlan_id):
     """Verify data on fake NSX API client in order to validate
     plugin did set them properly
     """
     # First find the NSX router ID
     ctx = context.get_admin_context()
     nsx_router_id = nsx_db.get_nsx_router_id(ctx.session, router_id)
     ports = [
         port
         for port in self.fc._fake_lrouter_lport_dict.values()
         if (port["lr_uuid"] == nsx_router_id and port["att_type"] == "L3GatewayAttachment")
     ]
     self.assertEqual(len(ports), 1)
     self.assertEqual(ports[0]["attachment_gwsvc_uuid"], l3_gw_uuid)
     self.assertEqual(ports[0].get("vlan_id"), vlan_id)