Ejemplo 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def _process_modified_physical_ports(self, context,
                                      modified_physical_ports):
     for physical_port in modified_physical_ports:
         pp_dict = physical_port
         pp_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         modified_port = db.get_physical_port(context, pp_dict)
         if modified_port:
             db.update_physical_ports_status(context, pp_dict)
             port_vlan_bindings = physical_port.get('vlan_bindings')
             vlan_bindings = db.get_all_vlan_bindings_by_physical_port(
                 context, pp_dict)
             for vlan_binding in vlan_bindings:
                 db.delete_vlan_binding(context, vlan_binding)
             for port_vlan_binding in port_vlan_bindings:
                 port_vlan_binding['port_uuid'] = pp_dict['uuid']
                 port_vlan_binding[
                     n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
                 db.add_vlan_binding(context, port_vlan_binding)
         else:
             db.add_physical_port(context, pp_dict)
Ejemplo n.º 4
0
 def _process_modified_physical_ports(self,
                                      context,
                                      modified_physical_ports):
     for physical_port in modified_physical_ports:
         pp_dict = physical_port
         pp_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         modified_port = db.get_physical_port(context, pp_dict)
         if modified_port:
             db.update_physical_ports_status(context, pp_dict)
             port_vlan_bindings = physical_port.get('vlan_bindings')
             vlan_bindings = db.get_all_vlan_bindings_by_physical_port(
                 context, pp_dict)
             for vlan_binding in vlan_bindings:
                 db.delete_vlan_binding(context, vlan_binding)
             for port_vlan_binding in port_vlan_bindings:
                 port_vlan_binding['port_uuid'] = pp_dict['uuid']
                 port_vlan_binding[
                     n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
                 db.add_vlan_binding(context, port_vlan_binding)
         else:
             db.add_physical_port(context, pp_dict)
Ejemplo n.º 5
0
 def test_delete_vlan_binding(self):
     record_dict = self._get_vlan_binding_dict()
     self._create_vlan_binding(record_dict)
     lib.delete_vlan_binding(self.ctx, record_dict)
     count = self.ctx.session.query(models.VlanBindings).count()
     self.assertEqual(count, 0)