Пример #1
0
 def constraint(obj, attr, value):
     try:
         return generate_password_hash(value)
     except Exception:
         raise ValueError(
             _("a password is required in field %(attr)s.") %
             {'attr': attr})
Пример #2
0
class ObjectNotFound(NotFound):
    """A not found exception indicating an identifiable object isn't found.
    A specialization of the NotFound exception indicating an object with a said
    ID doesn't exist.
    :param id: The ID of the (not found) object.
    """
    message = _("%(objtype)s object %(id)s not found.")
Пример #3
0
 def constraint(obj, attr, value):
     try:
         if not value:
             return uuid.uuid4().hex
         return uuid.UUID(str(value)).hex
     except Exception:
         raise ValueError(
             _("a UUID is required in field %(attr)s.") % {'attr': attr})
Пример #4
0
 def constraint(obj, attr, value):
     result = IPAddress.constraint(obj, attr, value)
     if result.version != 4:
         raise ValueError(
             _("%(val)s is not valid for the field %(attr)s") % {
                 'val': value,
                 'attr': attr
             })
     return result
Пример #5
0
 def constraint(obj, attr, value):
     try:
         return netaddr.IPAddress(value).__str__()
     except netaddr.AddrFormatError:
         raise ValueError(
             _("%(val)s is not valid IP Address for the field %(attr)s") % {
                 'val': value,
                 'attr': attr
             })
Пример #6
0
 def _null(self, obj, attr):
     """process field value is None
     """
     if self.nullable:
         return None
     else:
         raise ValueError(
             _("field '%(attr)s' of object '%(obj)s' cannot be None.") % {
                 'attr': attr,
                 'obj': obj
             })
Пример #7
0
    def constraint(obj, attr, value):
        """make sure the field value is string or converted to string
        """
        accepted_types = (str, int)

        if isinstance(value, accepted_types):
            return str(value)
        else:
            raise ValueError(
                _("a string is required in field %(attr)s, not a %(type)s.") %
                {
                    'attr': attr,
                    'type': type(value).__name__
                })
Пример #8
0
    "reopt_mode": "loose",
    "flow_factor": 1.0,
    "real_traffic": False,
    "traffic_ratio": 1.0,
    "congest_threshold": 0.8,
    "target_threshold": 0.7,
    "prioriry_prefer": "HIGH",
    "traffic_prefer": "HIGH",
    "priority_weight": 0.5,
    "bandwidth_weight": 0.5
}

################################################
# General Constants
################################################
DEFAULT_USER_ERR_MES = _('Invalid input arguments.')


################################################
# Unused Constants Below
################################################

ACTION_DICT_1 = {
    'creator': {"bgp": 0, "netconf": 1},
    'create_backup': {False: 0, True: 1},
    'tlv_encoding': {"old": 0, "new": 1},
    'origin': {"IGP": 0, "BGP": 1, "INCOMPLETE": 2},
    'valid_check': {False: 0, True: 1},
    'target_type': {"PE": 0, "RR": 1},
    'generator': {"manual": 0, "topo": 1, "auto": 2, "local": 3},
    'append_type': {"ANY": 0, "EPE": 1},
Пример #9
0
class SqlExecuteError(BaseException):
    """Database operation error."""
    message = _("database general function execution error, %(info)s.")
Пример #10
0
class ObjectFieldInvalid(BaseException):
    """the field value of object is invalid
    """
    message = _("Field %(field)s of %(objname)s is not an instance of Field")
Пример #11
0
class StatusError(BaseException):
    """Target object status error."""
    message = _("%(obj_type)s object of %(status)s status can't do the %(action)s operation.")
Пример #12
0
class NoAccessAuthority(BaseException):
    """No authority to do some operation"""
    message = _("current user no access to do %(obj_type)s %(oper_type)s operation.")
Пример #13
0
class ServiceUnavailable(BaseException):
    """A generic service unavailable exception."""
    message = _("The service is unavailable.")
Пример #14
0
class NotAuthorized(BaseException):
    """A generic not authorized exception."""
    message = _("Not authorized.")
Пример #15
0
class ObjectFieldUpdateError(BaseException):
    """the field value of object do not allow to update
    """
    message = _("Field %(field)s of %(objname)s no update allowed")
Пример #16
0
class AssociationError(BaseException):
    """operation failed for association exitsting."""
    message = _("operation error because target %(obj)s object still has associations with %(ass_obj)s.")
Пример #17
0
class BadRequest(BaseException):
    """An exception indicating a generic bad request for a said resource.
    A generic exception indicating a bad request for a specified resource.
    """
    message = _('Bad %(resource)s request: %(msg)s.')