Exemplo n.º 1
0
 def _process_deleted_physical_ports(self,
                                     context,
                                     deleted_physical_ports):
     for physical_port in deleted_physical_ports:
         pp_dict = physical_port
         pp_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         port_name = pp_dict['name']
         p_port = db.get_physical_port(context, pp_dict)
         if not p_port:
             raise l2gw_exc.L2GatewayInterfaceNotFound(
                 interface_id=port_name)
         p_switch_id = p_port.get('physical_switch_id')
         switch_dict = {}
         switch_dict['uuid'] = p_switch_id
         switch_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         switch_db = db.get_physical_switch(context, switch_dict)
         if not switch_db:
             raise l2gw_exc.L2GatewayDeviceNotFound(
                 device_id=p_switch_id)
         switch_name = switch_db.get('name')
         l2gw_id_list = self.l2gw_mixin._get_l2gw_ids_by_interface_switch(
             context, port_name, switch_name)
         if l2gw_id_list:
             for l2gw_id in l2gw_id_list:
                 self.l2gw_mixin._delete_connection_by_l2gw_id(context,
                                                               l2gw_id)
         vlan_bindings = db.get_all_vlan_bindings_by_physical_port(
             context, pp_dict)
         ls_set = set()
         for vlan_binding in vlan_bindings:
             vlan_binding['logical_switch_id'] = vlan_binding.get(
                 'logical_switch_uuid')
             if vlan_binding.get('logical_switch_uuid') in ls_set:
                 db.delete_vlan_binding(context, vlan_binding)
                 continue
             bindings = db.get_all_vlan_bindings_by_logical_switch(
                 context, vlan_binding)
             if bindings and len(bindings) == 1:
                 self._delete_macs_from_ovsdb(
                     context,
                     vlan_binding.get('logical_switch_uuid'),
                     self.ovsdb_identifier)
             elif bindings and len(bindings) > 1:
                 flag = True
                 for binding in bindings:
                     if binding[
                        'ovsdb_identifier'] == self.ovsdb_identifier:
                         flag = False
                         break
                 if flag:
                     self._delete_macs_from_ovsdb(
                         context,
                         vlan_binding.get('logical_switch_uuid'),
                         self.ovsdb_identifier)
             ls_set.add(vlan_binding.get('logical_switch_uuid'))
             db.delete_vlan_binding(context, vlan_binding)
         db.delete_physical_port(context, pp_dict)
Exemplo n.º 2
0
 def _get_physical_switch_ips(self, context, mac):
     physical_switch_ips = set()
     record_dict = {n_const.OVSDB_IDENTIFIER: self.ovsdb_identifier}
     vlan_bindings = db.get_all_vlan_bindings_by_logical_switch(
         context, mac)
     for vlan_binding in vlan_bindings:
         record_dict['uuid'] = vlan_binding.get('port_uuid')
         physical_port = db.get_physical_port(context, record_dict)
         record_dict['uuid'] = physical_port.get('physical_switch_id')
         physical_switch = db.get_physical_switch(context, record_dict)
         physical_switch_ips.add(physical_switch.get('tunnel_ip'))
     return list(physical_switch_ips)
Exemplo n.º 3
0
 def _get_physical_switch_ips(self, context, mac):
     physical_switch_ips = set()
     record_dict = {n_const.OVSDB_IDENTIFIER: self.ovsdb_identifier}
     vlan_bindings = db.get_all_vlan_bindings_by_logical_switch(
         context, mac)
     for vlan_binding in vlan_bindings:
         record_dict['uuid'] = vlan_binding.get('port_uuid')
         physical_port = db.get_physical_port(context, record_dict)
         record_dict['uuid'] = physical_port.get('physical_switch_id')
         physical_switch = db.get_physical_switch(context, record_dict)
         physical_switch_ips.add(physical_switch.get('tunnel_ip'))
     return list(physical_switch_ips)
Exemplo n.º 4
0
 def _process_deleted_physical_ports(self, context, deleted_physical_ports):
     for physical_port in deleted_physical_ports:
         pp_dict = physical_port
         pp_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         port_name = pp_dict['name']
         p_port = db.get_physical_port(context, pp_dict)
         if not p_port:
             raise l2gw_exc.L2GatewayInterfaceNotFound(
                 interface_id=port_name)
         p_switch_id = p_port.get('physical_switch_id')
         switch_dict = {}
         switch_dict['uuid'] = p_switch_id
         switch_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         switch_db = db.get_physical_switch(context, switch_dict)
         if not switch_db:
             raise l2gw_exc.L2GatewayDeviceNotFound(device_id=p_switch_id)
         switch_name = switch_db.get('name')
         l2gw_id_list = self.l2gw_mixin._get_l2gw_ids_by_interface_switch(
             context, port_name, switch_name)
         if l2gw_id_list:
             for l2gw_id in l2gw_id_list:
                 self.l2gw_mixin._delete_connection_by_l2gw_id(
                     context, l2gw_id)
         vlan_bindings = db.get_all_vlan_bindings_by_physical_port(
             context, pp_dict)
         ls_set = set()
         for vlan_binding in vlan_bindings:
             vlan_binding['logical_switch_id'] = vlan_binding.get(
                 'logical_switch_uuid')
             if vlan_binding.get('logical_switch_uuid') in ls_set:
                 db.delete_vlan_binding(context, vlan_binding)
                 continue
             bindings = db.get_all_vlan_bindings_by_logical_switch(
                 context, vlan_binding)
             if bindings and len(bindings) == 1:
                 self._delete_macs_from_ovsdb(
                     context, vlan_binding.get('logical_switch_uuid'),
                     self.ovsdb_identifier)
             elif bindings and len(bindings) > 1:
                 flag = True
                 for binding in bindings:
                     if binding[
                             'ovsdb_identifier'] == self.ovsdb_identifier:
                         flag = False
                         break
                 if flag:
                     self._delete_macs_from_ovsdb(
                         context, vlan_binding.get('logical_switch_uuid'),
                         self.ovsdb_identifier)
             ls_set.add(vlan_binding.get('logical_switch_uuid'))
             db.delete_vlan_binding(context, vlan_binding)
         db.delete_physical_port(context, pp_dict)
Exemplo n.º 5
0
    def delete_port_mac(self, context, port):
        """Process the deleted port and trigger the RPC

        to delete from the gateway.

        When the ML2 plugin invokes this call, the argument port is
        a single port dict, whereas the L2gateway service plugin
        sends it as a list of port dicts.
        """
        ls_dict = {}
        mac_list = []
        logical_switches = []
        ovsdb_identifier = None
        if isinstance(port, list):
            from_l2gw_plugin = True
            network_id = port[0].get('network_id')
            ovsdb_identifier = port[0].get('ovsdb_identifier')
            lg_dict = {'logical_switch_name': network_id,
                       'ovsdb_identifier': ovsdb_identifier}
            logical_switch = db.get_logical_switch_by_name(
                context, lg_dict)
            logical_switches.append(logical_switch)
            port_list = port
        else:
            from_l2gw_plugin = False
            network_id = port.get('network_id')
            logical_switches = (
                db.get_all_logical_switches_by_name(
                    context, network_id))
            l2gateway_connections = self.get_l2_gateway_connections(
                context, filters={'network_id': [network_id]})
            if not l2gateway_connections:
                return
            port_list = [port]
        for port_dict in port_list:
            if port_dict['device_owner']:
                if logical_switches:
                    for logical_switch in logical_switches:
                        logical_switch_uuid = logical_switch.get('uuid')
                        mac = port_dict.get("mac_address")
                        if port_dict.get('ovsdb_identifier', None):
                            ovsdb_identifier = port_dict.get(
                                'ovsdb_identifier')
                        else:
                            ovsdb_identifier = logical_switch.get(
                                'ovsdb_identifier')
                        record_dict = {'mac': mac,
                                       'logical_switch_uuid':
                                       logical_switch_uuid,
                                       'ovsdb_identifier': ovsdb_identifier}
                        rec_dict = {'logical_switch_id': logical_switch_uuid,
                                    'ovsdb_identifier': ovsdb_identifier}
                        if len(db.get_all_vlan_bindings_by_logical_switch(
                               context, rec_dict)) > 1:
                            if from_l2gw_plugin:
                                ls = logical_switch.get('name')
                                l2gateway_connections = (
                                    self.get_l2_gateway_connections(
                                        context, filters={'network_id': [ls]}))
                                if len(l2gateway_connections) > 1:
                                    continue
                        ucast_mac_remote = (
                            db.get_ucast_mac_remote_by_mac_and_ls(
                                context, record_dict))
                        del_count = 0
                        if not ucast_mac_remote:
                            LOG.debug("delete_port_mac: MAC %s does"
                                      " not exist", mac)
                            # It is possible that this MAC is present
                            # in the pending_ucast_mac_remote table.
                            # Delete this MAC as it was not inserted
                            # into the OVSDB server earlier.
                            del_count = db.delete_pending_ucast_mac_remote(
                                context, 'insert',
                                ovsdb_identifier,
                                logical_switch_uuid,
                                mac)
                        if not del_count:
                            mac_list = ls_dict.get(logical_switch_uuid, [])
                            mac_list.append(mac)
                            ls_dict[logical_switch_uuid] = mac_list
                else:
                    LOG.debug("delete_port_mac:Logical Switch %s "
                              "does not exist ", port_dict.get('network_id'))
                    return
        for logical_switch_uuid, mac_list in ls_dict.items():
            try:
                if mac_list:
                    self.agent_rpc.delete_vif_from_gateway(context,
                                                           ovsdb_identifier,
                                                           logical_switch_uuid,
                                                           mac_list)
            except messaging.MessagingTimeout:
                # If RPC is timed out, then the RabbitMQ
                # will retry the operation.
                LOG.exception(_LE("Communication error with "
                                  "the L2 gateway agent"))
            except Exception as ex:
                # The remote OVSDB server may be down.
                # We need to retry this operation later.
                LOG.debug("Exception occurred %s", str(ex))
                db.add_pending_ucast_mac_remote(
                    context, 'delete', ovsdb_identifier,
                    logical_switch_uuid,
                    None,
                    mac_list)