Exemplo n.º 1
0
    def connect_to_switches(self,
                            switch_list,
                            username,
                            password,
                            connection_type='https',
                            port=None,
                            timeout=30,
                            verify_ssl=True):
        """

        :param switch_list:
        :param username:
        :param password:
        :param connection_type:
        :param port:
        :param timeout:
        :param verify_ssl:
        :return:
        """
        for eachsw_ip in switch_list:
            swobj = Switch(eachsw_ip,
                           username=username,
                           password=password,
                           connection_type=connection_type,
                           port=port,
                           timeout=timeout,
                           verify_ssl=verify_ssl)
            self.__sw_obj_dict[eachsw_ip] = swobj
        return self.__sw_obj_dict
Exemplo n.º 2
0
    def connect_to_switches(self, switch_list, username, password, connection_type='https', port=None, timeout=30,
                            verify_ssl=True):
        """

        :param switch_list: List of switch ips that needs to be connected to
        :type switch_list: list
        :param username: username of the switches
        :type username: str
        :param password: password of the switches
        :type password: str
        :param connection_type: type of the connection http or https default is https
        :type connection_type:str
        :param port: http or https port, default is 8443
        :type port:int
        :param timeout: connection or command timeout in secs, default is 30s
        :type timeout:int
        :param verify_ssl: Default is True, please set it to False if there is no SSL defined between the switches and the host
        :type verify_ssl:bool
        :return: Dictionary with key value pair as switch ip and Switch object
        :rtype: dict
        """
        for eachsw_ip in switch_list:
            swobj = Switch(eachsw_ip, username=username, password=password, connection_type=connection_type, port=port,
                           timeout=timeout, verify_ssl=verify_ssl)
            self.__sw_obj_dict[eachsw_ip] = swobj
        return self.__sw_obj_dict
Exemplo n.º 3
0
def main():
    from tests.enablelog import ScriptLog, banner
    sl = ScriptLog("switch.log")
    log = sl.log
    from mdslib.switch import Switch

    user = '******'
    pw = 'nbv!2345'
    ip_address = '10.126.94.104'
    ip_address1 = '10.126.94.121'

    p = 8443

    sw104 = Switch(
        ip_address=ip_address,
        username=user,
        password=pw,
        connection_type='https',
        port=p,
        timeout=30,
        verify_ssl=False)

    sw121 = Switch(
        ip_address=ip_address1,
        username=user,
        password=pw,
        connection_type='https',
        port=p,
        timeout=30,
        verify_ssl=False)

    sw220 = Switch(
        ip_address="10.126.94.220",
        username=user,
        password=pw,
        connection_type='https',
        port=p,
        timeout=30,
        verify_ssl=False)

    sw = sw220
    banner("ip, version, model, npv")
    print("switch ip addr is   : " + sw.ipaddr)
    print("switch version is   : " + sw.version)
    print("switch model is     : " + sw.model)
    print("switch npv state is : " + str(sw.npv))
    banner("end")
Exemplo n.º 4
0
sl = ScriptLog("switch.log", consolelevel=logging.INFO)
log = sl.log

log.info("Starting Test...")

user = '******'
pw = 'nbv!2345'
ip_address = '10.126.94.104'
ip_address1 = '10.126.94.121'

p = 8443

sw104 = Switch(ip_address=ip_address,
               username=user,
               password=pw,
               connection_type='https',
               port=p,
               timeout=30,
               verify_ssl=False)

sw121 = Switch(
    ip_address=ip_address1,
    # ip_address='10.197.155.110',
    username=user,
    password=pw,
    # password='******',
    connection_type='https',
    port=p,
    timeout=30,
    verify_ssl=False)
Exemplo n.º 5
0
from mdslib.switch import Switch
from mdslib.vsan import Vsan

user = '******'
pw = 'yourswitchpassword'
ip_address = 'yourswitchip' # 10.197.155.110
p = 8443
sw = Switch(ip_address=ip_address,username=user,password=pw,connection_type='https',port=p,timeout=30,verify_ssl=False)

# Example for creating and deleting 10 vsan objects from id 10 to 19
vsan = []
for i in range(10,20):
	vsan.append(Vsan(switch=sw, id=i)
print("Vsan ID\tName\tState")
for v in vsan:
	v.create()  # creates vsan on switch
	print(str(v.id)+"\t\t"+v.name+"\t"+v.state) # print id,name,state	
	v.delete()  # deletes vsan
Exemplo n.º 6
0
from mdslib.switch import Switch
from mdslib.vsan import Vsan

# Lets set the basic switch inputs
user = '******'
pw = 'nbv!2345'
ipaddr = '10.126.94.104'
port = 8443

# ######################################################
# ############# SWITCH SECTION #########################
# Initialize the switch object
sw = Switch(ip_address=ipaddr,
            username=user,
            password=pw,
            connection_type='https',
            port=port,
            timeout=30,
            verify_ssl=False)
cmd = "show hardware internal errors all "
try:
    out = sw.show(cmd, raw_text=False)
    print(out)
except Exception as e:
    print("EXCEPTION!!!")
    # print(e.args)
    out = sw.show(cmd, raw_text=False)
    print(out)

sshcode = """
def ssh():
Exemplo n.º 7
0
from mdslib.vsan import Vsan
from mdslib.fc import Fc
from mdslib.portchannel import PortChannel
from mdslib.devicealias import DeviceAlias

# Switch credentials
user = '******'
pw = 'yourswitchpassword'
ip_address = 'yourswitchip'  # 10.197.155.110
p = 8443

# Creating switch object
sw = Switch(ip_address=ip_address,
            username=user,
            password=pw,
            connection_type='https',
            port=p,
            timeout=30,
            verify_ssl=False)

# Instantiating Vsan object with id 2
v = Vsan(sw, 2)

# Creating vsan
v.create()

# Creating Fc object for interface fc1/3
int13 = Fc(sw, "fc1/3")

# Instantiating PortChannel object 1
pc1 = PortChannel(sw, 1)
Exemplo n.º 8
0
    def discover_all_switches_in_fabric(self,
                                        seed_switch_ip,
                                        username,
                                        password,
                                        connection_type='https',
                                        port=8443,
                                        timeout=30,
                                        verify_ssl=True,
                                        discover_npv=True):
        """
        Discover all the switches in the fabric using the seed switch ip

        :param seed_switch_ip: Seed switch ip that needs to be used to discover the fabric
        :type seed_switch_ip: list
        :param username: username of the switches
        :type username: str
        :param password: password of the switches
        :type password: str
        :param connection_type: type of the connection http or https default is https
        :type connection_type:str
        :param port: http or https port, default is 8443
        :type port:int
        :param timeout: connection or command timeout in secs, default is 30s
        :type timeout:int
        :param verify_ssl: Default is True, please set it to False if there is no SSL defined between the switches and the host
        :type verify_ssl:bool
        :param discover_npv: discover NPV switches in the fabric, default us True
        :type discover_npv: bool
        :return: Returns True if discovery is successful
        :rtype: bool
        """
        discovered_switches = {}
        log.info(
            "Discovering all switches in the fabric with the seed switch : " +
            seed_switch_ip)
        swobj = Switch(seed_switch_ip,
                       username=username,
                       password=password,
                       connection_type=connection_type,
                       port=port,
                       timeout=timeout,
                       verify_ssl=verify_ssl)

        if swobj.can_connect:
            discovered_switches[swobj.ipaddr] = swobj
        else:
            msg = "ERROR!! Unable to connect to the seed switch : " + swobj.ipaddr + \
                  " via " + swobj.connectiontype + " with port " + str(
                swobj.port) + " . Make sure that NXAPI is enabled."
            log.error(msg)
            return False

        if (swobj.is_npv_switch()):
            log.error(
                "The seed switch({0}) is a NPV switch, please provide a NPIV switch as seed switch to discover the entire fabric"
                .format(swobj.ipaddr))
            return False

        peer_switches = swobj.get_peer_switches()
        # print(peer_switches)

        i = 0
        while i < len(peer_switches):
            each_ip = peer_switches[i]
            i = i + 1
            # for each_ip in peer_switches:
            if each_ip in discovered_switches.keys():
                continue
            else:
                # print(discovered_switches)
                swobj = Switch(each_ip,
                               username=username,
                               password=password,
                               connection_type=connection_type,
                               port=port,
                               timeout=timeout,
                               verify_ssl=verify_ssl)

                if swobj.can_connect:
                    discovered_switches[swobj.ipaddr] = swobj
                    peers = swobj.get_peer_switches()
                    peer_switches = peer_switches + peers
                else:
                    msg = "ERROR!! Unable to connect to the switch : " + swobj.ipaddr + \
                          " via " + swobj.connectiontype + " with port " + str(
                        port) + " . Make sure that NXAPI is enabled."
                    log.debug(msg)

        # print(discovered_switches)

        if discover_npv:
            allswlist = list(discovered_switches.keys())
            for swobj in discovered_switches.values():
                allswlist = allswlist + swobj.get_peer_npv_switches()
            allswlist = list(dict.fromkeys(allswlist))
            for eachswip in allswlist:
                if eachswip not in discovered_switches.keys():
                    swobj = Switch(eachswip,
                                   username=username,
                                   password=password,
                                   connection_type=connection_type,
                                   port=port,
                                   timeout=timeout,
                                   verify_ssl=verify_ssl)
                    if swobj.can_connect:
                        discovered_switches[swobj.ipaddr] = swobj
                    else:
                        msg = "ERROR!! Unable to connect to the seed switch : " + swobj.ipaddr + \
                              " via " + swobj.connectiontype + " with port " + str(
                            port) + " . Make sure that NXAPI is enabled."
                        log.debug(msg)

        self.discovered_switches = discovered_switches
        return True