def Main():
    # Create a client handler for connecting to server
    client = JetHandler()
    # Open session with Thrift Server
    try:
        client.OpenRequestResponseSession(device=DEFAULT_JSD_HOST, port=DEFAULT_JSD_PORT,
                                           user=USER, password=PASSWORD, ca_certs=None, client_id=DEFAULT_CLIENT_ID)
        evHandle = client.OpenNotificationSession(DEFAULT_JSD_HOST, DEFAULT_NOTIFICATION_PORT,
                                                  None, None, None, DEFAULT_MQTT_TIMEOUT, "", True)
        global topic
        topic = "SubscribedToBgpNotifications"
        stream = evHandle.CreateStreamTopic(topic)
        evHandle.Subscribe(stream, handleMessage, 2)
        print "Connected to Server and ",stream.topic
        bgp = client.GetRoutingBgpRoute()
        RouteInit(bgp)
        print "Verify on router using cli : show programmable-rpd clients"
        raw_input("<ENTER to Set route>")
        RouteSet(bgp)
        print "Verify on router using cli : show route protocol bgp-static"
        raw_input("<ENTER to Get route>")
        RouteGet(bgp)
        print "Compare API out put with CLI : show route protocol bgp-static"
        raw_input("<ENTER to Delete route>")
        RouteDel(bgp)
        print "Verify on router using cli : show route protocol bgp-static"
        raw_input("<Verify in router and ENTER>")
        print "Closing the Client"
        client.CloseNotificationSession()

    except Exception as tx:
        print '%s' % (tx.message)
    return
Ejemplo n.º 2
0
    dispatch_thread.setDaemon(True)
    dispatch_thread.start()
    # Connection to JSD
    client = JetHandler()

    # Open a Request Response session
    client.OpenRequestResponseSession(device=HOST,
                                      port=PORT,
                                      user=USER,
                                      password=PASSWORD,
                                      ca_certs=None,
                                      client_id=CLIENT_ID)
    LOG.info("Connected to the JET request response server")

    # Open a notification channel to receive the streaming GET response from JSD
    evHandle = client.OpenNotificationSession(HOST, 1883, None, None, None,
                                              DEFAULT_MQTT_TIMEOUT, "", True)
    LOG.info("Connected to the JET notification server")
    bgp = client.GetRoutingBgpRoute()
    prpd = client.GetRoutingBase()

    purgeTime = 30
    # Variables for RouteGet Operation
    eod = 0
    count = 0
    getroutelist = []
    getwaitflag = 0

    # Dictionary of sockets waiting on incomplete data for requests
    sockdict = {}

    # Route request queue
Ejemplo n.º 3
0
def mail(message):
    smtpObj = smtplib.SMTP('smtp.juniper.net')
    smtpObj.sendmail(sender, receivers, message)
    print "Successfully sent email"

try:
    # Create a client handler for connecting to server
    client = JetHandler()

    # Open session with Thrift Servers
    client.OpenRequestResponseSession(device=R1, connect_timeout=300000, user=APP_USER, password=APP_PASSWORD, client_id= "1211111")
    print "\nEstablished connection with the", R1

    # Create a service handlers
    R1_route_handle = client.GetRouteService()
    R1_mgmt_handle = client.GetManagementService()

    # Create a event handlers to MQTT server
    evHandle = client.OpenNotificationSession(device=R1)

    # Subscribe for syslog events
    syslog = evHandle.CreateSyslogTopic("SNMPD_RMON_EVENTLOG")
    print "Subscribing to Syslog RMON notifications"
    evHandle.Subscribe(syslog, on_message)

    while 1:
        1 + 1

except Exception as tx:
    print '%s' % tx.message
def Main():
    parser = argparse.ArgumentParser(prog=os.path.basename(__file__),
                                     description='Sample JET application')
    parser.add_argument(
        "--address",
        nargs='?',
        help="Address of the JSD server. (default: %(default)s)",
        type=str,
        default='localhost')
    parser.add_argument(
        "--port",
        nargs='?',
        help="Port number of the JSD notification server. default: %(default)s",
        type=int,
        default=1883)
    parser.add_argument("--bind_address",
                        nargs='?',
                        help="Client source address to bind.",
                        type=str,
                        default="")
    args = parser.parse_args()

    try:

        # Create a client handler for connecting to server
        client = JetHandler()

        # open session with MQTT server
        evHandle = client.OpenNotificationSession(
            device=args.address,
            port=args.port,
            bind_address=args.bind_address)
        # different ways of creating topic
        ifdtopic = evHandle.CreateIFDTopic(
            op=evHandle.ALL, ifd_name=DEFAULT_NOTIFICATION_IFD_NAME)
        ifltopic = evHandle.CreateIFLTopic(evHandle.ALL,
                                           DEFAULT_NOTIFICATION_IFL_NAME,
                                           DEFAULT_NOTIFICATION_IFL_UNIT)
        ifatopic = evHandle.CreateIFATopic(evHandle.DELETE)
        ifftopic = evHandle.CreateIFFTopic(evHandle.CHANGE)
        rtmtopic = evHandle.CreateRouteTableTopic(evHandle.ALL)
        rttopic = evHandle.CreateRouteTopic(evHandle.ALL)
        fwtopic = evHandle.CreateFirewallTopic(evHandle.ALL)

        # Subscribe for events
        print "Subscribing to IFD notifications"
        evHandle.Subscribe(ifdtopic, handleEvents1)
        evHandle.Subscribe(ifltopic, handleEvents2)
        #evHandle.Subscribe(ifftopic, handleEvents1)
        evHandle.Subscribe(ifatopic, handleEvents1)
        evHandle.Subscribe(rtmtopic, handleEvents2)
        evHandle.Subscribe(rttopic, handleEvents2)
        evHandle.Subscribe(fwtopic, handleEvents1)
        ret = evHandle.Unsubscribe(ifftopic)
        if ret != 0:
            print('Failed to unsubscribe %s' % ifftopic.topic)
        evHandle.Unsubscribe(ifdtopic)

        time.sleep(5)
        # Unsubscribe events
        print "Unsubscribe from all the event notifications"
        evHandle.Unsubscribe()

        # Close session
        print "Closing the Client"
        client.CloseNotificationSession()

    except Exception, tx:
        print '%s' % (tx.message)