Пример #1
0
    def _check_port_fault_status_and_switch_fault_status(self, context,
                                                         l2_gateway_id):
        l2gw = self.get_l2_gateway(context, l2_gateway_id)
        if not l2gw:
            raise l2gw_exc.L2GatewayNotFound(gateway_id=l2_gateway_id)
        devices = l2gw['devices']
        rec_dict = {}
        for device in devices:
            device_name = device['device_name']
            dev_db = db.get_physical_switch_by_name(context, device_name)
            if not dev_db:
                raise l2gw_exc.L2GatewayDeviceNotFound(device_id=device_name)
            rec_dict['physical_switch_id'] = dev_db['uuid']
            rec_dict['ovsdb_identifier'] = dev_db['ovsdb_identifier']
            status = dev_db.get('switch_fault_status')
            if status and status != constants.SWITCH_FAULT_STATUS_UP:
                raise l2gw_exc.L2GatewayPhysicalSwitchFaultStatus(
                    device_name=device_name, fault_status=status)
            for interface_list in device['interfaces']:
                int_name = interface_list.get('name')
                rec_dict['interface_name'] = int_name
                port_db = db.get_physical_port_by_name_and_ps(context,
                                                              rec_dict)
                if not port_db:
                    raise l2gw_exc.L2GatewayInterfaceNotFound(
                        interface_id=int_name)

                port_status = port_db['port_fault_status']
                if (port_status and port_status !=
                        constants.PORT_FAULT_STATUS_UP):
                    raise l2gw_exc.L2GatewayPhysicalPortFaultStatus(
                        int_name=int_name, device_name=device_name,
                        fault_status=port_status)
Пример #2
0
 def update_l2_gateway(self, context, id, l2_gateway):
     """Update l2 gateway."""
     self._admin_check(context, 'UPDATE')
     gw = l2_gateway[self.gateway_resource]
     if 'devices' in gw:
         devices = gw['devices']
     with context.session.begin(subtransactions=True):
         l2gw_db = self._get_l2_gateway(context, id)
         if l2gw_db.network_connections:
             raise l2gw_exc.L2GatewayInUse(gateway_id=id)
         dev_db = self._get_l2_gateway_devices(context, id)
         if not gw.get('devices'):
             l2gw_db.name = gw.get('name')
             return self._make_l2_gateway_dict(l2gw_db)
         for device in devices:
             dev_name = device['device_name']
             dev_db = self._get_l2gw_devices_by_name_andl2gwid(
                 context, dev_name, id)
             if not dev_db:
                 raise l2gw_exc.L2GatewayDeviceNotFound(device_id="")
             interface_db = self._get_l2_gw_interfaces(
                 context, dev_db[0].id)
             self._delete_l2_gateway_interfaces(context, interface_db)
             interface_dict_list = []
             self.validate_device_name(context, dev_name, id)
             for interfaces in device['interfaces']:
                 interface_dict_list.append(interfaces)
             self._update_interfaces_db(context, interface_dict_list,
                                        dev_db)
     if gw.get('name'):
         l2gw_db.name = gw.get('name')
     return self._make_l2_gateway_dict(l2gw_db)
Пример #3
0
    def _validate_gateway_for_update(self, context, gw):
        LOG.debug("L2gwRpcDriver._validate_gateway_for_update gw=%s", gw)
        devices = gw.get('l2_gateway').get('devices')

        for device in devices:
            interfaces = device.get('interfaces')
            device_name = device.get("device_name")
            for interface in interfaces:
                interface_name = interface.get('name')
                physical_switch = db.get_physical_switch_by_name(
                    context, device.get('device_name'))
                if not physical_switch:
                    raise l2gw_exc.L2GatewayDeviceNotFound(
                        device_id=device_name)
                ovsdb_identifier = physical_switch.get('ovsdb_identifier')
                pp_dict = {
                    'interface_name': interface_name,
                    'ovsdb_identifier': ovsdb_identifier,
                    'physical_switch_id': physical_switch.get('uuid')
                }

                ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict)
                if not ps_port:
                    raise l2gw_exc.L2GatewayPhysicalPortNotFound(
                        int_name=interface_name, device_name=device_name)
Пример #4
0
 def _get_l2_gateway_device_by_name_id(self, context, device_name, l2gw_id):
     """Get the l2 gateway device by name and id."""
     try:
         gw = context.session.query(models.L2GatewayDevice).filter_by(
             device_name=device_name, l2_gateway_id=l2gw_id).all()
     except sa_orm_exc.NoResultFound:
         raise l2gw_exc.L2GatewayDeviceNotFound(device_id=device_name)
     return gw
Пример #5
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)
Пример #6
0
 def validate_l2_gateway_for_update(self, context, id, l2_gateway):
     self._admin_check(context, 'UPDATE')
     gw = l2_gateway[self.gateway_resource]
     devices = None
     dev_db = None
     if 'devices' in gw:
         devices = gw['devices']
     if not devices:
         return
     with context.session.begin(subtransactions=True):
         # Attemp to retrieve l2gw
         gw_db = self._get_l2_gateway(context, id)
         if devices:
             for device in devices:
                 dev_name = device['device_name']
                 dev_db = self._get_l2gw_devices_by_name_andl2gwid(
                     context, dev_name, id)
                 if not dev_db:
                     raise l2gw_exc.L2GatewayDeviceNotFound(
                         device_id=dev_name)
                 self.validate_device_name(context, dev_name, id)
                 interface_list = device['interfaces']
                 if not interface_list:
                     raise l2gw_exc.L2GatewayInterfaceRequired()
                 if constants.SEG_ID in interface_list[0]:
                     for interfaces in interface_list:
                         if constants.SEG_ID not in interfaces:
                             raise l2gw_exc.L2GatewaySegmentationRequired()
                 if constants.SEG_ID not in interface_list[0]:
                     for interfaces in interface_list[1:]:
                         if constants.SEG_ID in interfaces:
                             raise l2gw_exc.L2GatewaySegmentationRequired()
                 if gw_db.devices:
                     if gw_db.devices[0].interfaces[0]['segmentation_id']:
                         if constants.SEG_ID not in interface_list[0]:
                             raise l2gw_exc.L2GatewaySegmentationIDExists()
                     else:
                         if constants.SEG_ID in interface_list[0]:
                             raise l2gw_exc.\
                                 L2GatewaySegmentationIDNotExists()