Exemplo n.º 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)
Exemplo n.º 2
0
    def validate_l2_gateway_connection_for_create(self, context,
                                                  l2_gateway_connection):
        # HACK: Override this since segmentation id validation is not
        # applicable in Midonet. After deactivating segmentation id validation
        # of l2gw_validators.validate_network_mapping_list in plugin side,
        # validate it in this method.
        super(MidonetL2GatewayMixin,
              self).validate_l2_gateway_connection_for_create(
                  context, l2_gateway_connection)

        # Validate l2 gateway existence before getting gateway device type
        gw_connection = l2_gateway_connection[self.connection_resource]
        l2gw = self.get_l2_gateway(context, gw_connection['l2_gateway_id'])
        if not l2gw:
            raise l2gw_exc.L2GatewayNotFound(
                gateway_id=gw_connection['l2_gateway_id'])
        if self._get_l2_gateway_connection_by_l2gw_id(
                context, gw_connection['l2_gateway_id']):
            raise exceptions.MidonetL2GatewayConnectionExists(
                l2_gateway_id=gw_connection['l2_gateway_id'])

        # Validate segmentation id range according to gateway device type
        gw_connection = l2_gateway_connection[
            constants.CONNECTION_RESOURCE_NAME]
        seg_id = gw_connection.get(constants.SEG_ID)
        if seg_id:
            gw_type = self.get_gateway_device_type_from_l2gw(context, l2gw)
            l2gw_midonet_validators.is_valid_segmentaion_id(gw_type, seg_id)
Exemplo n.º 3
0
 def delete_l2_gateway(self, context, id):
     """delete the l2 gateway by id."""
     self.l2gateway_db._admin_check(context, 'DELETE')
     with context.session.begin(subtransactions=True):
         gw_db = self.l2gateway_db._get_l2_gateway(context, id)
         if gw_db is None:
             raise l2gw_exc.L2GatewayNotFound(gateway_id=id)
         if gw_db.network_connections:
             raise l2gw_exc.L2GatewayInUse(gateway_id=id)
         return gw_db
Exemplo n.º 4
0
 def _get_l2_gateway(self, context, gw_id):
     try:
         gw = context.session.query(models.L2Gateway).get(gw_id)
     except sa_orm_exc.NoResultFound:
         raise l2gw_exc.L2GatewayNotFound(gateway_id=gw_id)
     return gw
Exemplo n.º 5
0
 def _get_l2_gateway(self, context, gw_id):
     gw = context.session.query(models.L2Gateway).get(gw_id)
     if not gw:
         raise l2gw_exc.L2GatewayNotFound(gateway_id=gw_id)
     return gw