Esempio n. 1
0
    def add_router_interface(self, context, router_id, interface_info):
        add_by_port, add_by_sub = self._validate_interface_info(
            interface_info)
        if add_by_sub:
            subnet = self.get_subnet(context, interface_info['subnet_id'])
            port = {'port': {'network_id': subnet['network_id'], 'name': '',
                             'admin_state_up': True, 'device_id': '',
                             'device_owner': l3_db.DEVICE_OWNER_ROUTER_INTF,
                             'mac_address': attr.ATTR_NOT_SPECIFIED,
                             'fixed_ips': [{'subnet_id': subnet['id'],
                                            'ip_address':
                                                subnet['gateway_ip']}]}}
            port = self.create_port(context, port)
        elif add_by_port:
            port = self.get_port(context, interface_info['port_id'])
            subnet_id = port['fixed_ips'][0]['subnet_id']
            subnet = self.get_subnet(context, subnet_id)

        lrouter = utils.ovn_name(router_id)
        lswitch = utils.ovn_name(subnet['network_id'])
        cidr = netaddr.IPNetwork(subnet['cidr'])
        network = "%s/%s" % (port['fixed_ips'][0]['ip_address'],
                             str(cidr.prefixlen))

        logical_port = self.nb_api.get_logical_port(port['id'])
        self.nb_api.add_lrouter_port(port['id'], lrouter, lswitch,
                                     mac=port['mac_address'],
                                     network=network,
                                     tunnel_key=logical_port.get_tunnel_key())
        interface_info['port_id'] = port['id']
        if 'subnet_id' in interface_info:
            del interface_info['subnet_id']
        return super(DFPlugin, self).add_router_interface(
            context, router_id, interface_info)
Esempio n. 2
0
    def remove_router_interface(self, context, router_id, interface_info):
        new_router = super(DFPlugin, self).remove_router_interface(
            context, router_id, interface_info)

        subnet = self.get_subnet(context, new_router['subnet_id'])
        network_id = subnet['network_id']

        self.nb_api.delete_lrouter_port(utils.ovn_name(router_id),
                                        utils.ovn_name(network_id))
Esempio n. 3
0
    def create_port_in_nb_api(self, port):
        # The port name *must* be port['id'].  It must match the iface-id set
        # in the Interfaces table of the Open_vSwitch database, which nova sets
        # to be the port ID.
        external_ids = {ovn_const.OVN_PORT_NAME_EXT_ID_KEY: port['name']}
        parent_name, tag = self._get_data_from_binding_profile(port)
        allowed_macs = self._get_allowed_mac_addresses_from_port(port)
        ips = []
        if 'fixed_ips' in port:
            if 'ip_address' in port['fixed_ips'][0]:
                ips.append(port['fixed_ips'][0]['ip_address'])

        chassis = None
        if 'binding:host_id' in port:
            chassis = port['binding:host_id']

        tunnel_key = self._allocate_tunnel_key()

        self.nb_api.create_lport(
            name=port['id'],
            lswitch_name=utils.ovn_name(port['network_id']),
            macs=[port['mac_address']], ips=ips,
            external_ids=external_ids,
            parent_name=parent_name, tag=tag,
            enabled=port.get('admin_state_up', None),
            chassis=chassis, tunnel_key=tunnel_key,
            port_security=allowed_macs)

        return port
Esempio n. 4
0
 def delete_subnet(self, context, id):
     orig_subnet = super(DFPlugin, self).get_subnet(context, id)
     net_id = orig_subnet['network_id']
     with context.session.begin(subtransactions=True):
         # delete subnet in DB
         super(DFPlugin, self).delete_subnet(context, id)
         # update df controller with subnet delete
         self.nb_api.delete_subnet(id, utils.ovn_name(net_id))
Esempio n. 5
0
 def delete_router(self, context, router_id):
     router_name = utils.ovn_name(router_id)
     try:
         self.nb_api.delete_lrouter(router_name)
     except df_exceptions.DBKeyNotFound:
         LOG.debug("router %s is not found in DF DB, might have "
                   "been deleted concurrently" % router_name)
     ret_val = super(DFPlugin, self).delete_router(context,
                                                   router_id)
     return ret_val
Esempio n. 6
0
 def delete_network(self, context, network_id):
     with context.session.begin(subtransactions=True):
         super(DFPlugin, self).delete_network(context,
                                              network_id)
     # TODO(gsagie) this patch is used to remove DHCP port
     # remove when we implement distributed DHCP service and dont use
     # q-dhcp
     for port in self.nb_api.get_all_logical_ports():
         if port.get_lswitch_id() == utils.ovn_name(network_id):
             try:
                 self.nb_api.delete_lport(port.get_id())
             except df_exceptions.DBKeyNotFound:
                 LOG.debug("port %s is not found in DB, might have"
                           "been deleted concurrently" % port.get_id())
     try:
         self.nb_api.delete_lswitch(utils.ovn_name(network_id))
     except df_exceptions.DBKeyNotFound:
         LOG.debug("lswitch %s is not found in DF DB, might have "
                   "been deleted concurrently" % utils.ovn_name(network_id))
Esempio n. 7
0
    def create_router(self, context, router):
        router = super(DFPlugin, self).create_router(
            context, router)
        router_name = utils.ovn_name(router['id'])
        external_ids = {ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY:
                        router.get('name', 'no_router_name')}
        self.nb_api.create_lrouter(router_name, external_ids=external_ids)

        # TODO(gsagie) rollback router creation on OVN failure
        return router
Esempio n. 8
0
    def create_network_nb_api(self, network):
        # Create a logical switch with a name equal to the Neutron network
        # UUID.  This provides an easy way to refer to the logical switch
        # without having to track what UUID OVN assigned to it.
        external_ids = {ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY: network['name']}

        # TODO(DF): Undo logical switch creation on failure
        self.nb_api.create_lswitch(name=utils.ovn_name(network['id']),
                                   external_ids=external_ids)
        return network
Esempio n. 9
0
 def update_subnet(self, context, id, subnet):
     with context.session.begin(subtransactions=True):
         # update subnet in DB
         new_subnet = super(DFPlugin,
                            self).update_subnet(context, id, subnet)
         net_id = new_subnet['network_id']
         # update df controller with subnet
         self.nb_api.update_subnet(
             new_subnet['id'],
             utils.ovn_name(net_id),
             enable_dhcp=new_subnet['enable_dhcp'],
             cidr=new_subnet['cidr'],
             dhcp_ip=new_subnet['allocation_pools'][0]['start'],
             gateway_ip=new_subnet['gateway_ip'],
             dns_nameservers=new_subnet.get('dns_nameservers', []))
         return new_subnet
Esempio n. 10
0
    def create_port_in_nb_api(self, port, parent_name, tag, sgids):
        # The port name *must* be port['id'].  It must match the iface-id set
        # in the Interfaces table of the Open_vSwitch database, which nova sets
        # to be the port ID.
        external_ids = {ovn_const.OVN_PORT_NAME_EXT_ID_KEY: port['name']}
        allowed_macs = self._get_allowed_mac_addresses_from_port(port)
        ips = []
        if 'fixed_ips' in port:
            if 'ip_address' in port['fixed_ips'][0]:
                ips.append(port['fixed_ips'][0]['ip_address'])

        chassis = None
        if 'binding:host_id' in port:
            chassis = port['binding:host_id']

        tunnel_key = self.nb_api.allocate_tunnel_key()

        # Router GW ports are not needed by dragonflow controller and
        # they currently cause error as they couldnt be mapped to
        # a valid ofport (or location)
        if port.get('device_owner') == const.DEVICE_OWNER_ROUTER_GW:
            chassis = None

        self.nb_api.create_lport(
            name=port['id'],
            lswitch_name=utils.ovn_name(port['network_id']),
            macs=[port['mac_address']], ips=ips,
            external_ids=external_ids,
            parent_name=parent_name, tag=tag,
            enabled=port.get('admin_state_up', None),
            chassis=chassis, tunnel_key=tunnel_key,
            port_security=allowed_macs,
            device_owner=port.get('device_owner', None),
            sgids=sgids)

        return port
Esempio n. 11
0
 def _set_network_name(self, network_id, name):
     ext_id = [ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY, name]
     self.nb_api.update_lswitch(utils.ovn_name(network_id),
                                external_ids=ext_id)
Esempio n. 12
0
 def delete_router(self, context, router_id):
     router_name = utils.ovn_name(router_id)
     self.nb_api.delete_lrouter(router_name)
     ret_val = super(DFPlugin, self).delete_router(context,
                                                   router_id)
     return ret_val
Esempio n. 13
0
 def delete_network(self, context, network_id):
     with context.session.begin():
         super(DFPlugin, self).delete_network(context,
                                              network_id)
     self.nb_api.delete_lswitch(utils.ovn_name(network_id))