コード例 #1
0
def convert_integer(raw, limit=sys.maxint):
    if not isinstance(raw, (int, long)):
        try:
            value = int(raw, 0)
        except ValueError:
            raise exc.UnacceptableDataError(
                raw, 'not numeric value: {}'.format(raw))
    else:
        value = raw

    if limit is not None and value > limit:
        raise exc.UnacceptableDataError(raw,
                                        'integer value too big {}'.format(raw))
    return value
コード例 #2
0
 def _verify_fields(self):
     super(AbstractLink, self)._verify_fields()
     if not self.source or not self.dest:
         raise exc.UnacceptableDataError(
             self, ('can\'t instantiate {} without defining both '
                    'source=={!r} and dest=={!r} fields').format(
                        type(self).__name__, self.source, self.dest))
コード例 #3
0
def drop_by_mask(tx, mask):
    logger.info('Delete link props by mask %s', mask)

    p = _make_match_by_mask(mask)
    if not p:
        raise exc.UnacceptableDataError(
            mask, 'reject to drop all link props in DB')

    where = ['target.{0}=${0}'.format(x) for x in p]
    q = 'MATCH (target:link_props)\n'
    if where:
        q += 'WHERE ' + '\n  AND '.join(where)
    q += '\nRETURN target, id(target) as ref'
    db.log_query('pre delete link props fetch', q, p)

    refs = []
    persistent = []
    for db_record in tx.run(q, p):
        persistent.append(model.LinkProps.new_from_db(db_record['target']))
        refs.append(db_record['ref'])

    q = 'MATCH (target:link_props)\n'
    q += 'WHERE id(target) in [{}]'.format(', '.join(str(x) for x in refs))
    q += '\nDELETE target'
    db.log_query('delete link props', q, {})
    tx.run(q)

    return persistent
コード例 #4
0
def convert_integer(raw, limit=sys.maxint):
    if isinstance(raw, (int, long)):
        return raw
    value = int(raw, 0)
    if value > limit:
        raise exc.UnacceptableDataError(raw,
                                        'numeric value too big {}'.format(raw))
    return value
コード例 #5
0
def _make_match(subject):
    match = _make_endpoint_match(subject.source, 'src_')
    match.update(_make_endpoint_match(subject.dest, 'dst_'))

    masked_fields = {k for k in match if match[k] is None}
    if masked_fields:
        raise exc.UnacceptableDataError(
            subject, 'Match field(s) without value: {}'.format(
                ', '.join(repr(x) for x in sorted(masked_fields))))
    return match
コード例 #6
0
    def link_props_put(self):
        link_props = self._unpack_link_props()
        protected = link_props.extract_protected_props()
        if protected:
            raise exc.UnacceptableDataError(
                link_props, 'property(es) %s is can\'t be changed'.format(
                    ', '.join(repr(x) for x in sorted(protected))))

        with graph.begin() as tx:
            link_props_utils.create_if_missing(tx, link_props)
            link_props_utils.set_props_and_propagate_to_isl(tx, link_props)

            actual_link_props = link_props_utils.read(tx, link_props)

        payload = message_utils.make_link_props_response(
            self.payload, actual_link_props)
        message_utils.send_link_props_response(payload, self.correlation_id)