Exemple #1
0
 def __init__(self, host, port, username, password):
     """This class creates a grpc client for the functions to use.
         :param host: The ip address for the device.
         :param port: The port for the device.
         :param user: Username for device login.
         :param password: Password for device login.
         :type host: str
         :type port: int
         :type password: str
         :type username: str
     """
     self.client = CiscoGRPCClient(host, port, 10, username, password)
def main():
    '''
    To not use tls we need to do 2 things. 
    1. Comment the variables creds and options out
    2. Remove creds and options CiscoGRPCClient
    ex: client = CiscoGRPCClient('11.1.1.10', 57777, 10, 'vagrant', 'vagrant')
    '''
    creds = open('ems.pem').read()
    options = 'ems.cisco.com'
    client = CiscoGRPCClient('11.1.1.10', 57777, 10, 'vagrant', 'vagrant',
                             creds, options)
    #Test 1: Test Get config json requests
    path = '{"Cisco-IOS-XR-ip-static-cfg:router-static": [null]}'
    result = client.getconfig(path)
    print json.dumps(json.loads(result))
Exemple #3
0
def main():
    '''
    To not use tls we need to do 2 things.
    1. Comment the variables creds and options out
    2. Remove creds and options CiscoGRPCClient
    ex: client = CiscoGRPCClient('11.1.1.10', 57777, 10, 'vagrant', 'vagrant')
    '''
    creds = open('ems.pem').read()
    options = 'ems.cisco.com'
    client = CiscoGRPCClient('127.0.0.1', 57777, 10, 'vagrant', 'vagrant',
                             creds, options)
    #Test 1: Test Get config json requests
    path = '{"Cisco-IOS-XR-ip-static-cfg:router-static": [null]}'
    try:
        err, result = client.getconfig(path)
        if err:
            print err
        print json.dumps(json.loads(result))
    except AbortionError:
        print('Unable to connect to local box, check your gRPC destination.')
Exemple #4
0
""" Basic collector for telemetry.
Initiate a gRPC dial-in telemetry channel, subscribe to a stream,
and output to display. Converts from protobuf to JSON for display.
"""

import sys
sys.path.insert(0, '../')
from lib.cisco_grpc_client import CiscoGRPCClient
import json


def print_connectivity(connectivity):
    print connectivity


# Change client details to match your environment.
client = CiscoGRPCClient('localhost', 57777, 10, 'vagrant', 'vagrant')
subscription_id = 'sub1'
recv_count = 0
# Handle connectivity changes.
client.connectivityhandler(print_connectivity)
# Iterate over subscription recvs.
for segment in client.getsubscription(subscription_id, unmarshal=True):
    # unmarshal is an optional argument, default is unmarshal = True
    # If unmarshal is false, out is in gpb k/v
    recv_count += 1
    print json.dumps(segment, indent=4, separators=(',', ': '))
    print 'End Telemetry Segment'
    print str(recv_count) + ' Segments Received'
Exemple #5
0
 def __init__(self):
     self.client = CiscoGRPCClient('127.0.0.1', 57777, 10, 'vagrant', 'vagrant')
 def setUp(self):
     self.client = CiscoGRPCClient('192.168.1.2', 57777, 10, 'vagrant',
                                   'vagrant')
     self.maxDiff = None
     path = '{"Cisco-IOS-XR-ip-static-cfg:router-static": [null]}'
     self._result = self.client.getconfig(path)
Exemple #7
0
def main():

    __version__ = 'GRPC_Client 1.0'
    arguments = docopt(__doc__, version=__version__)

    IP = arguments['<router_IP>']
    TCP_PORT = int(arguments['<port>'])
    user = arguments['<user>']
    password = arguments['<password>']
    RPC = arguments['<rpc>']

    client = CiscoGRPCClient(IP, TCP_PORT, 10, user, password)

    if RPC == "get-oper":

        if arguments['--file']:
            file = arguments['--file']
            path = open(file).read()
#            path = open('json/' + file).read()
        else:
            path = 'Error'
            print(
                'get-oper argument must include --file option and json file to filter yang operational namespace'
            )
        try:
            err, result = client.getoper(path)
            if err:
                print err
            print result
        except AbortionError:
            print(
                'Unable to connect to local box, check your gRPC destination.')

    if RPC == "get-config":

        if arguments['--file']:
            file = arguments['--file']
            path = open(file).read()


#            path = open('json/' + file).read()
        else:
            path = ""

        try:
            err, result = client.getconfig(path)
            if err:
                print err
            print result
        except AbortionError:
            print(
                'Unable to connect to local box, check your gRPC destination.')

    if RPC == "merge-config":

        if arguments['--file']:
            file = arguments['--file']
            path = open(file).read()
        else:
            path = 'Error'
            print(
                'get-oper argument must include --file option and json file to filter yang operational namespace'
            )
        try:
            err = client.mergeconfig(path)
            if err:
                print err
            #print result
        except AbortionError:
            print(
                'Unable to connect to local box, check your gRPC destination.')

    if RPC == "replace-config":

        if arguments['--file']:
            file = arguments['--file']
            path = open(file).read()
        else:
            path = 'Error'
            print(
                'get-oper argument must include --file option and json file to filter yang operational namespace'
            )
        try:
            err = client.replaceconfig(path)
            if err:
                print err
        except AbortionError:
            print(
                'Unable to connect to local box, check your gRPC destination.')
Exemple #8
0
""" Basic gRPC getcall configuration. Shows how to set up the vairables
for tls and how to put into the class and get information from the box.
    """
    import json
    from grpc.framework.interfaces.face.face import AbortionError
    import sys
    sys.path.insert(0, '../')
    from lib.cisco_grpc_client import CiscoGRPCClient

    def main():
            '''
        To not use tls we need to do 2 things.
        1. Comment the variables creds and options out
        2. Remove creds and options CiscoGRPCClient
        ex: client = CiscoGRPCClient('10.1.1.30', 57777, 10, 'vagrant', 'vagrant')
        '''
        creds = open('ems.pem').read()
        options = 'ems.cisco.com'
        client = CiscoGRPCClient('127.0.0.1', 57777, 10, 'vagrant', 'vagrant',creds,options)
        policy_file = open('example.cfg', 'r')
        new_policy = policy_file.read()
        policy_file.close()
        result = client.commitreplace(new_policy)
        print result

    if __name__ == '__main__':
        main()