import logging logging.basicConfig( filename='test_switch.log', filemode='w', level=logging.DEBUG, format="[%(asctime)s] [%(module)-14.14s] [%(levelname)-5.5s] %(message)s") import json with open('../switch_details.json', 'r') as j: data = json.load(j) sw = Switch(ip_address=data['ip_address'], username=data['username'], password=data['password'], connection_type=data['connection_type'], port=data['port'], timeout=data['timeout'], verify_ssl=False) import sys sys.stdout = open('test_switch_output.txt', 'wt') from tests.test_switch.test_switchshow import * TestSwitchShow.switch = sw TestSwitchShow.commands = "show vsan usage" from tests.test_switch.test_switchshowlist import * TestSwitchShowList.switch = sw TestSwitchShowList.commands = ["show vsan usage", "show module"]
logConsoleFormatter = logging.Formatter( "[%(asctime)s] %(message)s" ) logging.getLogger("paramiko").setLevel(logging.WARNING) # Add stdout handler, with level INFO console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(logConsoleFormatter) logging.getLogger().addHandler(console) from mdssdk.switch import Switch from mdssdk.switch import Switch import time from mdssdk.vsan import Vsan sw = Switch("10.197.106.40", "admin", "nbv_!2345", verify_ssl=False, connection_type="https", port="8443") print(sw.version) print("--------") print(sw.form_factor) # sw.feature("analytics",enable=True)8 # out = sw.feature("analytics") # print(out) # e = Vsan(sw,200) # # e.create("SDK vsan") # # print (e.name) # print (e.id) #
from mdssdk.switch import Switch from mdssdk.devicealias import DeviceAlias user = "******" pw = "yourswitchpassword" ip_address = "yourswitchip" # 10.197.155.110 p = 8443 # Set connection_type='https' for NXAPI # Set connection_type='ssh' for SSH sw = Switch( ip_address=ip_address, username=user, password=pw, connection_type="https", port=p, timeout=30, verify_ssl=False, ) # Instantiating DeviceAlias object d = DeviceAlias(sw) # Display the database, mode, distribute, locked print("Device Alias Database") print(d.database) print("Mode : " + d.mode) print("Distribute : " + str(d.distribute)) print("Locked : " + str(d.locked)) old = d.database
from mdssdk.switch import Switch user = "******" pw = "yourswitchpassword" ip_address = "yourswitchip" # 10.197.155.110 p = 8443 # Set connection_type='https' for NXAPI # Set connection_type='ssh' for SSH switch_obj = Switch( ip_address=ip_address, username=user, password=pw, connection_type="https", port=p, timeout=30, verify_ssl=False, ) # Displaying switch name, version, image print("Name: " + switch_obj.name) print("Version: " + switch_obj.version) print("Kickstart Image: " + switch_obj.kickstart_image) print("System Image: " + switch_obj.system_image) # Changing name of switch switch_obj.name = "switch_test" print("Changed Name: " + switch_obj.name) # Enabling feature analytics switch_obj.feature("analytics", True)
from mdssdk.vsan import Vsan from mdssdk.zone import Zone from mdssdk.zoneset import ZoneSet # 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
suiteList.append(MyTestLoader(sw).discover("tests.test_zone", "test_*.py")) suiteList.append( MyTestLoader(sw).discover("tests.test_zoneset", "test_*.py")) return suiteList for conntype in ["ssh", "https"]: with open("switch_details.json", "r+", encoding="utf-8") as f: data = json.load(f) print("\nRunning tests on '" + data["ip_address"] + "' with connection type '" + conntype + "'") log.info("Creating switch object") sw = Switch(ip_address=data["ip_address"], username=data["username"], password=data["password"], connection_type=conntype, port=data["port"], timeout=data["timeout"], verify_ssl=False) log.info("Connection type for switch object is " + sw.connection_type) comboSuite = unittest.TestSuite(get_suite_list(sw)) unittest.TextTestRunner( verbosity=2, failfast=True, resultclass=TimeLoggingTestResult).run(comboSuite) time.sleep(0.01) END = time.perf_counter() hours, rem = divmod(END - START, 3600) minutes, seconds = divmod(rem, 60) log.info("End of Tests (Took " + ( "{:0>1}h:{:0>1}m:{:02.1f}s".format(int(hours), int(minutes), seconds)) +
def runAnySwitchLogic(ip, user, pw, port): my_switch = Switch(ip, user, pw, "https", port=port, verify_ssl=False) status = isCFSoIpEnabled(my_switch) myData[my_switch.name] = status
scsi_target_io_profile = { "protocol": "scsi", "metrics": [], "view": "scsi_target_io" } scsi_initiator_io_profile = { "protocol": "scsi", "metrics": [], "view": "scsi_initiator_io", } sw = Switch( ip_address="10.126.94.184", username="******", password="******", connection_type="https", port=8443, timeout=30, verify_ssl=False, ) # sw.feature("analytics", True) analytics_object = sw.analytics analytics_object.create_query("scsi_target_io_profile", scsi_target_io_profile) show_scsi_initiator_query = analytics_object.show_query( "scsi_target_io_profile") analytics_object.delete_query("scsi_target_io_profile") analytics_object.create_query("port_query", port_scsi_profile) show_port_query = analytics_object.show_query("port_query") print("Checking Packet count") print(show_port_query) for item in show_port_query[0]: