Exemplo n.º 1
0
def read_devices_info(devices_file):

    devices_list = []

    # Open the device file with JSON data and read into string
    json_file = open(devices_file,'r')   # open the JSON file
    json_device_data = json_file.read()  # read in the JSON data from file

    # Convert JSAON string into Python data structure
    devices_info_list = json.loads(json_device_data)

    for device_info in devices_info_list:

        # Create a device object with this data
        if device_info['os'] == 'ios':
 
            device = NetworkDeviceIOS(device_info['name'],device_info['ip'],
                                      device_info['user'],device_info['password'])

        elif device_info['os'] == 'ios-xr':
 
            device = NetworkDeviceXR(device_info['name'],device_info['ip'],
                                     device_info['user'],device_info['password'])

        else:
            device = NetworkDevice(device_info['name'],device_info['ip'],
                                   device_info['user'],device_info['password'])

        devices_list.append(device) # Append this device object to list

    return devices_list
def read_devices_info(devices_file):

    devices_list = []

    file = open(devices_file,'r')   # Open the CSV file
    csv_devices = csv.reader(file)  # Create the CSV reader for file

    # Iterate through all devices in our CSV file
    for device_info in csv_devices:

        # Create a device object with this data
        if device_info[1] == 'ios':
 
            device = NetworkDeviceIOS(device_info[0],device_info[2],
                                      device_info[3],device_info[4])

        elif device_info[1] == 'ios-xr':
 
            device = NetworkDeviceXR(device_info[0],device_info[2],
                                     device_info[3],device_info[4])

        else:
            device = NetworkDevice(device_info[0],device_info[2],
                                   device_info[3],device_info[4])

        devices_list.append(device) # Append this device object to list

    return devices_list
Exemplo n.º 3
0
def read_devices_info(devices_file):

    devices_list = []

    file = open(devices_file, 'r')
    for line in file:

        device_info = line.strip().split(',')

        # Create a device object with this data
        if device_info[1] == 'ios':

            device = NetworkDeviceIOS(device_info[0], device_info[2],
                                      device_info[3], device_info[4])

        else:
            device = NetworkDevice(device_info[0], device_info[2],
                                   device_info[3], device_info[4])

        devices_list.append(device)

    return devices_list
def read_devices_info(devices_file):

    devices_list = []

    # Open the device file with JSON data and read into string
    json_file = open(devices_file,'r')   # open the JSON file
    json_device_data = json_file.read()  # read in the JSON data from file

    # Convert JSAON string into Python data structure
    devices_info_list = json.loads(json_device_data)

    for device_info in devices_info_list:

        # Create a device object with this data
        if device_info['os'] == 'ios':
 
            device = NetworkDeviceIOS(device_info['name'],device_info['ip'],
                                      device_info['user'],device_info['password'])

        elif device_info['os'] == 'ios-xr':
 
            device = NetworkDeviceXR(device_info['name'],device_info['ip'],
                                     device_info['user'],device_info['password'])

        else:
            device = NetworkDevice(device_info['name'],device_info['ip'],
                                   device_info['user'],device_info['password'])

        # Open SSH key file for this device
        key_file_path = "sshkeys/"+device_info['ip']+"/"+device_info['key']
        key_file = open(key_file_path,'rb')

        key_data = key_file.read()    # read ssh key data
        device.set_sshkey(key_data)   # store ssh key data in device object

        devices_list.append(device) # Append this device object to list

    return devices_list
Exemplo n.º 5
0
 def __init__(self, name, ip, user='******', pw='cisco'):
     NetworkDevice.__init__(self, name, ip, user, pw)
     self.os_type = 'ios'
 def __init__(self, name, ip, user='******', pw='cisco'):
     NetworkDevice.__init__(self, name, ip, user, pw)