示例#1
0
def main():
    switchip = input("Switch IP Address: ")

    username = input("Switch login username: "******"Switch login password: "******"https://{0}/rest/{1}/".format(switchip, version)
    try:
        session_dict = dict(s=session.login(base_url, username, password),
                            url=base_url)

        system_info_dict = system.get_system_info(
            params={"selector": "configuration"}, **session_dict)

        pprint.pprint(system_info_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))
    session.logout(**session_dict)
示例#2
0
    def _get_client(self):
        # self.config['username'] = '******'
        # self.config['password'] = '******'

        base_url = "https://{0}/rest/{1}/".format('10.132.0.213', 'v10.04')
        # base_url = "https://{0}/rest/{1}/".format(self.config['switchip'], self.config['version'])
        print(base_url)
        try:
            session_dict = dict(s=session.login(base_url, 'admin', 'siesta3'), url=base_url)
            # session_dict = dict(s=session.login(base_url, self.config['username'], self.config['password']), url=base_url)
        except Exception as error:
            print('Ran into exception: {}. Logging out..'.format(error))
            session.logout(**session_dict)
        return (session, session_dict)
示例#3
0
def main():
    switchip = input("Switch IP Address: ")

    username = input("Switch login username: "******"Switch login password: "******"https://{0}/rest/{1}/".format(switchip, version)
    try:
        session_dict = dict(s=session.login(base_url, username, password),
                            url=base_url)

        vlan.create_vlan_and_svi(999,
                                 'VLAN999',
                                 'vlan999',
                                 'vlan999',
                                 'For LAB 999',
                                 '10.10.10.99/24',
                                 vlan_port_desc='### SVI for LAB999 ###',
                                 **session_dict)

        # Add DHCP helper IPv4 addresses for SVI
        dhcp.add_dhcp_relays('vlan999', "default", ['1.1.1.1', '2.2.2.2'],
                             **session_dict)

        # Add a new entry to the Port table if it doesn't yet exist
        interface.add_l2_interface('1/1/20', **session_dict)

        # Update the Interface table entry with "user-config": {"admin": "up"}
        interface.enable_disable_interface('1/1/20', **session_dict)

        # Set the L2 port VLAN mode as 'access'
        vlan.port_set_vlan_mode('1/1/20', "access", **session_dict)

        # Set the access VLAN on the port
        vlan.port_set_untagged_vlan('1/1/20', 999, **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))
    session.logout(**session_dict)
 def get_info_link(self, hostname, port):
     """
     get the MAC address and IP address using LLDP information of the device
     connected to the specified port of an AOS-CX switch
     :param hostname: AOS-CX hostname found in syslog message
     :param port: interface who's link came up in syslog message
     :return: list of ip adress, mac address, and device name
     """
     # gets switch login info that sent syslog
     ip, username, password = self.get_syslog_host_tower_info(hostname)
     # log into AOS-CX switch
     login_url = "https://" + ip + ":443/rest/v1/"
     sesh = session.login(login_url, username, password)
     try:
         response = lldp.get_lldp_neighbor_info(int_name=port,
                                                s=sesh,
                                                url=login_url,
                                                depth=3)
         if not response:
             self.logger.error("Failed REST called to "
                               "AOS-CX: {0}".format(ip))
             session.logout(s=sesh, url=login_url)
             exit(-1)
         ip_addr = None
         if response["interface"]["name"] == port:
             ip_addr_tmp = response["neighbor_info"]["mgmt_ip_list"]
             # In case both IPv4 and IPv6 addresses are found, IPv4 is used
             if ',' in str(ip_addr_tmp):
                 ip_addr_split = ip_addr_tmp.split(',')
                 for address in ip_addr_split:
                     if ':' not in address:
                         ip_addr = address
             # Protects against MAC address populating for mgmt address
             elif ':' not in str(ip_addr_tmp):
                 ip_addr = ip_addr_tmp
             else:
                 self.logger.error("\nERROR: IPv4 address not populated on"
                                   "{0} - found {1} ".format(
                                       port, ip_addr_tmp))
             mac_addr = response["chassis_id"]
             device_name = response["neighbor_info"]["chassis_name"]
             session.logout(s=sesh, url=login_url)
             return [ip_addr, mac_addr, device_name]
     except Exception as error:
         self.logger.error("ERROR: %s", error)
         session.logout(s=sesh, url=login_url)
         exit(-1)
     # registers error if port not found on core switch
     self.logger.error(
         "ERROR: Failed to retrieve "
         "LLDP info port %s not found on %s", port, ip)
     session.logout(s=sesh, url=login_url)
     exit(-1)
示例#5
0
    def get_link_status(self, ip, username, password, proxy):
        """
        executes REST API call to AOS-CX switch and retrieves the given
        switch's interfaces and their link status
        :param ip:  Address to be used in REST API calls
        :param username: Switch login username used in REST API call
        :param password: Switch login password used in REST API call
        :param proxy: Dictionary containing proxy information with keys 'http'
        and 'https'
        :return: dict of all interfaces link statuses present on the switch
        """
        # log into AOS-CX switch
        login_url = "https://" + ip + ":443/rest/v1/"

        sesh = session.login(login_url, username, password)
        response = interface.get_all_interfaces(s=sesh, url=login_url)
        if not response:
            self.logger.error("Failed REST called to "
                              "AOS-CX: {0}".format(ip))
            session.logout(s=sesh, url=login_url)
            exit(-1)
        try:
            # create a dictionary of each interface's link status
            link_stat_dict = {}
            for int_url in response:
                # Takes string after last '/'
                port_num = int_url[(int_url.rfind('/') + 1):]
                # Ignore bridge_normal interface
                if port_num == "bridge_normal":
                    continue
                int_response = (sesh.get("https://" + ip + int_url,
                                         verify=False,
                                         proxies=proxy))
                link_state = json.loads(int_response.text)["link_state"]
                port_num = common_ops._replace_percents(port_num)
                link_stat_dict[port_num] = link_state
            # logs out of the core switch
            session.logout(s=sesh, url=login_url)
            return link_stat_dict
        except Exception as error:
            self.logger.error("ERROR: %s", error)
            session.logout(s=sesh, url=login_url)
            exit(-1)
示例#6
0
#!/usr/bin/env python3

# (C) Copyright 2019-2020 Hewlett Packard Enterprise Development LP.
# Apache License 2.0

from requests.packages.urllib3.exceptions import InsecureRequestWarning
from pyaoscx import session, vlan
import requests
import os

# requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


base_url = "https://{0}/rest/{1}/".format('10.132.0.213','v1')
print(base_url)
session_dict = dict(s=session.login(base_url, 'admin', 'siesta3'), url=base_url)
vlan_data1 = vlan.get_all_vlans(**session_dict)
print("VLAN data: %s" % (vlan_data1))
print('Logging Out!')
session.logout(**session_dict)