def main(): args = parse_arguments() backup_config_linux_path = convert_ios_path_to_linux( BACKUP_CONFIG_IOS_PATH) if args.check_only: checks() # check if the current running config backup is saved on the flash elif not os.path.isfile(backup_config_linux_path): # if not, save it and exit save_config_to_ios_file(BACKUP_CONFIG_IOS_PATH, args.syslog) message = 'Running-config file is saved for the first time, exiting.' print(message) if args.syslog: send_syslog(message) # not running for the first time, starting checks else: try: checks(args.syslog) except AssertionError: message = 'Trying configuration rollback' print(message) if args.syslog: send_syslog(message) clip('configure replace {config_path} force'.format( config_path=BACKUP_CONFIG_IOS_PATH)) else: save_config_to_ios_file(BACKUP_CONFIG_IOS_PATH, args.syslog)
def show_set(): set_mon = 'Y' set_mon = raw_input("설정된 스케줄러를 확인하시겠습니까?[Y]") if set_mon == 'y' or set_mon == 'Y' or set_mon == '': clip('show scheduler schedule')
#!/bin/env python #-*- coding: utf-8 -*- from cli import cli, clip def eem_conf(interface): syslog_var1 = "configure terminal ; event manager applet Auto-Provisioning ;" syslog_var2 = "event syslog pattern 'Interface Ethernet%s is up in mode access'" % interface syslog_var_pattern = syslog_var1 + syslog_var2 cli(syslog_var_pattern) cli("configure terminal ; event manager applet Auto-Provisioning ; \ action 1.0 syslog priority notifications msg Run_Python_Auto_Provisioning" ) cli("configure terminal ; event manager applet Auto-Provisioning ; \ action 2.0 cli python bootflash:scripts/auto_provisioning.py") cli("configure terminal ; event manager applet Auto-Provisioning ; \ action 3.0 syslog priority notifications msg Finish_Python_Auto_Provisioning" ) if __name__ == "__main__": interface = '1/24' interface = raw_input("어떤 인터페이스로 nxos 이미지를 내려받으시겠습니까?[1/24]") if interface == '': interface = '1/24' eem_conf(interface) clip("show running-config eem")
output = cli("configure terminal ; interface gigabitEthernet 0/0 ; no shutdown") Args: command (str): The exec or config CLI command(s) to be run. Returns: string: CLI output for show commands and an empty string for configuration commands. Raises: errors.cli_syntax_error: if the command is not valid. errors.cli_exec_error: if the execution of command is not successful. help(clip) Help on function clip in module cli: clip(command) Execute Cisco IOS CLI command(s) and print the result. A single command or a delimited batch of commands may be run. The delimiter is a space and a semicolon, " ;". Configuration commands must be in fully qualified form. clip("show version") clip("show version ; show ip interface brief") clip("configure terminal ; interface gigabitEthernet 0/0 ; no shutdown") Args: command (str): The exec or config CLI command(s) to be run.
if not arg['virtualmachines']: print('\n') print('Hypervisor' + '\t\t\t' + 'Connected Port' + '\t\t\t' + 'IP address' + '\t\t\t' + 'Neighbor Type' + '\t\t\t' + 'Local Port') print( '--------------------------------------------------------------------------------------------------------------------------------------------------' ) if arg['virtualmachines']: key_y = raw_input( "\nBefore continue, please, copy public key to your hypervisors. Or you will need to enter password.Show pubkey?(y/n)" ) if key_y.startswith('y'): print('\n') get_pub_key = 'run bash cat /var/home/admin/.ssh/id_rsa.pub' cli.clip(get_pub_key) else: print('\n') print('\n') print('VM Name' + '\t\t\t\t\t\t' + 'VM UUID' + '\t\t\t\t\t\t' + 'Hypervisor' + '\t\t\t' + 'Local Port') print( '-------------------------------------------------------------------------------------------------------------------------------------------------' ) if (protocheck == 4) or (arg['cdp']): if arg['virtualmachines']: cdpneigh() else: cdpneigh() elif (protocheck == 1) or (arg['lldp']): if arg['virtualmachines']:
cli.configurep([ "interface " + intf, "ip address 10.55.55.55 255.255.255.0", "no shut", "end" ]) print("\nConfiguring interface %s with 'configure' function...\n") % intf cmd = 'interface %s,logging event link-status,end' % intf cli.configure(cmd.split(',')) print("Printing show command output with 'executep' function...\n") cli.executep('show ip interface brief') print("\nPrinting show command with 'execute' function...\n") output = cli.execute('show run interface %s' % intf) print(output) print("\nConfiguring interface %s with 'cli' function...\n" % intf) cli.cli( 'config terminal; interface %s; description Configured with a Python script from Guest Shell' % intf) print("Printing show command with 'clip' function...") cli.clip('show run interface %s' % intf)
if arg['cdp'] or arg['lldp'] or arg['all'] or arg['virtualmachines']: if arg['all']: deviceinfo() protocheck = protocol_check() #print protocheck if not arg['virtualmachines']: print ('\n') print ('Hypervisor' +'\t\t\t' + 'Connected Port' + '\t\t\t' + 'IP address' + '\t\t\t' + 'Neighbor Type' + '\t\t\t' + 'Local Port') print ('--------------------------------------------------------------------------------------------------------------------------------------------------') if arg['virtualmachines']: key_y = raw_input("\nBefore continue, please, copy public key to your hypervisors. Or you will need to enter password.Show pubkey?(y/n)") if key_y.startswith('y'): print ('\n') get_pub_key = 'run bash cat /var/home/admin/.ssh/id_rsa.pub' cli.clip(get_pub_key) else: print ('\n') print ('\n') print ('VM Name' +'\t\t\t\t\t\t' + 'VM UUID' + '\t\t\t\t\t\t' + 'Hypervisor' + '\t\t\t' + 'Local Port') print ('-------------------------------------------------------------------------------------------------------------------------------------------------') if (protocheck == 4) or (arg['cdp']): if arg['virtualmachines']: cdpneigh() else: cdpneigh() elif (protocheck == 1) or (arg['lldp']): if arg['virtualmachines']: lldpneigh() else: lldpneigh()
x = cli.configure(bootsys_cmds) cli.executep("write mem") with open("/bootflash/{}.log".format(sn), "a") as f: for i in range(len(qc_str)): f.write("#############START OF SEGMENT##############\n") f.write("") f.write(qc_str[i]) f.write("") f.write("#############END OF SEGMENT##############\n") with open("/bootflash/{}.log".format(sn), "a") as f: for i in range(len(upgr_qc)): f.write("#############START OF SEGMENT##############\n") f.write("") f.write(upgr_qc[i]) f.write("") f.write("#############END OF SEGMENT##############\n") with open("/bootflash/{}.log".format(sn), "a") as f: f.write("#############START OF SEGMENT##############\n") f.write("") f.write(x) f.write("") f.write("#############END OF SEGMENT##############\n") cli.clip("copy bootflash:{}.log usb0: ; \n".format(sn))