def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() input_dir = os.path.normpath(self.input_folder_location) output_dir = os.path.normpath(self.output_file_path) is_download_from_host = False if self.ns_host_ip: input_dir = output_dir + os.path.sep + self.ns_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.ns_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True self.print_pip_and_controller_version() if is_download_from_host: LOG.debug("Copying files from host") scp_util.get_files_from_ns(input_dir, self.ns_host_ip, self.ns_ssh_user, self.ns_ssh_password) LOG.debug("Copied input files") source_file = input_dir + os.path.sep + "ns.conf" else: source_file = self.ns_config_file if not source_file: print 'Not found ns configuration file' return ns_config, skipped_cmds = ns_parser.get_ns_conf_dict(source_file) user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) # getting meta tag from superclass meta = self.meta(self.tenant, self.controller_version) report_name = os.path.splitext(os.path.basename(source_file))[0] avi_config = ns_conf_converter.convert( meta, ns_config, self.tenant, self.cloud_name, self.controller_version, output_dir, input_dir, skipped_cmds, self.vs_state, self.object_merge_check, report_name, self.prefix, self.profile_path, self.ns_passphrase_file, user_ignore) avi_config = self.process_for_utils( avi_config) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output( avi_config, output_dir, '%s-Output.json' % report_name) if self.option == 'auto-upload': self.upload_config_to_controller(avi_config) return avi_config
def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() input_dir = os.path.normpath(self.input_folder_location) output_dir = os.path.normpath(self.output_file_path) is_download_from_host = False if self.ns_host_ip: input_dir = output_dir + os.path.sep + self.ns_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.ns_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True self.print_pip_and_controller_version() if is_download_from_host: LOG.debug("Copying files from host") scp_util.get_files_from_ns(input_dir, self.ns_host_ip, self.ns_ssh_user, self.ns_ssh_password) LOG.debug("Copied input files") source_file = input_dir + os.path.sep + "ns.conf" else: source_file = self.ns_config_file if not source_file: print 'Not found ns configuration file' return ns_config, skipped_cmds = ns_parser.get_ns_conf_dict(source_file) user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) # getting meta tag from superclass meta = self.meta(self.tenant, self.controller_version) report_name = os.path.splitext(os.path.basename(source_file))[0] avi_config = ns_conf_converter.convert( meta, ns_config, self.tenant, self.cloud_name, self.controller_version, output_dir, input_dir, skipped_cmds, self.vs_state, self.object_merge_check, report_name, self.prefix, self.profile_path, self.ns_passphrase_file, user_ignore) avi_config = self.process_for_utils(avi_config) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output(avi_config, output_dir, '%s-Output.json' % report_name) if self.option == 'auto-upload': self.upload_config_to_controller(avi_config) return avi_config
def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() output_dir = os.path.normpath(self.output_file_path) input_dir = os.path.normpath(self.input_folder_location) is_download_from_host = False if self.f5_host_ip: input_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) custom_mappings = None if self.custom_config: with open(self.custom_config) as stream: custom_mappings = yaml.safe_load(stream) partitions = [] # Add logger and print avi f5 converter version self.print_pip_and_controller_version() if self.partition_config: partitions = self.partition_config.split(',') source_file = None if is_download_from_host: LOG.debug("Copying files from host") print "Copying Files from Host..." scp_util.get_files_from_f5(input_dir, self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password, None, self.f5_ssh_port) LOG.debug("Copied input files") source_file = open(input_dir + os.path.sep + "bigip.conf", "r") files = os.listdir(input_dir) for f in files: if f.endswith('_bigip.conf'): partitions.append(input_dir + os.path.sep + f) elif self.bigip_config_file: source_file = open(self.bigip_config_file, "r") if not source_file: print 'Not found F5 configuration file' return source_str = source_file.read() total_size = source_file.tell() LOG.debug('Parsing config file:' + source_file.name) print "Parsing Input Configuration..." f5_config_dict, not_supported_list = f5_parser.parse_config( source_str, total_size, self.f5_config_version) LOG.debug('Config file %s parsed successfully' % source_file.name) avi_config_dict = None LOG.debug('Parsing defaults files') f5_defaults_dict = self.get_default_config(is_download_from_host, input_dir) # Added to get not supported parse config not_supported_list_partition = [] if partitions: partition_conf = {} for partition in partitions: with open(partition, "r") as p_source_file: p_src_str = p_source_file.read() total_size = p_source_file.tell() LOG.debug('Parsing partition config file:' + p_source_file.name) print "Parsing Partitions Configuration..." partition_dict, not_supported_list = f5_parser.parse_config( p_src_str, total_size, self.f5_config_version) LOG.debug( 'Config file %s parsed successfully' % p_source_file.name) # TO get all not supported configuration. not_supported_list_partition = not_supported_list_partition \ + not_supported_list self.dict_merge(partition_conf, partition_dict) self.dict_merge(partition_conf, f5_config_dict) f5_config_dict = partition_conf # Added not supported parse config to file merged_not_supported_list = (not_supported_list + not_supported_list_partition) # Added status of all command that are not supported in parsing. for command in merged_not_supported_list: d = command.rsplit('/', 1) object_type = d[0].rsplit(' ', 1) object_name = '%s/%s' % (object_type[-1], d[-1]) self.conversion_util.add_status_row(object_type[0], '', object_name, conv_const.STATUS_NOT_SUPPORTED) LOG.debug('Defaults files parsed successfully') LOG.debug('Conversion started') self.dict_merge(f5_defaults_dict, f5_config_dict) f5_config_dict = f5_defaults_dict report_name = os.path.splitext(os.path.basename(source_file.name))[0] avi_config_dict, part_mapping = f5_config_converter.convert( f5_config_dict, output_dir, self.vs_state, input_dir, self.f5_config_version, self.object_merge_check, self.controller_version, report_name, self.prefix, self.con_snatpool, user_ignore, self.profile_path, self.tenant, self.cloud_name, self.f5_passphrase_file, self.vs_level_status, self.vrf, self.segroup, custom_mappings) avi_config = self.process_for_utils(avi_config_dict) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output(avi_config, output_dir, '%s-Output.json' % report_name) # Call to create ansible playbook if create ansible flag set. if self.create_ansible: avi_traffic = AviAnsibleConverterMigration( avi_config, output_dir, self.prefix, self.not_in_use, test_vip=self.test_vip, skip_types=self.ansible_skip_types, partitions=part_mapping, controller_version=self.controller_version) avi_traffic.write_ansible_playbook( self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password, 'f5') if self.option == 'auto-upload': self.upload_config_to_controller(avi_config) print "Total Warning: ", get_count('warning') print "Total Errors: ", get_count('error')
def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() output_dir = os.path.normpath(self.output_file_path) input_dir = os.path.normpath(self.input_folder_location) is_download_from_host = False if self.f5_host_ip: input_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) custom_mappings = None if self.custom_config: with open(self.custom_config) as stream: custom_mappings = yaml.safe_load(stream) partitions = [] # Add logger and print avi f5 converter version self.print_pip_and_controller_version() if self.partition_config: partitions = self.partition_config.split(',') source_file = None if is_download_from_host: LOG.debug("Copying files from host") print "Copying Files from Host..." scp_util.get_files_from_f5(input_dir, self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password, None, self.f5_ssh_port) LOG.debug("Copied input files") source_file = open(input_dir + os.path.sep + "bigip.conf", "r") files = os.listdir(input_dir) for f in files: if f.endswith('_bigip.conf'): partitions.append(input_dir + os.path.sep + f) elif self.bigip_config_file: source_file = open(self.bigip_config_file, "r") if not source_file: print 'Not found F5 configuration file' return source_str = source_file.read() total_size = source_file.tell() LOG.debug('Parsing config file:' + source_file.name) print "Parsing Input Configuration..." f5_config_dict, not_supported_list = f5_parser.parse_config( source_str, total_size, self.f5_config_version) LOG.debug('Config file %s parsed successfully' % source_file.name) avi_config_dict = None LOG.debug('Parsing defaults files') f5_defaults_dict = self.get_default_config(is_download_from_host, input_dir) # Added to get not supported parse config not_supported_list_partition = [] if partitions: partition_conf = {} for partition in partitions: with open(partition, "r") as p_source_file: p_src_str = p_source_file.read() total_size = p_source_file.tell() LOG.debug('Parsing partition config file:' + p_source_file.name) print "Parsing Partitions Configuration..." partition_dict, not_supported_list = f5_parser.parse_config( p_src_str, total_size, self.f5_config_version) LOG.debug( 'Config file %s parsed successfully' % p_source_file.name) # TO get all not supported configuration. not_supported_list_partition = not_supported_list_partition \ + not_supported_list self.dict_merge(partition_conf, partition_dict) self.dict_merge(partition_conf, f5_config_dict) f5_config_dict = partition_conf # Added not supported parse config to file merged_not_supported_list = (not_supported_list + not_supported_list_partition) # Added status of all command that are not supported in parsing. for command in merged_not_supported_list: d = command.rsplit('/', 1) object_type = d[0].rsplit(' ', 1) object_name = '%s/%s' % (object_type[-1], d[-1]) self.conversion_util.add_status_row(object_type[0], '', object_name, conv_const.STATUS_NOT_SUPPORTED) LOG.debug('Defaults files parsed successfully') LOG.debug('Conversion started') self.dict_merge(f5_defaults_dict, f5_config_dict) f5_config_dict = f5_defaults_dict report_name = os.path.splitext(os.path.basename(source_file.name))[0] avi_config_dict, part_mapping = f5_config_converter.convert( f5_config_dict, output_dir, self.vs_state, input_dir, self.f5_config_version, self.object_merge_check, self.controller_version, report_name, self.prefix, self.con_snatpool, user_ignore, self.profile_path, self.tenant, self.cloud_name, self.f5_passphrase_file, self.vs_level_status, self.vrf, self.segroup, custom_mappings) avi_config_dict["META"] = self.meta(self.tenant, self.controller_version) avi_config = self.process_for_utils(avi_config_dict) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output(avi_config, output_dir, '%s-Output.json' % report_name) # Call to create ansible playbook if create ansible flag set. if self.create_ansible: avi_traffic = AviAnsibleConverter( avi_config, output_dir, self.prefix, self.not_in_use, test_vip=self.test_vip, skip_types=self.ansible_skip_types, partitions=part_mapping) avi_traffic.write_ansible_playbook( self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password, 'f5') if self.option == 'auto-upload': self.upload_config_to_controller(avi_config) print "Total Warning: ", get_count('warning') print "Total Errors: ", get_count('error')
def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() input_dir = os.path.normpath(self.input_folder_location) output_dir = os.path.normpath(self.output_file_path) is_download_from_host = False if self.ns_host_ip: input_dir = output_dir + os.path.sep + self.ns_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.ns_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True self.print_pip_and_controller_version() # print the arguments in input LOG.info("Input parameters: %s" % ' '.join(sys.argv)) if is_download_from_host: LOG.debug("Copying files from host") print "Copying Files from Host..." scp_util.get_files_from_ns(input_dir, self.ns_host_ip, self.ns_ssh_user, self.ns_ssh_password) LOG.debug("Copied input files") source_file = input_dir + os.path.sep + "ns.conf" else: source_file = self.ns_config_file if not source_file: print 'Not found ns configuration file' return ns_config, skipped_cmds = ns_parser.get_ns_conf_dict(source_file) user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) # getting meta tag from superclass meta = self.meta(self.tenant, self.controller_version) report_name = os.path.splitext(os.path.basename(source_file))[0] # Added dict for collecting vs for netscaler. vs_name_dict = dict() vs_name_dict['csvs'] = dict() vs_name_dict['lbvs'] = dict() avi_config = ns_conf_converter.convert( meta, ns_config, self.tenant, self.cloud_name, self.controller_version, output_dir, input_dir, skipped_cmds, self.vs_state, self.object_merge_check, report_name, self.prefix, vs_name_dict, self.profile_path, self.redirect, self.ns_passphrase_file, user_ignore, self.vs_level_status, self.vrf, self.segroup) avi_config = self.process_for_utils( avi_config) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output( avi_config, output_dir, '%s-Output.json' % report_name) if self.create_ansible: avi_traffic = AviAnsibleConverter( avi_config, output_dir, self.prefix, self.not_in_use, ns_vs_name_dict=vs_name_dict, test_vip=self.test_vip, skip_types=self.ansible_skip_types) avi_traffic.write_ansible_playbook( self.ns_host_ip, self.ns_ssh_user, self.ns_ssh_password, 'netscaler' ) if self.option == 'auto-upload': self.upload_config_to_controller(avi_config) return avi_config
def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() output_dir = os.path.normpath(self.output_file_path) input_dir = os.path.normpath(self.input_folder_location) is_download_from_host = False if self.f5_host_ip: input_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) partitions = [] # Add logger and print avi f5 converter version self.print_pip_and_controller_version() if self.partition_config: partitions = self.partition_config.split(',') if is_download_from_host: LOG.debug("Copying files from host") scp_util.get_files_from_f5(input_dir, self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password) LOG.debug("Copied input files") source_file = open(input_dir + os.path.sep + "bigip.conf", "r") files = os.listdir(input_dir) for f in files: if f.endswith('_bigip.conf'): partitions.append(input_dir + os.path.sep + f) elif self.bigip_config_file: source_file = open(self.bigip_config_file, "r") if not source_file: print 'Not found ns configuration file' return source_str = source_file.read() LOG.debug('Parsing config file:' + source_file.name) f5_config_dict = f5_parser.parse_config(source_str, self.f5_config_version) LOG.debug('Config file %s parsed successfully' % source_file.name) avi_config_dict = None LOG.debug('Parsing defaults files') f5_defaults_dict = self.get_default_config(is_download_from_host, input_dir) if partitions: partition_conf = {} for partition in partitions: with open(partition, "r") as p_source_file: p_src_str = p_source_file.read() LOG.debug('Parsing partition config file:' + p_source_file.name) partition_dict = f5_parser.parse_config( p_src_str, self.f5_config_version) LOG.debug( 'Config file %s parsed successfully' % p_source_file.name) self.dict_merge(partition_conf, partition_dict) self.dict_merge(partition_conf, f5_config_dict) f5_config_dict = partition_conf LOG.debug('Defaults files parsed successfully') LOG.debug('Conversion started') self.dict_merge(f5_defaults_dict, f5_config_dict) f5_config_dict = f5_defaults_dict report_name = os.path.splitext(os.path.basename(source_file.name))[0] avi_config_dict = f5_config_converter.convert( f5_config_dict, output_dir, self.vs_state, input_dir, self.f5_config_version, self.object_merge_check, self.controller_version, report_name, self.prefix, self.con_snatpool, user_ignore, self.profile_path, self.tenant, self.cloud_name) avi_config_dict["META"] = self.meta(self.tenant, self.controller_version) if parse_version(self.controller_version) >= parse_version('17.1'): avi_config_dict['META']['supported_migrations']['versions'].append( '17_1_1') avi_config_dict['META']['supported_migrations']['versions'].append( 'current_version') avi_config = self.process_for_utils(avi_config_dict) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output(avi_config, output_dir, '%s-Output.json' % report_name) if self.create_ansible: avi_traffic = AviAnsibleConverter( avi_config, output_dir, self.prefix, self.not_in_use) avi_traffic.write_ansible_playbook( self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password) if self.option == 'auto-upload': self.upload_config_to_controller(avi_config)
def convert(self): if not os.path.exists(self.output_file_path): os.mkdir(self.output_file_path) self.init_logger_path() output_dir = os.path.normpath(self.output_file_path) input_dir = os.path.normpath(self.input_folder_location) is_download_from_host = False if self.f5_host_ip: input_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "input" if not os.path.exists(input_dir): os.makedirs(input_dir) output_dir = output_dir + os.path.sep + self.f5_host_ip + \ os.path.sep + "output" if not os.path.exists(output_dir): os.makedirs(output_dir) is_download_from_host = True user_ignore = {} # Read the attributes for user ignore val if self.ignore_config: with open(self.ignore_config) as stream: user_ignore = yaml.safe_load(stream) partitions = [] # Add logger and print avi f5 converter version self.print_pip_and_controller_version() if self.partition_config: partitions = self.partition_config.split(',') if is_download_from_host: LOG.debug("Copying files from host") scp_util.get_files_from_f5(input_dir, self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password) LOG.debug("Copied input files") source_file = open(input_dir + os.path.sep + "bigip.conf", "r") files = os.listdir(input_dir) for f in files: if f.endswith('_bigip.conf'): partitions.append(input_dir + os.path.sep + f) elif self.bigip_config_file: source_file = open(self.bigip_config_file, "r") if not source_file: print 'Not found ns configuration file' return source_str = source_file.read() LOG.debug('Parsing config file:' + source_file.name) f5_config_dict = f5_parser.parse_config(source_str, self.f5_config_version) LOG.debug('Config file %s parsed successfully' % source_file.name) avi_config_dict = None LOG.debug('Parsing defaults files') f5_defaults_dict = self.get_default_config(is_download_from_host, input_dir) if partitions: partition_conf = {} for partition in partitions: with open(partition, "r") as p_source_file: p_src_str = p_source_file.read() LOG.debug('Parsing partition config file:' + p_source_file.name) partition_dict = f5_parser.parse_config( p_src_str, self.f5_config_version) LOG.debug('Config file %s parsed successfully' % p_source_file.name) self.dict_merge(partition_conf, partition_dict) self.dict_merge(partition_conf, f5_config_dict) f5_config_dict = partition_conf LOG.debug('Defaults files parsed successfully') LOG.debug('Conversion started') self.dict_merge(f5_defaults_dict, f5_config_dict) f5_config_dict = f5_defaults_dict report_name = os.path.splitext(os.path.basename(source_file.name))[0] avi_config_dict = f5_config_converter.convert( f5_config_dict, output_dir, self.vs_state, input_dir, self.f5_config_version, self.object_merge_check, self.controller_version, report_name, self.prefix, self.con_snatpool, user_ignore, self.profile_path, self.tenant, self.cloud_name) avi_config_dict["META"] = self.meta(self.tenant, self.controller_version) if parse_version(self.controller_version) >= parse_version('17.1'): avi_config_dict['META']['supported_migrations']['versions'].append( '17_1_1') avi_config_dict['META']['supported_migrations']['versions'].append( 'current_version') avi_config = self.process_for_utils(avi_config_dict) # Check if flag true then skip not in use object if self.not_in_use: avi_config = wipe_out_not_in_use(avi_config) self.write_output(avi_config, output_dir, '%s-Output.json' % report_name) if self.create_ansible: avi_traffic = AviAnsibleConverter(avi_config, output_dir, self.prefix, self.not_in_use) avi_traffic.write_ansible_playbook(self.f5_host_ip, self.f5_ssh_user, self.f5_ssh_password) if self.option == 'auto-upload': self.upload_config_to_controller(avi_config)