def fetch(tx, isl): p = _make_match(isl) q = textwrap.dedent(""" MATCH (:switch {name: $src_switch}) - [target:isl { src_switch: $src_switch, src_port: $src_port, dst_switch: $dst_switch, dst_port: $dst_port }] -> (:switch {name: $dst_switch}) RETURN target""") db.log_query('ISL fetch', q, p) cursor = tx.run(q, p) try: target = db.fetch_one(cursor)['target'] except exc.DBEmptyResponse: raise exc.DBRecordNotFound(q, p) return target
def fetch(tx, isl): match = _make_match(isl) q = textwrap.dedent(""" MATCH (:switch {name: $src_switch}) - [target:isl { src_switch: $src_switch, src_port: $src_port, dst_switch: $dst_switch, dst_port: $dst_port }] -> (:switch {name: $dst_switch}) RETURN target""") logger.debug('link_props lookup query:\n%s', q) cursor = tx.run(q, match) try: target = db.fetch_one(cursor)['target'] except exc.DBEmptyResponse: raise exc.DBRecordNotFound(q, match) return target
def set_link_props(tx, isl, props): match = _make_match(isl) q = textwrap.dedent(""" MATCH (target:link_props { src_switch: $src_switch, src_port: $src_port, dst_switch: $dst_switch, dst_port: $dst_port}) RETURN target""") logger.debug('link_props lookup query:\n%s', q) cursor = tx.run(q, match) try: target = db.fetch_one(cursor)['target'] except exc.DBEmptyResponse: raise exc.DBRecordNotFound(q, match) origin, update = _locate_changes(target, props) if update: q = textwrap.dedent(""" MATCH (target:link_props) WHERE id(target)=$target_id """) + db.format_set_fields(db.escape_fields(update), field_prefix='target.') logger.debug('Push link_props properties: %r', update) tx.run(q, {'target_id': py2neo.remote(target)._id}) sync_with_link_props(tx, isl, *update.keys()) return origin
def fetch(tx, subject): p = _make_match(subject) q = textwrap.dedent(""" MATCH (target:link_props { src_switch: $src_switch, src_port: $src_port, dst_switch: $dst_switch, dst_port: $dst_port}) RETURN target""") db.log_query('link props update', q, p) cursor = tx.run(q, p) try: db_object = db.fetch_one(cursor)['target'] except exc.DBEmptyResponse: raise exc.DBRecordNotFound(q, p) return db_object
def drop(tx, subject): logger.info("Delete %s request", subject) q = textwrap.dedent(""" MATCH (target:link_props) WHERE target.src_switch=$src_switch, AND target.src_port=$src_port, AND target.dst_port=$dst_port, AND target.dst_switch=$dst_switch DELETE target RETURN target""") p = _make_match(subject) db.log_query('delete link props', q, p) cursor = tx.run(q, p) try: db_subject = db.fetch_one(cursor)['target'] except exc.DBEmptyResponse: raise exc.DBRecordNotFound(q, p) return model.LinkProps.new_from_db(db_subject)
def set_props(tx, isl, props): match = _make_match(isl) q = textwrap.dedent(""" MATCH (:switch {name: $src_switch}) - [target:isl { src_switch: $src_switch, src_port: $src_port, dst_switch: $dst_switch, dst_port: $dst_port }] -> (:switch {name: $dst_switch}) RETURN target""") logger.debug('ISL lookup query:\n%s', q) cursor = tx.run(q, match) try: target = db.fetch_one(cursor)['target'] except exc.DBEmptyResponse: raise exc.DBRecordNotFound(q, match) origin, update = _locate_changes(target, props) if update: q = textwrap.dedent(""" MATCH (:switch)-[target:isl]->(:switch) WHERE id(target)=$target_id """) + db.format_set_fields(db.escape_fields(update), field_prefix='target.') logger.debug('Push ISL properties: %r', update) tx.run(q, {'target_id': db.neo_id(target)}) return origin
def __init__(self, cursor, q, p): self.cursor = cursor self.exc_empty = exc.DBRecordNotFound(q, p)