from requests.packages.urllib3 import disable_warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from src import loginOS, vlan, deviceidentity, ports
from sampledata import getyaml

disable_warnings(InsecureRequestWarning)

data = getyaml.readyaml()
for ip in data['ipadd']:
    baseurl = "https://{}/rest/v4/".format(ip)
    try:
        cookie_header = loginOS.login_os(data, baseurl)
        # --------------- Name the Ports --------------- #
        portname = data['port']
        print('Port Information: {}'.format(portname))
        for name in portname:
            ports.name_ports(baseurl, cookie_header, name)
        # --------------- Create Vlans tagged and untagged --------------- #
        vlandata = data['vlan']
        for vlans in vlandata:
            print("Vlan to create \n", vlans)
            vlan.create_vlan(baseurl, cookie_header, vlans)
        # --------------- Get all Vlans --------------- #
        vlans = vlan.get_vlan(baseurl, cookie_header)
        print('Vlans in the system are: \n')
        for i in range(len(vlans['vlan_element'])):
            print("Vlan ID: {} and Vlan Name: {}".format(
                vlans['vlan_element'][i]['vlan_id'],
                vlans['vlan_element'][i]['name']))
        # --------------- create LACP ports with trunk --------------- #
        lacpport = data['lacpport']
예제 #2
0
from requests.packages.urllib3 import disable_warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from sampledata import getyaml
from src import loginOS, snmp, system

disable_warnings(InsecureRequestWarning)

# Login to Switch
data = getyaml.readyaml('data-device-mgmt.yaml')

# Iterate through the devices in data-device-mgmt.yaml file to update User password and create new SNMP Communities
for device in data['devices']:
    baseurl = "https://{}/rest/v4/".format(device["ip_address"])
    cookie_header = loginOS.login_os(device, baseurl)

    try:
        userFound = False
        communityFound = False
        communities = snmp.get_snmp_communities(baseurl, cookie_header)
        print(communities['snmp_server_community_element'])
        for community in communities['snmp_server_community_element']:
            if community['community_name'] == device["past_snmp"]:
                communityFound = True
                print("Creating SNMP community string: {} in switch: {}.".format(
                    device["past_snmp"], device["ip_address"]))
                result = snmp.create_snmp_community(baseurl, cookie_header, device["new_snmp"], community)
                if result == 201:
                    snmp.delete_snmp_community(baseurl, cookie_header, device["past_snmp"])
        if not communityFound:
            print("SNMP community string: {} not found in switch: {}".format(device["past_snmp"], device["ip_address"]))
        users = system.get_device_users(baseurl, cookie_header)