Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation
Guide That Contains This Content
[+] Expand All
[-] Collapse All

    JET Interfaces Application

    sampleInterfaceApp.py illustrates the following functions of the JET interfaces:

    1. Creates an IFL object

    2. Deletes an IFL object

    3. Creates an IFA object

    4. Deletes an IFA object

    The application uses the device IP and IFA address as the inputs.

    The application must be configured as shown in the example using:
    set system extensions extension-service application file sampleInterfaceApp.py arguments "-addr 10.0.0.1 -host 10.221.138.41"
    Where 10.221.138.41 is the IP of the device and 10.0.0.1 is the IFA address to be created.

    #!/usr/bin/env python
    from grpc.beta import implementations
    from dcd_service_pb2 import *
    import authentication_service_pb2
    import dcd_service_pb2
    import argparse
    import sys,signal,os,jcs
    
    GRPC_PORT = 32767
    CLIENT_ID = 'G1_1175'
    USER = 'foo'
    PASSWORD = 'bar'
    TIMEOUT = 5
    
    def connect_to_jsd(args):
    	channel = implementations.insecure_channel(host=args.hostip, port=GRPC_PORT)
    	stub = authentication_service_pb2.beta_create_Login_stub(channel)
    	login_response = stub.LoginCheck(authentication_service_pb2.LoginRequest(user_name=USER,password=PASSWORD, client_id=CLIENT_ID), TIMEOUT)
    	if login_response.result != True:
    		print "gRPC Server Connection failed!!!"
    
    	dcd = dcd_service_pb2.beta_create_InterfacesService_stub(channel)
    
    	return dcd
    
    def exe_op_test(dcd,args):
    
    	#InterfaceLogicalCreate
    	# Create IFL object for interface ge-0/0/1 unit 0
    	unit = Value32(unit=0)
    	config = InterfaceLogicalConfig(port_name = "ge-0/0/1",ifl_unit = unit,operation = 1)
    	Result = dcd.InterfaceLogicalCreate(config,TIMEOUT)
    	print 'Invoked DCD logical create API Status return = ', Result.status
    	print 'Invoked DCD logical create API Error message return = ', Result.error_message
    
    	#InterfaceLogicalDelete
    	# Delete IFL object for interface ge-0/0/1 unit 0
    	unit = Value32(unit=0)
    	config = InterfaceLogicalConfig(port_name = "ge-0/0/1",ifl_unit = unit,operation = 2)
    	Result = dcd.InterfaceLogicalDelete(config,TIMEOUT)
    	print 'Invoked DCD logical delete API Status return = ', Result.status
    	print 'Invoked DCD logical delete API Error message return = ', Result.error_message
    
    
    	#InterfaceAddressCreate
    	# Create IFA object for interface ge-0/0/1 unit 0 family inet address 10.0.0.1
    	add = IpAddress(addr_string=args.address)
    	unit = Value32(unit=0)
    	config = InterfaceAddressConfig( port_name = "ge-0/0/1", ifl_unit = unit, operation = 1, family = 2, interface_address = add)
    	Result = dcd.InterfaceAddressCreate(config,TIMEOUT)
    	print 'Invoked DCD InterfaceAddressCreate API Status return = ', Result.status
    	print 'Invoked DCD InterfaceAddressCreate API Error message return = ', Result.error_message
    
    	#InterfaceAddressDelete
    	# Delete IFA object for interface ge-0/0/1 unit 0 family inet address 10.0.0.1
    	add = IpAddress(addr_string=args.address)
    	unit = Value32(unit=0)
    	config = InterfaceAddressConfig( port_name = "ge-0/0/1", ifl_unit = unit, operation = 2, family = 2, interface_address = add)
    	Result = dcd.InterfaceAddressDelete(config,TIMEOUT)
    
    	print 'Invoked DCD InterfaceAddressDelete API Status return = ', Result.status
    	print 'Invoked DCD InterfaceAddressDelete API Error message return = ', Result.error_message
    
    	return
    
    
    def Main():
    	parser = argparse.ArgumentParser(description='This is a demo script by nixCraft.')
    	parser.add_argument('-addr','--address',help='Input Addres name', required=False)
    	parser.add_argument('-host','--hostip',help='Input Attribute type`', required=False)
    
    	args = parser.parse_args()
    
    	try:
    		dcd = connect_to_jsd(args)
    		exe_op_test(dcd,args)
    		print "In finally statement"
    		#raw_input("<ENTER to Close Client Session>")
    	except Exception as tx:
    		print tx
    			#sys.exit(3)
    	finally:
    		#print "In finally statement"
    		os.kill(os.getpid(), signal.SIGTERM)
    
    	return
    
    if __name__ == '__main__':
    	Main()
    

    Modified: 2018-02-22