예제 #1
0
class OptionPool(BaseModel):
    id = models.AutoField(primary_key=True, db_column='id_optionspool')
    type = models.CharField(max_length=50, blank=False, db_column='type')
    name = models.CharField(max_length=50,
                            blank=False,
                            db_column='description')

    log = logging.getLogger('OptionPool')

    class Meta(BaseModel.Meta):
        db_table = u'optionspool'
        managed = True

    def valid_option_pool(self, optionpool_map):
        """Validate the values ​​of option pool

        @param optionpool_map: Map with the data of the request.

        @raise InvalidValueError: Represents an error occurred validating a value.
        """

        # Get XML data
        type = optionpool_map.get('type')
        name = optionpool_map.get('name')

        # type can NOT be greater than 50
        if not is_valid_string_maxsize(type, 50,
                                       True) or not is_valid_option(type):
            self.log.error(u'Parameter type is invalid. Value: %s.', type)
            raise InvalidValueError(None, 'type', type)

        # name_txt can NOT be greater than 50
        if not is_valid_string_maxsize(name, 50,
                                       True) or not is_valid_option(name):
            self.log.error(u'Parameter name_txt is invalid. Value: %s.', name)
            raise InvalidValueError(None, 'name', name)

        # set variables
        self.type = type
        self.name = name

    @classmethod
    def get_by_pk(cls, id):
        """"Get  Option Pool by id.

        @return: Option Pool.

        @raise OptionPoolNotFoundError: Option Pool is not registered.
        @raise OptionPoolError: Failed to search for the Option Pool.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return OptionPool.objects.filter(id=id).uniqueResult()
        except ObjectDoesNotExist, e:
            raise OptionPoolNotFoundError(
                e, u'There is no option pool with pk = %s.' % id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #2
0
    def get_by_unique_key(cls, user_group, object_type):
        """"Get Object Group Permission General by user_group and object_type.

        @return: Object Group Permission General.

        @raise ObjectGroupPermissionNotFoundError: Object Group Permission
                                                   General not registered.
        @raise ObjectGroupPermissionError: Failed to search for the Object
                                           Group Permission General.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return ObjectGroupPermissionGeneral.objects.get(
                user_group=user_group, object_type=object_type)
        except ObjectDoesNotExist as e:
            cls.log.error(u'Object group permission general not found. '
                          'user_group {}, object_type {}'.format(
                              user_group, object_type))
            raise exceptions.ObjectGroupPermissionGeneralError(
                u'Object group permission general not found. '
                'user_group {}, object_type {}'.format(user_group,
                                                       object_type))
        except OperationalError as e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
        except Exception as e:
            cls.log.error(
                u'Failure to search the object group permission general.')
            raise exceptions.ObjectGroupPermissionGeneralError(
                u'Failure to search the object group permission general.')
예제 #3
0
    def get_by_pk(cls, ids=None, asn=None, equipment=None):
        """Get AsnEquipment by id.

        :return: AsnEquipment.

        :raise AsnEquipmentNotFoundError: AsnEquipment not registered.
        :raise AsnEquipmentError: Failed to search for the AsnEquipment.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            logging.info("get asn_equipment by id, asn or equipment")
            if ids:
                return AsnEquipment.objects.get(id=int(ids))
            elif asn:
                return AsnEquipment.objects.filter(asn=int(asn))
            elif equipment:
                return AsnEquipment.objects.filter(
                    equipment__id=int(equipment))

            return AsnEquipment.objects.all()

        except ObjectDoesNotExist:
            cls.log.error(u'AsnEquipment not found. pk {}'.format(id))
            raise exceptions.AsnEquipmentNotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError()
        except Exception as e:
            cls.log.error(u'Failure to search the ASNEquipment. E: %s' % e)
            raise exceptions.AsnEquipmentError(
                u'Failure to search the ASNEquipment. E: %s' % e)
예제 #4
0
파일: db.py 프로젝트: dwtcourses/erp5
 def _query(self, query, allow_reconnect=False):
     """
       Send a query to MySQL server.
       It reconnects automatically if needed and the following conditions are
       met:
        - It has not just tried to reconnect (ie, this function will not
          attempt to connect twice per call).
        - This connection is not transactional and has set not MySQL locks,
          because they are bound to the connection. This check can be
          overridden by passing allow_reconnect with True value.
     """
     try:
         self.db.query(query)
     except OperationalError, m:
         if m[0] in query_syntax_error:
           raise OperationalError(m[0], '%s: %s' % (m[1], query))
         if m[0] in lock_error:
           raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
         if m[0] in query_timeout_error:
           raise TimeoutReachedError('%s: %s: %s' % (m[0], m[1], query))
         if (allow_reconnect or not self._use_TM) and \
           m[0] in hosed_connection:
           self._forceReconnection()
           self.db.query(query)
         else:
           LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,))
           raise
예제 #5
0
    def get_by_pk(cls, id):
        """"
        Get Object Group Permission by id.

        @return: Object Group Permission.

        @raise ObjectGroupPermissionNotFoundError: Object Group Permission
                                                   not registered.
        @raise ObjectGroupPermissionError: Failed to search for the Object
                                           Group Permission.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return ObjectGroupPermission.objects.get(id=id)
        except ObjectDoesNotExist as e:
            cls.log.error(
                u'object group permission not found. pk {}'.format(id))
            raise exceptions.ObjectGroupPermissionNotFoundError(id)
        except OperationalError as e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
        except Exception as e:
            cls.log.error(u'Failure to search the object group permission.')
            raise exceptions.ObjectGroupPermissionError(
                u'Failure to search the object group permission.')
예제 #6
0
 def connection(self, isolation_level=None):
     conn = self.get()
     try:
         if isolation_level is not None:
             if conn.isolation_level == isolation_level:
                 isolation_level = None
             else:
                 conn.set_isolation_level(isolation_level)
         yield conn
     except:
         if not conn.open:
             conn = None
             self.close_all()
         else:
             conn = self._rollback(conn)
         raise
     else:
         if not conn.open:
             raise OperationalError(
                 "Cannot commit because connection was closed: %r" %
                 (conn, ))
     finally:
         if conn is not None and conn.open:
             if isolation_level is not None:
                 conn.set_isolation_level(isolation_level)
             self.put(conn)
예제 #7
0
class VipRequestPort(BaseModel):

    log = logging.getLogger('VipRequestPort')

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )

    vip_request = models.ForeignKey(
        VipRequest,
        db_column='id_vip_request',
    )

    port = models.IntegerField(
        max_length=5,
        db_column='port'
    )

    identifier = models.CharField(
        max_length=255,
        db_column='identifier',
        null=True
    )

    @cached_property
    def pools(self):
        pools = self.viprequestportpool_set.all()
        return pools

    @cached_property
    def options(self):
        options = self.viprequestportoptionvip_set.all()
        return options

    class Meta(BaseModel.Meta):
        db_table = u'vip_request_port'
        managed = True

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request Port by id.

        @return: Vip Request Port.

        @raise VipRequestPortNotFoundError: Vip Request Port not registered.
        @raise VipRequestPortError: Failed to search for the Vip Request Port.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestPort.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(u'vip request port not found. pk {}'.format(id))
            raise exceptions.VipRequestPortNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #8
0
class DHCPRelayIPv4(BaseModel):

    log = logging.getLogger('DHCPRelayIPv4')

    id = models.AutoField(
        primary_key=True,
        db_column='id_dhcprelay_ipv4'
    )
    ipv4 = models.ForeignKey(
        'ip.Ip',
        db_column='id_ip'
    )
    networkipv4 = models.ForeignKey(
        'ip.NetworkIPv4',
        db_column='id_networkipv4'
    )

    class Meta(BaseModel.Meta):
        db_table = u'dhcprelay_ipv4'
        managed = True
        unique_together = ('ipv4', 'networkipv4')

    def create(self, ipv4_id, networkipv4_id):
        ipv4_model = get_model('ip', 'Ip')
        networkipv4_model = get_model('ip', 'NetworkIPv4')

        ipv4 = ipv4_model.get_by_pk(ipv4_id)
        networkipv4 = networkipv4_model.get_by_pk(networkipv4_id)

        if len(DHCPRelayIPv4.objects.filter(ipv4=ipv4, networkipv4=networkipv4)) > 0:
            raise exceptions.DHCPRelayAlreadyExistsError(
                ipv4_id, networkipv4_id)

        self.ipv4 = ipv4
        self.networkipv4 = networkipv4

    @classmethod
    def get_by_pk(cls, id):
        """
        Get DHCPRelayIPv4 by id.

        @return: DHCPRelayIPv4

        @raise DHCPRelayNotFoundError: DHCPRelayIPv4 is not registered.
        @raise OperationalError: Lock wait timeout exceed
        """

        try:
            return DHCPRelayIPv4.objects.get(id=id)
        except ObjectDoesNotExist, e:
            raise exceptions.DHCPRelayNotFoundError('IPv4', id)
        except OperationalError, e:
            cls.log.error(
                u'Lock wait timeout exceeded searching DHCPRelayIPv4.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #9
0
class VipRequestPortPool(BaseModel):

    log = logging.getLogger('VipRequestPortPool')

    id = models.AutoField(primary_key=True, db_column='id')

    vip_request_port = models.ForeignKey(
        VipRequestPort,
        db_column='id_vip_request_port',
    )

    optionvip = models.ForeignKey(
        'requisicaovips.OptionVip',
        db_column='id_opcoesvip',
    )

    server_pool = models.ForeignKey(
        'requisicaovips.ServerPool',
        db_column='id_server_pool',
    )

    val_optionvip = models.CharField(max_length=255,
                                     db_column='val_optionvip',
                                     blank=True,
                                     null=True)

    order = models.IntegerField(null=True)

    @cached_property
    def l7_rule(self):
        return self.optionvip

    class Meta(BaseModel.Meta):
        db_table = u'vip_request_port_pool'
        managed = True

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request Port Pool by id.

        @return: Vip Request Port Pool.

        @raise VipRequestPortPoolNotFoundError: Vip Request Port Pool not registered.
        @raise VipRequestPortPoolError: Failed to search for the Vip Request Port Pool.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestPortPool.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(u'vip request port pool not found. pk {}'.format(id))
            raise exceptions.VipRequestPortPoolNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #10
0
    def _query(self, query, force_reconnect=False):
        """
          Send a query to MySQL server.
          It reconnects automaticaly if needed and the following conditions are
          met:
           - It has not just tried to reconnect (ie, this function will not
             attempt to connect twice per call).
           - This conection is not transactionnal and has set no MySQL locks,
             because they are bound to the connection. This check can be
             overridden by passing force_reconnect with True value.
        """
        try:
            self.db.query(query)
        except OperationalError as exc:
            if exc.args[0] in query_syntax_error:
                raise OperationalError(exc.args[0],
                                       '%s: %s' % (exc.args[1], query))

            if not force_reconnect and \
               (self._mysql_lock or self._transactions) or \
               exc.args[0] not in hosed_connection:
                if len(query) > 2000:
                    msg = '%s... (truncated at 2000 chars)' % query[:2000]
                else:
                    msg = query
                LOG.warning('query failed:\n%s' % msg)
                raise

            # Hm. maybe the db is hosed.  Let's restart it.
            if exc.args[0] in hosed_connection:
                msg = '%s Forcing a reconnect.' % hosed_connection[exc.args[0]]
                LOG.error(msg)
            self._forceReconnection()
            self.db.query(query)
        except ProgrammingError as exc:
            if exc.args[0] in hosed_connection:
                self._forceReconnection()
                msg = '%s Forcing a reconnect.' % hosed_connection[exc.args[0]]
                LOG.error(msg)
            else:
                if len(query) > 2000:
                    msg = '%s... (truncated at 2000 chars)' % query[:2000]
                else:
                    msg = query
                LOG.warning('query failed:\n%s' % msg)
            raise

        return self.db.store_result()
예제 #11
0
class VipRequestGroupPermission(BaseModel):

    log = logging.getLogger('VipRequestGroupPermission')

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )
    user_group = models.ForeignKey(
        'grupo.UGrupo',
        db_column='id_user_group'
    )
    vip_request = models.ForeignKey(
        VipRequest,
        db_column='id_vip_request'
    )
    read = models.BooleanField()
    write = models.BooleanField()
    change_config = models.BooleanField()
    delete = models.BooleanField()

    class Meta(BaseModel.Meta):
        db_table = u'vip_request_group_permission'
        managed = True
        unique_together = ('user_group', 'vip_request')

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request Group Permission by id.

        @return: Vip Request Group Permission.

        @raise VipRequestGroupPermissionNotFoundError: Vip Request Group Permission not registered.
        @raise VipRequestGroupPermissionError: Failed to search for the Vip Request Group Permission.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestGroupPermission.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(
                u'vip request group permission not found. pk {}'.format(id))
            raise exceptions.VipRequestGroupPermissionNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #12
0
class VirtualInterface(BaseModel):
    id = models.AutoField(primary_key=True, db_column='id')
    name = models.CharField(blank=False, max_length=45)

    vrf = models.ForeignKey('api_vrf.Vrf', db_column='id_vrf', null=True)

    log = logging.getLogger('VirtualInterface')

    class Meta(BaseModel.Meta):
        db_table = u'virtual_interface'
        managed = True

    def _get_ipv4_equipment_virtual_interface(self):

        return self.ipequipamento_set.all()

    ipv4_equipment_virtual_interface = \
        property(_get_ipv4_equipment_virtual_interface)

    def _get_ipv6_equipment_virtual_interface(self):

        return self.ipv6equipament_set.all()

    ipv6_equipment_virtual_interface = \
        property(_get_ipv6_equipment_virtual_interface)

    @classmethod
    def get_by_pk(cls, id):
        """Get Virtual Interface by id.

        :return: Virtual Interface.

        :raise VirtualInterfaceNotFoundError: Virtual Interface not registered.
        :raise VirtualInterfaceError: Failed to search for the Virtual Interface.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return VirtualInterface.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(u'Virtual Interface not found. pk {}'.format(id))
            raise exceptions.VirtualInterfaceNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #13
0
class VipRequestPortOptionVip(BaseModel):

    log = logging.getLogger('VipRequestPortOptionVip')

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )

    vip_request_port = models.ForeignKey(
        VipRequestPort,
        db_column='id_vip_request_port',
    )

    optionvip = models.ForeignKey(
        'requisicaovips.OptionVip',
        db_column='id_opcoesvip',
    )

    class Meta(BaseModel.Meta):
        db_table = u'vip_request_port_optionsvip'
        managed = True

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request Port Option Vip by id.

        @return: Vip Request Port Option Vip.

        @raise VipRequestPortOptionVipNotFoundError: Vip Request Port Option Vip not registered.
        @raise VipRequestPortOptionVipError: Failed to search for the Vip Request Port Option Vip.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestPortOptionVip.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(
                u'vip request port option vip not found. pk {}'.format(id))
            raise exceptions.VipRequestPortOptionVipNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #14
0
class VipRequestDSCP(BaseModel):

    log = logging.getLogger('VipRequestDSCP')

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )

    vip_request = models.ForeignKey(
        VipRequest,
        db_column='id_vip_request',
    )

    dscp = models.IntegerField(
        max_length=2,
        db_column='dscp')

    class Meta(BaseModel.Meta):

        db_table = u'vip_request_dscp'
        managed = True

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request DSCP by id.

        @return: Vip Request DSCP.

        @raise VipRequestDscpNotFoundError: Vip Request DSCP not registered.
        @raise VipRequestDscpError: Failed to search for the Vip Request DSCP.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestDSCP.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(u'vip request dscp not found. pk {}'.format(id))
            raise exceptions.VipRequestDSCPNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #15
0
    def get_by_pk(cls, id):
        """Get RouteMap by id.

        :return: RouteMap.

        :raise RouteMapNotFoundError: RouteMap not registered.
        :raise RouteMapError: Failed to search for the RouteMap.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return RouteMap.objects.get(id=id)
        except ObjectDoesNotExist:
            cls.log.error(u'RouteMap not found. pk {}'.format(id))
            raise exceptions.RouteMapNotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded')
            raise OperationalError()
        except Exception:
            cls.log.error(u'Failure to search the RouteMap')
            raise exceptions.RouteMapError(u'Failure to search the RouteMap')
예제 #16
0
    def get_by_asn(cls, asn):
        """Get AS by id.

        :return: AS.

        :raise AsnNotFoundError: As not registered.
        :raise AsnError: Failed to search for the As.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return Asn.objects.get(asn=asn)
        except ObjectDoesNotExist:
            cls.log.error(u'ASN not found. pk {}'.format(id))
            raise exceptions.AsnNotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError()
        except Exception:
            cls.log.error(u'Failure to search the ASN.')
            raise exceptions.AsnError(u'Failure to search the ASN.')
예제 #17
0
    def get_by_pk(cls, id_vrf):
        """Get Vrf by id.

        @return: Vrf.

        @raise VrfNotFoundError: Vrf is not registered.
        @raise VrfError: Failed to search for the Vrf.
        @raise OperationalError: Lock wait timeout exceed
        """
        try:
            return Vrf.objects.filter(id=id_vrf).uniqueResult()
        except ObjectDoesNotExist as e:
            raise VrfNotFoundError(u'Dont there is a Vrf by pk = %s.' % id_vrf)
        except OperationalError as e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                u'Lock wait timeout exceeded; try restarting transaction')
        except Exception as e:
            cls.log.error(u'Failure to search the Vrf. Error: {}'.format(e))
            raise VrfError(u'Failure to search the Vrf. Error: {}'.format(e))
예제 #18
0
    def get_by_pk(cls, id):
        """Get AsnEquipment by id.

        :return: AsnEquipment.

        :raise AsnEquipmentNotFoundError: AsnEquipment not registered.
        :raise AsnEquipmentError: Failed to search for the AsnEquipment.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return AsnEquipment.objects.get(id=id)
        except ObjectDoesNotExist:
            cls.log.error(u'AsnEquipment not found. pk {}'.format(id))
            raise exceptions.AsnEquipmentNotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError()
        except Exception:
            cls.log.error(u'Failure to search the AS.')
            raise exceptions.AsnEquipmentError(u'Failure to search the AS.')
예제 #19
0
    def get_by_pk(cls, id):
        """Get NeighborV6 by id.

        :return: NeighborV6.

        :raise NeighborV6NotFoundError: NeighborV6 not registered.
        :raise NeighborV6Error: Failed to search for the NeighborV6.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return NeighborV6.objects.get(id=id)
        except ObjectDoesNotExist:
            cls.log.error(u'NeighborV6 not found. pk {}'.format(id))
            raise exceptions.NeighborV6NotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded')
            raise OperationalError()
        except Exception:
            cls.log.error(u'Failure to search the NeighborV6')
            raise exceptions.NeighborV6Error(
                u'Failure to search the NeighborV6')
예제 #20
0
    def get_by_pk(cls, id):
        """Get EnvironmentPeerGroup by id.

        :return: EnvironmentPeerGroup.

        :raise EnvironmentPeerGroupNotFoundError: EnvironmentPeerGroup not registered.
        :raise EnvironmentPeerGroupError: Failed to search for the EnvironmentPeerGroup.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return EnvironmentPeerGroup.objects.get(id=id)
        except ObjectDoesNotExist:
            cls.log.error(u'EnvironmentPeerGroup not found. pk {}'.format(id))
            raise exceptions.EnvironmentPeerGroupNotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded')
            raise OperationalError()
        except Exception:
            cls.log.error(u'Failure to search the EnvironmentPeerGroup')
            raise exceptions.EnvironmentPeerGroupError(
                u'Failure to search the EnvironmentPeerGroup')
예제 #21
0
    def get_by_pk(cls, id):
        """Get ListConfigBGP by id.

        :return: ListConfigBGP.

        :raise ListConfigBGPNotFoundError: ListConfigBGP not registered.
        :raise ListConfigBGPError: Failed to search for the ListConfigBGP.
        :raise OperationalError: Lock wait timeout exceeded
        """
        try:
            return ListConfigBGP.objects.get(id=id)
        except ObjectDoesNotExist:
            cls.log.error(u'ListConfigBGP not found. pk {}'.format(id))
            raise exceptions.ListConfigBGPNotFoundError(id)
        except OperationalError:
            cls.log.error(u'Lock wait timeout exceeded')
            raise OperationalError()
        except Exception:
            cls.log.error(u'Failure to search the ListConfigBGP')
            raise exceptions.ListConfigBGPError(
                u'Failure to search the ListConfigBGP')
예제 #22
0
class ObjectGroupPermission(BaseModel):
    id = models.AutoField(primary_key=True, db_column='id')
    user_group = models.ForeignKey(
        'grupo.UGrupo',
        db_column='id_user_group'
    )
    object_type = models.ForeignKey(ObjectType, db_column='id_object_type')
    object_value = models.IntegerField(db_column='id_object')
    read = models.BooleanField()
    write = models.BooleanField()
    change_config = models.BooleanField()
    delete = models.BooleanField()

    class Meta(BaseModel.Meta):
        db_table = u'object_group_permission'
        managed = True
        unique_together = ('user_group', 'object_type', 'object_value')

    @classmethod
    def get_by_pk(cls, id):
        """"Get Object Group Permission by id.

        @return: Object Group Permission.

        @raise ObjectGroupPermissionNotFoundError: Object Group Permission
                                                   not registered.
        @raise ObjectGroupPermissionError: Failed to search for the Object
                                           Group Permission.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return ObjectGroupPermission.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(
                u'object group permission not found. pk {}'.format(id))
            raise exceptions.ObjectGroupPermissionNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #23
0
    def get_by_object(cls, object_value, object_type):
        """"Get Object Group Permission General by object_value and object_type.

        @return: Object Group Permission General.

        @raise ObjectGroupPermissionNotFoundError: Object Group Permission
                                                   General not registered.
        @raise ObjectGroupPermissionError: Failed to search for the Object
                                           Group Permission General.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return ObjectGroupPermission.objects.filter(
                object_value=object_value, object_type__name=object_type)
        except OperationalError as e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
        except Exception as e:
            cls.log.error(u'Failure to search the object group permission.')
            raise exceptions.ObjectGroupPermissionError(
                u'Failure to search the object group permission.')
예제 #24
0
    def get_by_name(cls, name):
        """"
        Get Object Type by name.

        @return: Object Type.

        @raise ObjectTypeNotFoundError: Object Type not registered.
        @raise ObjectTypeError: Failed to search for the Object Type.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return ObjectType.objects.get(name=name)
        except ObjectDoesNotExist as e:
            cls.log.error(u'object type not found. pk {}'.format(name))
            raise exceptions.ObjectTypeNotFoundError(name)
        except OperationalError as e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
        except Exception as e:
            cls.log.error(u'Failure to search the object type.')
            raise exceptions.ObjectTypeError(
                u'Failure to search the object type.')
예제 #25
0
class OptionPoolEnvironment(BaseModel):

    id = models.AutoField(primary_key=True,
                          db_column='id_optionspool_environment_xref')
    option = models.ForeignKey(OptionPool, db_column='id_optionspool')
    environment = models.ForeignKey(Ambiente, db_column='id_environment')

    log = logging.getLogger('OptionPoolEnvironment')

    class Meta(BaseModel.Meta):
        db_table = u'optionspool_environment_xref'
        managed = True
        unique_together = ('option', 'environment')

    def get_by_option_environment(self, option_id, environment_id):
        """Get OptionVipEnvironmentPool by OptionPool and EnvironmentVip.

        @return: OptionPoolEnvironment.

        @raise OptionVipEnvironmentVipNotFoundError: Ipv6Equipament is not registered.
        @raise OptionVipEnvironmentVipError: Failed to search for the OptionVipEnvironmentVip.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return OptionPoolEnvironment.objects.filter(
                option__id=option_id,
                environment__id=environment_id).uniqueResult()
        except ObjectDoesNotExist, e:
            raise OptionPoolEnvironmentNotFoundError(
                e,
                u'Dont there is a OptionPoolEnvironment by option_id = %s and environment_id = %s'
                % (option_id, environment_id))
        except OperationalError, e:
            self.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #26
0
class Vrf(BaseModel):

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )
    vrf = models.TextField(
        max_length=45,
        db_column='vrf'
    )
    internal_name = models.TextField(
        max_length=45,
        db_column='internal_name'
    )

    log = logging.getLogger('Vrf')

    @classmethod
    def get_by_pk(cls, id_vrf):
        """Get Vrf by id.

        @return: Vrf.

        @raise VrfNotFoundError: Vrf is not registered.
        @raise VrfError: Failed to search for the Vrf.
        @raise OperationalError: Lock wait timeout exceed
        """
        try:
            return Vrf.objects.filter(id=id_vrf).uniqueResult()
        except ObjectDoesNotExist, e:
            raise VrfNotFoundError(
                e, u'Dont there is a Vrf by pk = %s.' % id_vrf)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #27
0
        @raise VipRequestOptionVipNotFoundError: Vip Request Option Vip not registered.
        @raise VipRequestOptionVipError: Failed to search for the Vip Request Option Vip.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestOptionVip.objects.get(
                vip_request_id=vip_request_id, optionvip__tipo_opcao=kind)
        except ObjectDoesNotExist, e:
            cls.log.error(
                u'Vip request option vip not found. Vip {} '
                u'kind {}'.format(vip_request_id, kind))
            raise exceptions.VipRequestOptionVipNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
        except Exception, e:
            cls.log.error(u'Failure to search the option vip.')
            raise exceptions.VipRequestOptionVipError(
                e, u'Failure to search the vip request option vip.')


class VipRequestPort(BaseModel):

    log = logging.getLogger('VipRequestPort')

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )
예제 #28
0
 def execute_mock(*args, **kwargs):
     raise OperationalError("got exception")
예제 #29
0
class VipRequest(BaseModel):

    log = logging.getLogger('VipRequest')

    id = models.AutoField(
        primary_key=True,
    )

    created = models.BooleanField(
        default=False,
        db_column='created')

    ipv4 = models.ForeignKey(
        'ip.Ip',
        db_column='id_ipv4',
        blank=True,
        null=True
    )

    ipv6 = models.ForeignKey(
        'ip.Ipv6',
        db_column='id_ipv6',
        blank=True,
        null=True
    )

    environmentvip = models.ForeignKey(
        'ambiente.EnvironmentVip',
        db_column='id_environmentvip',
        blank=True,
        null=True
    )

    business = models.CharField(
        max_length=255,
        db_column='business',
        null=True)

    service = models.CharField(
        max_length=255,
        db_column='service',
        null=True)

    name = models.CharField(
        max_length=255,
        db_column='name',
        null=True)

    class Meta(BaseModel.Meta):
        db_table = u'vip_request'
        managed = True

    @cached_property
    def dscp(self):
        return self.viprequestdscp_set.get().dscp

    @cached_property
    def equipments(self):
        eqpts = list()
        if self.ipv4:
            eqpts = self.ipv4.ipequipamento_set.all().prefetch_related('equipamento')
        if self.ipv6:
            eqpts |= self.ipv6.ipv6equipament_set.all().prefetch_related('equipamento')
        eqpts = [eqpt.equipamento for eqpt in eqpts]
        return eqpts

    @cached_property
    def default_names(self):
        names = [port.identifier for port in self.viprequestport_set.all()]
        names = list(set(names))
        return names

    @cached_property
    def ports(self):
        ports = self.viprequestport_set.all()
        return ports

    @cached_property
    def options(self):
        options = self.viprequestoptionvip_set.all()
        return options

    @cached_property
    def groups_permissions(self):
        perms = self.viprequestgrouppermission_set.all()
        return perms

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request by id.

        @return: Vip Request.

        @raise VipRequestNotFoundError: Vip Request not registered.
        @raise VipRequestError: Failed to search for the Vip Request.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequest.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(u'vip request not found. pk {}'.format(id))
            raise exceptions.VipRequestNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')
예제 #30
0
class VipRequestOptionVip(BaseModel):

    log = logging.getLogger('VipRequestOptionVip')

    id = models.AutoField(
        primary_key=True,
        db_column='id'
    )

    vip_request = models.ForeignKey(
        VipRequest,
        db_column='id_vip_request',
    )

    optionvip = models.ForeignKey(
        'requisicaovips.OptionVip',
        db_column='id_opcoesvip',
    )

    @cached_property
    def traffic_return(self):
        opt = self.optionvip \
            if self.optionvip.tipo_opcao == 'Retorno de trafego' \
            else None
        return opt

    @cached_property
    def cache_group(self):
        opt = self.optionvip \
            if self.optionvip.tipo_opcao == 'cache' \
            else None
        return opt

    @cached_property
    def persistence(self):
        opt = self.optionvip \
            if self.optionvip.tipo_opcao == 'Persistencia' \
            else None
        return opt

    @cached_property
    def timeout(self):
        opt = self.optionvip \
            if self.optionvip.tipo_opcao == 'timeout' \
            else None
        return opt

    class Meta(BaseModel.Meta):
        db_table = u'vip_request_optionsvip'
        managed = True

    @classmethod
    def get_by_pk(cls, id):
        """"Get Vip Request Option Vip by id.

        @return: Vip Request Option Vip.

        @raise VipRequestOptionVipNotFoundError: Vip Request Option Vip not registered.
        @raise VipRequestOptionVipError: Failed to search for the Vip Request Option Vip.
        @raise OperationalError: Lock wait timeout exceeded.
        """
        try:
            return VipRequestOptionVip.objects.get(id=id)
        except ObjectDoesNotExist, e:
            cls.log.error(
                u'vip request option vip not found. pk {}'.format(id))
            raise exceptions.VipRequestOptionVipNotFoundError(id)
        except OperationalError, e:
            cls.log.error(u'Lock wait timeout exceeded.')
            raise OperationalError(
                e, u'Lock wait timeout exceeded; try restarting transaction')