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 read_config(): q = 'MATCH (target:config {name: "config"}) RETURN target LIMIT 2' db.log_query('CONFIG read', q, None) with graph.begin() as tx: cursor = tx.run(q) try: config_node = db.fetch_one(cursor)['target'] for feature, name in features_status_app_to_transport_map.items(): features_status[feature] = config_node[name] except exc.DBEmptyResponse: logger.info( 'There is no persistent config in DB, fallback to' ' builtin defaults')
def test_update(self): self.assertTrue(make_feature_toggle_request({ messageclasses.features_status_app_to_transport_map[ messageclasses.FEATURE_REROUTE_ON_ISL_DISCOVERY]: False})) with share.env.neo4j_connect.begin() as tx: cursor = tx.run( 'MATCH (c:config {name: "config"}) RETURN c LIMIT 2') db_config = db.fetch_one(cursor)['c'] self.assertEqual( False, db_config[ messageclasses.features_status_app_to_transport_map[ messageclasses.FEATURE_REROUTE_ON_ISL_DISCOVERY]])
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