class Resolve_Ver_Mismatch(threading.Thread): def __init__(self, net_device, true_of_version): threading.Thread.__init__(self) self.net_device = net_device self.true_of_version = true_of_version def run(self): self.net_connect = ConnectHandler(**self.net_device) self.net_connect.find_prompt() #Add true_of_version command = "sudo -S <<< 7654321 ovs-vsctl set bridge {} protocols={}".format( BRIDGE, self.true_of_version) output = self.net_connect.send_command_timing(command, strip_command=False, strip_prompt=False) print("Added Version: {}, Switch: {}".format(self.true_of_version, self.net_device['ip']))
class Resolve_Ctl_Misconfig(threading.Thread): def __init__(self, net_device, true_ctl_config): threading.Thread.__init__(self) self.net_device = net_device self.true_ctl_config = true_ctl_config def run(self): self.net_connect = ConnectHandler(**self.net_device) self.net_connect.find_prompt() #Remove false ctl config command = "sudo -S <<< 7654321 ovs-vsctl del-controller {}".format( BRIDGE) output = self.net_connect.send_command_timing(command, strip_command=False, strip_prompt=False) #Add true ctl config command = "sudo -S <<< 7654321 ovs-vsctl set-controller {} {}".format( BRIDGE, self.true_ctl_config) output = self.net_connect.send_command_timing(command, strip_command=False, strip_prompt=False)
class Check_Ctl_Connectivity(threading.Thread): def __init__(self, net_device): threading.Thread.__init__(self) self.net_device = net_device def run(self): self.net_connect = ConnectHandler(**self.net_device) self.net_connect.find_prompt() output = self.net_connect.send_command_timing( "sudo -S <<< 7654321 ovs-vsctl show | grep is_connected", strip_command=False, strip_prompt=False) output = output.split('\n')[1] if 'true' in output: connected_ovses.append(self.net_device['ip']) else: #disconnected_ovses.append(self.net_device['ip']) command = "sudo -S <<< 7654321 ovs-vsctl get-controller {}".format( BRIDGE) controller_config = self.net_connect.send_command_timing( command, strip_command=False, strip_prompt=False) controller_config = controller_config.split('\n')[1] of_ver = self.net_connect.send_command_timing( "sudo -S <<< 7654321 ovs-vsctl get bridge br0 protocols", strip_command=False, strip_prompt=False) of_ver = of_ver.split('\n')[1] of_versions = re.findall(r'OpenFlow\d+', of_ver) disconnected_ovses.append({ 'switch_mgmt_ip': self.net_device['ip'], 'controller_config': controller_config, 'of_versions': of_versions, })
import time from netmiko import redispatch from netmiko.ssh_dispatcher import ConnectHandler jumpserver = { 'device_type': 'terminal_server', 'ip': '10.108.16.104', 'username': '******', 'password': '******', # 'global_delay_factor':2 } print("Connecting %s" % jumpserver) net_connect = ConnectHandler(**jumpserver) print(net_connect.find_prompt()) filewrite = open("output1.txt", "a") file_obj = open("officeDevice.txt", "r") for line in file_obj: print("Connecting ***** %s" % line) net_connect.write_channel("mtrad " + line) time.sleep(1) net_connect.read_channel() redispatch(net_connect, device_type='cisco_ios_telnet') output = net_connect.send_command("show version | i IOS") output = net_connect.send_command("show mod | i 10GE") print(output) net_connect.send_command("exit", expect_string="mobboss2")