Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 def __init__(self, cursor, q, p):
     self.cursor = cursor
     self.exc_empty = exc.DBRecordNotFound(q, p)