Beispiel #1
0
 def _process_new_physical_switches(self, context, new_physical_switches):
     for physical_switch in new_physical_switches:
         ps_dict = physical_switch
         ps_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         if (ps_dict.get('tunnel_ip'))[0] == 'set':
             ps_dict['tunnel_ip'] = None
         p_switch = db.get_physical_switch(context, ps_dict)
         if not p_switch:
             db.add_physical_switch(context, ps_dict)
Beispiel #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)
Beispiel #3
0
 def _process_new_physical_switches(self,
                                    context,
                                    new_physical_switches):
     for physical_switch in new_physical_switches:
         ps_dict = physical_switch
         ps_dict[n_const.OVSDB_IDENTIFIER] = self.ovsdb_identifier
         if (ps_dict.get('tunnel_ip'))[0] == 'set':
             ps_dict['tunnel_ip'] = None
         p_switch = db.get_physical_switch(context, ps_dict)
         if not p_switch:
             db.add_physical_switch(context, ps_dict)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
 def test_get_physical_switch(self):
     record_dict = self._get_physical_switch_dict()
     with self.ctx.session.begin(subtransactions=True):
         entry = self._create_physical_switch(record_dict)
     result = lib.get_physical_switch(self.ctx, record_dict)
     self.assertEqual(entry, result)