# coding=utf-8 """ Modules Import """ from requests.packages.urllib3 import disable_warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning from sampledata import getyaml from src import loginOS, tn disable_warnings(InsecureRequestWarning) """ Retrieve and display LLDP Informations for each devices. """ # Login to Switch data = getyaml.readyaml('data-tn.yaml') for x in data['ipadd']: baseurl = "https://{}/rest/v4/".format(x) try: cookie_header = loginOS.login_os(data, baseurl) result = tn.get_tnconf(baseurl, cookie_header) print("\nTunneled-Node Global Configuration") tn.print_tnconfig(result) if result['is_tn_server_configured'] is True: result = tn.get_tnstats(baseurl, cookie_header) print("\nTunneled-Node Statistics\n") tn.print_tnstats(result) print("\nUsers currently connected with Tunneled-Node\n") result = tn.get_tn_users(baseurl, cookie_header) print(result)
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']
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)
from requests.packages.urllib3 import disable_warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning from sampledata import getyaml from src import loginOS from src import vsf disable_warnings(InsecureRequestWarning) data = getyaml.readyaml('data.yaml') for ip in (data['ipadd']): baseurl = "https://{}/rest/v6/".format(ip) try: cookie_header = loginOS.login_os(data, baseurl) # This workflow shows all the information that can be seen # from the "show vsf" command in CLI. print('\n\nVSF Global configuration: \n') vsf_config = vsf.get_global_config(baseurl, cookie_header) vsf_info = vsf.get_vsf_info(baseurl, cookie_header) vsf_members = vsf.get_vsf_members(baseurl, cookie_header) # Prints only the desired information not the json file. vsf.print_show_vsf(vsf_info, vsf_members, vsf_config) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) finally: loginOS.logout(baseurl, cookie_header)
""" Modules Import """ from requests.packages.urllib3 import disable_warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning from sampledata import getyaml from src import loginOS, lldp disable_warnings(InsecureRequestWarning) """ Retrieve and display LLDP Information for each devices. """ data = getyaml.readyaml('data-lldp.yaml') for ip in data['ipadd']: baseurl = "https://{}/rest/v4/".format(ip) try: cookie_header = loginOS.login_os(data, baseurl) result = lldp.lldp(baseurl, cookie_header) print("\nLLDP Global Status") lldp.print_lldpstatus(result) if result['admin_status'] == 'LLAS_ENABLED': result = lldp.lldp_remote(baseurl, cookie_header) print("\nLLDP remote devices information\n") lldp.print_lldpremote(result) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) finally: loginOS.logout(baseurl, cookie_header)
from sampledata import getyaml from src import loginOS, ip_static_route from requests.exceptions import ConnectTimeout from requests.packages.urllib3 import disable_warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning disable_warnings(InsecureRequestWarning) data = getyaml.readyaml('data_static_route.yaml') destination = data['destination'] mask = data['mask'] gateway = data['gateway'] for x in data['ipadd']: baseurl = "https://{}/rest/v4/".format(x) try: # Login cookie_header = loginOS.login_os(data, baseurl) except ConnectTimeout as error: print('Ran into exception: {}'.format(error)) else: try: # Configure static route ip_static_route.configure_static_route(baseurl, cookie_header, destination, mask, gateway) # Get routing table static_data = ip_static_route.get_ip_route(baseurl, cookie_header) # Print RIB to screen ip_static_route.print_static_route(static_data) # Ping static gateway and print result to screen ip_static_route.gateway_check(baseurl, gateway, cookie_header) except Exception as error:
from requests.packages.urllib3 import disable_warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning from sampledata import getyaml from src import loginOS, vxlan disable_warnings(InsecureRequestWarning) data = getyaml.readyaml('data-vxlan.yaml') vxlan_data = data['vxlan'] for ip in (data['ipadd']): baseurl = "https://{}/rest/v4/".format(ip) try: cookie_header = loginOS.login_os(data, baseurl) for x in vxlan_data: result = vxlan.configure_vxlan(baseurl, x, cookie=cookie_header) vxlan.print_vxlandeploy(result, ip) except Exception as error: print('Ran into exception: {}. Logging out...'.format(error)) finally: loginOS.logout(baseurl, cookie_header)