def Main(): try: "connection handles to site is optional in case polling to sites on SNMP/DyCOS server" for i in range(1, n + 1): S_handle = JetHandler() S_handle.OpenRequestResponseSession(device=globals()['S%s_IP' % i], port=PORT, user=USER, password=PASSWORD, client_id=CLIENT_ID) S_mgmt = S_handle.GetManagementService() globals()['mgmt_S%s' % i] = S_mgmt "MX router connection and JET service handles" for i in range(1, n - 1): R_handle = JetHandler() R_handle.OpenRequestResponseSession(device=globals()['R%s_IP' % i], port=PORT, user=USER, password=PASSWORD, client_id=CLIENT_ID) R_fw = R_handle.GetFirewallService() R_mgmt = R_handle.GetManagementService() globals()['mgmt_R%s' % i] = R_mgmt globals()['fw_R%s' % i] = R_fw Initial_Cos_Configs() Get_Site_Latest_Data() except KeyboardInterrupt: pass except Exception as tx: print '%s' % (tx.message) return
def Main(): parser = argparse.ArgumentParser(prog=os.path.basename(__file__), description='Sample JET application') parser.add_argument( "--user", nargs='?', help="Username for authentication by JET server (default:%(default)s)", type=str, default=DEFAULT_JSD_USERNAME) parser.add_argument( "--password", nargs='?', help="Password for authentication by JET server (default:%(default)s", type=str, default=DEFAULT_JSD_PASSWORD) parser.add_argument( "--address", nargs='?', help="Address of the JSD server. (default: %(default)s)", type=str, default=DEFAULT_JSD_HOST) parser.add_argument( "--port", nargs='?', help= "Port number of the JSD request-response server. (default: %(default)s)", type=int, default=DEFAULT_JSD_PORT) parser.add_argument("--certificate", nargs='?', help="Certificate full path. (default: %(default)s)", type=str, default=DEFAULT_JSD_SSL_CERTIFICATE_PATH) args = parser.parse_args() # Create a client handler for connecting to server client = JetHandler() # Open session with Thrift Server try: client.OpenRequestResponseSession(device=args.address, port=args.port, user=args.user, password=args.password, ca_certs=args.certificate, client_id='T101') print 'Requesting for Interface services' FirewallTests(client) client.CloseRequestResponseSession() except Exception as tx: print '%s' % (tx.message) traceback.print_exc(file=sys.stdout) return
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
except: LOG.debug("SocketIO: Write failed") requestQ.task_done() try: CONNECTION_LIST = list() for i in range(1): t = Thread(target=allRouteApis) t.setDaemon(True) t.start() dispatch_thread = Thread(target=sendtoPS) 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()
mail (message = """Subject: SMTP e-mail test JET App deleted route in R1""") else: print "V4RouteDelete service API deactivation failed \n" route_present = True else: print "No changes required \n" 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"
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)