def copy_folder(site_configs): for site_config in site_configs: #copying site config source_path = site_config.base_dir + site_config.site + "FINAL/" source_file_osw = source_path + site_config.switch + "VCE.txt" source_file_vsw = source_path + site_config.switch + "VSW.txt" source_path = site_config.base_dir + site_config.site + "DATA_SRC/CFG/" source_file_vpe = source_path + site_config.vpe_router + ".txt" dest_path = site_config.base_dir + site_config.site + "AID/" dest_file_osw = dest_path + site_config.switch + "VCE.txt" dest_file_vsw = dest_path + site_config.switch + "VSW.txt" dest_file_vpe = dest_path + site_config.vpe_router + ".txt" for dest_file, source_file in zip([dest_file_osw, dest_file_vsw, dest_file_vpe], [source_file_osw, source_file_vsw, source_file_vpe]): if exists(dest_file): print(dest_file + " already exists.") else: print("Copying " + dest_file) copy_file(source_file, dest_file, dest_path) for site_config in site_configs: #copying site config source_path = site_config.base_dir + site_config.site + "FINAL/" source_file_osw = source_path + site_config.switch + "VCE_addendum.txt" source_file_vsw = source_path + site_config.switch + "VPE_addendum.txt" dest_path = site_config.base_dir + site_config.site + "AID/" dest_file_osw = dest_path + site_config.switch + "VCE_addendum.txt" dest_file_vsw = dest_path + site_config.switch + "VPE_addendum.txt" for dest_file, source_file in zip([dest_file_osw, dest_file_vsw], [source_file_osw, source_file_vsw]): if exists(dest_file): print(dest_file + " already exists.") else: print("Copying " + dest_file) copy_file(source_file, dest_file, dest_path)
def check_cfg(box_config): credentials = open_file( os.path.dirname(os.path.realpath(__file__)) + "/pass.json") if not exists(box_config.conf_dest_path[1] + box_config.switch + '.txt'): print("Config file is about to be downloaded in " + box_config.conf_dest_path[1] + box_config.switch + '.txt' + ".") save_command = Get_Command(credentials, box_config) id = save_command.get_deviceID_osw() save_command.set_deviceID_osw(id) output_command = save_command.get_running_conf_osw() # replace vlan 4093 with 4000 output_command = replace_vlan4093(output_command, box_config) for box in box_config.conf_dest_path: save_result(output_command, box, box_config.switch) print("Config file has been downloaded for " + box_config.switch + ".") if exists(box_config.conf_dest_path[1] + box_config.switch + '.txt'): print("Config file is already in place in " + box_config.conf_dest_path[1] + box_config.switch + '.txt' + ".") if not exists(box_config.conf_dest_path[0] + box_config.switch + ".txt"): # copies the file in Stage1 folder source = box_config.conf_dest_path[1] + box_config.switch + ".txt" dest = box_config.conf_dest_path[0] + box_config.switch + ".txt" shutil.copy(source, dest) print("-> Copied in " + box_config.conf_dest_path[1] + box_config.switch + '.txt' + ".") ############VPE if not exists(box_config.conf_dest_path[1] + box_config.vpe_router + '.txt'): print("Config file is about to be downloaded in " + box_config.conf_dest_path[1] + box_config.vpe_router + '.txt' + ".") save_command = Get_Command(credentials, box_config) id = save_command.get_deviceID_vpe() save_command.set_deviceID_vpe(id) output_command = save_command.get_running_conf_vpe() #copies only in DATA_SRC/CFG for box in box_config.conf_dest_path: save_result(output_command, box_config.conf_dest_path[1], box_config.vpe_router) print("Config file has been downloaded for " + box_config.vpe_router + ".") else: print("Config file is already in place in " + box_config.conf_dest_path[1] + box_config.vpe_router + '.txt' + ".")
def get_command(site_configs): cmd_list = [ 'show spanning-tree bridge address', 'show spanning-tree root brief', 'show interface description', 'show interface po1 trunk', 'show interface po10 trunk', 'show interface po100 trunk', 'show spanning-tree bridge address', 'show spanning-tree root brief', 'show standby brief', 'show vlan brief', 'show vrrp brief', ] credentials = open_file( os.path.dirname(os.path.realpath(__file__)) + "/pass.json") for box_config in site_configs: base_dir = box_config.base_dir + box_config.site check_cfg(box_config) for cmd in cmd_list: if not exists(base_dir + "DATA_SRC/CMD/" + box_config.switch + '_' + cmd.replace(' ', '_') + '.txt'): print(box_config.switch + "_" + cmd.replace(' ', '_') + ".txt" + " file is about to be downloaded in " + base_dir + "DATA_SRC/CMD/") save_command = Get_Command(credentials, box_config) id = save_command.get_deviceID() save_command.set_deviceID(id) output_command = save_command.get_cmd(cmd) #replace vlan 4093 with 4000 output_command = output_command.replace('4093', '4000') save_result(output_command, base_dir + "DATA_SRC/CMD/", box_config.switch + '_' + cmd.replace(' ', '_')) print(box_config.switch + "_" + cmd.replace(' ', '_') + ".txt" + " file has been downloaded for " + box_config.switch + ".") elif exists(base_dir + "DATA_SRC/CMD/" + box_config.switch + '_' + cmd.replace(' ', '_') + '.txt'): print(box_config.switch + "_" + cmd.replace(' ', '_') + ".txt" + " file is already in place in " + base_dir + "DATA_SRC/CMD/")
def copy_file(source_file, dest_file, dest_path): import shutil if not exists(source_file): print("File " + source_file + ".txt is missing. \nPlease create it.") exit(0) create_dir(dest_path) shutil.copy(source_file, dest_file)
def get_config(site_configs): import shutil credentials = open_file( os.path.dirname(os.path.realpath(__file__)) + "/pass.json") for box_config in site_configs: #it only checks if file exists in DATA_SRC folder if not exists(box_config.conf_dest_path[1] + box_config.switch + '.txt'): print("Config file is about to be downloaded in " + box_config.conf_dest_path[1] + box_config.switch + '.txt' + ".") save_command = Get_Command(credentials, box_config) id = save_command.get_deviceID() save_command.set_deviceID(id) command = save_command.get_running_conf() for box in box_config.conf_dest_path: save_result(command, box, box_config.switch) print("Config file has been downloaded for " + box_config.switch + ".") else: print("Config file is already in place in " + box_config.conf_dest_path[1] + box_config.switch + '.txt' + ".") # copies the file in Stage1 folder source = box_config.conf_dest_path[1] + box_config.switch + ".txt" dest = box_config.conf_dest_path[0] + box_config.switch + ".txt" shutil.copy(source, dest) print("-> Copied in " + box_config.conf_dest_path[1] + box_config.switch + '.txt' + ".")
def create_folder(site_configs): for site_config in site_configs: source_path = site_config.base_dir + site_config.site + "/DATA_SRC/XLS/OUTPUT_STAGE_1.5/" if not exists(source_path + site_config.switch + "_checked_v" + str(site_config.checked_version) + ".0_OUT_DB_OPT.XLSX"): print("File " + source_path + site_config.switch + "_checked_v" + str(site_config.checked_version) + ".0_OUT_DB_OPT.XLSX" + " is missing.\nPlease create it.") exit(0) dest_path = site_config.base_dir + site_config.site + site_config.switch + "/Stage_2/" copy_file(site_config, source_path, dest_path)
def copy_folder(site_configs): for site_config in site_configs: #copying site config source_path = site_config.base_dir + site_config.site + "/DATA_SRC/CFG/" source_file = source_path + site_config.switch + ".txt" dest_path = site_config.base_dir + site_config.site + site_config.switch + "/Stage_3/" dest_file = dest_path + site_config.switch + ".txt" if exists(dest_file): print(dest_file + " already exists.") else: print("Copying " + dest_file) copy_file(source_file, dest_file, dest_path) #copying xls config source_path = site_config.base_dir + site_config.site + "/DATA_SRC/XLS/OUTPUT_STAGE_2.0/" source_file = source_path + site_config.switch + "_OUT_DB_OPT.xlsx" dest_path = site_config.base_dir + site_config.site + site_config.switch + "/Stage_3/" dest_file = dest_path + site_config.switch + "_OUT_DB_OPT.xlsx" if exists(dest_file): print(dest_path + " already exists.") else: print("Copying " + dest_file) copy_file(source_file, dest_file, dest_path)