示例#1
0
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():
    # 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
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
示例#4
0
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()
    prpd = client.GetRoutingBase()

    purgeTime = 30
    # Variables for RouteGet Operation
    eod = 0
    count = 0
示例#5
0
            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"
    evHandle.Subscribe(syslog, on_message)

    while 1: