コード例 #1
0
def verify_ports_vip(vips):
    for idx, vip in enumerate(vips['vips']):
        pts = list()
        for port in vip['ports']:
            if port['port']:
                pts.append(resolve(port, '#/port'))

        if len(pts) != len(list(set(pts))):
            raise ValidationError('Vip has same ports',
                                  ['#vips/%s/ports/*/port ' % (idx)])
コード例 #2
0
 def fail(self, reason, obj, pointer=None):
     """
     Called when validation fails.
     """
     pointer = pointer_join(pointer)
     err = ValidationError(reason, obj, pointer)
     if self.fail_fast:
         raise err
     else:
         self.errors.append(err)
     return err
コード例 #3
0
ファイル: draft04.py プロジェクト: djta/5GCORE-1
    def validate(self, obj, pointer=None):
        """
        Validate object against validator

        :param obj: the object to validate
        """

        pointer = pointer or '#'

        validator = deepcopy(self)
        validator.errors = []
        validator.fail_fast = False

        obj = deepcopy(obj)
        obj = validator.validate_enum(obj, pointer)
        obj = validator.validate_type(obj, pointer)
        obj = validator.validate_not(obj, pointer)
        obj = validator.validate_all_of(obj, pointer)
        obj = validator.validate_any_of(obj, pointer)
        obj = validator.validate_one_of(obj, pointer)

        if self.is_array(obj):
            obj = validator.validate_items(obj, pointer)
            obj = validator.validate_max_items(obj, pointer)
            obj = validator.validate_min_items(obj, pointer)
            obj = validator.validate_unique_items(obj, pointer)
        elif self.is_number(obj):
            obj = validator.validate_maximum(obj, pointer)
            obj = validator.validate_minimum(obj, pointer)
            obj = validator.validate_multiple_of(obj, pointer)
        elif self.is_object(obj):
            obj = validator.validate_required(obj, pointer)
            obj = validator.validate_max_properties(obj, pointer)
            obj = validator.validate_min_properties(obj, pointer)
            obj = validator.validate_dependencies(obj, pointer)
            obj = validator.validate_properties(obj, pointer)
            obj = validator.validate_default_properties(obj, pointer)
        elif self.is_string(obj):
            obj = validator.validate_max_length(obj, pointer)
            obj = validator.validate_min_length(obj, pointer)
            obj = validator.validate_pattern(obj, pointer)
            obj = validator.validate_format(obj, pointer)

        if validator.errors:
            raise ValidationError('multiple errors',
                                  obj,
                                  errors=validator.errors)

        return obj
コード例 #4
0
def verify_ports(pools):
    for idx, pool in enumerate(pools['server_pools']):
        ips = list()
        v6 = list()
        for member in pool['server_pool_members']:
            if member['ip']:
                ips.append((resolve(member,
                                    '#/ip/id'), resolve(member,
                                                        '#/port_real')))
            if member['ipv6']:
                v6.append(
                    (resolve(member,
                             '#/ipv6/id'), resolve(member, '#/port_real')))

        if len(ips) != len(list(set(ips))):
            raise ValidationError('Ips have same ports', [
                '#server_pools/%s/server_pool_members/*/ip/id - #server_pools/%s/server_pool_members/*/port_real'
                % (idx, idx)
            ])
        if len(v6) != len(list(set(v6))):
            raise ValidationError('Ipv6 have same ports', [
                '#server_pools/%s/server_pool_members/*/ipv6/id - #server_pools/%s/server_pool_members/*/port_real'
                % (idx, idx)
            ])