예제 #1
0
def sr_plugin_init_cb(session):
    ctx = {}
    ctx["yang_model"] = yang_model
    ctx["sess"] = session
    ctx["sub"] = sr.Subscribe(session)
    ctx["config_file"] = "network"
    ctx["uci_sections"] = ["interface"]
    ctx["map"] = table_sr_uci

    rc = load_startup_datastore(ctx)
    if sr.SR_ERR_OK != rc:
        return sr.SR_ERR_INTERNAL

    rc = sync_datastores(ctx)
    if sr.SR_ERR_OK != rc:
        return sr.SR_ERR_INTERNAL

    # subscribe for changes in running config */
    ctx["sub"].module_change_subscribe(ctx["yang_model"], module_change_cb, ctx)

    print "\n\n ========== READING STARTUP CONFIG: ==========\n"
    try:
        print_current_config(session, yang_model);
    except Exception as e:
        print e

    print "\n\n ========== STARTUP CONFIG APPLIED AS RUNNING ==========\n"

    sr.global_loop()

    return rc
예제 #2
0
    if len(sys.argv) > 1:
        module_name = sys.argv[1]
    else:
        print "\nYou can pass the module name to be subscribed as the first argument"

    # connect to sysrepo
    conn = sr.Connection("example_application")

    # start session
    sess = sr.Session(conn)

    # subscribe for changes in running config */
    subscribe = sr.Subscribe(sess)

    subscribe.module_change_subscribe(module_name, module_change_cb, None, 0, sr.SR_SUBSCR_DEFAULT | sr.SR_SUBSCR_APPLY_ONLY)

    print "\n\n ========== READING STARTUP CONFIG: ==========\n"
    try:
        print_current_config(sess, module_name)
    except Exception as e:
        print e

    print "\n\n ========== STARTUP CONFIG APPLIED AS RUNNING ==========\n"

    sr.global_loop()

    print "Application exit requested, exiting.\n";

except Exception as e:
    print e
예제 #3
0
        module_name = sys.argv[1]

        six.print_("Application will watch for changes in " + module_name +
                   "\n")

        # connect to sysrepo
        conn = sr.Connection("example_application")

        # start session
        sess = sr.Session(conn)

        # subscribe for changes in running config
        subscribe = sr.Subscribe(sess)
        subscribe.module_change_subscribe(
            module_name, module_change_cb, None, 0,
            sr.SR_SUBSCR_DEFAULT | sr.SR_SUBSCR_APPLY_ONLY)
        try:
            print_current_config(sess, module_name)

        except Exception as e:
            six.print_(e)

        six.print_(
            "\n\n ========== STARTUP CONFIG APPLIED AS RUNNING ==========\n")

        sr.global_loop()

        six.print_("Application exit requested, exiting.\n")

except Exception as e:
    six.print_(e)