def test_config_conversion(self): dir_path = os.path.abspath(os.path.dirname(__file__)) dir_path = dir_path.rsplit(os.path.sep, 1)[0] f5_config_dict = f5_parser.parse_config(gSAMPLE_CONFIG, 10) defaults_file = open(dir_path+os.path.sep+"f5_v10_defaults.conf", "r") f5_defaults_dict = f5_parser.parse_config(defaults_file.read(), 10) f5_converter.dict_merge(f5_defaults_dict, f5_config_dict) f5_config_dict = f5_defaults_dict assert f5_config_dict.get("virtual", False) assert f5_config_dict.get("monitor", False) assert f5_config_dict.get("pool", False) assert f5_config_dict.get("profile", False) assert f5_config_dict.get("node", False) avi_config_dict = f5_config_converter.convert( f5_config_dict, dir_path+os.path.sep+"output", "disable", "certs", '10') assert avi_config_dict with open('%s%soutput%sConversionStatus.csv' % (dir_path, os.path.sep, os.path.sep)) as csvfile: reader = csv.DictReader(csvfile) for row in reader: assert row['Status'] != 'error'
def test_config_conversion(self): dir_path = os.path.abspath(os.path.dirname(__file__)) dir_path = dir_path.rsplit(os.path.sep, 1)[0] f5_config_dict = f5_parser.parse_config(gSAMPLE_CONFIG, 11) defaults_file = open(dir_path + os.path.sep + "f5_v11_defaults.conf", "r") f5_defaults_dict = f5_parser.parse_config(defaults_file.read(), 11) f5_converter.dict_merge(f5_defaults_dict, f5_config_dict) f5_config_dict = f5_defaults_dict assert f5_config_dict.get("virtual", None) assert f5_config_dict.get("monitor", None) assert f5_config_dict.get("pool", None) assert f5_config_dict.get("profile", None) assert f5_config_dict.get("node", None) avi_config_dict = f5_config_converter.convert( f5_config_dict, dir_path + os.path.sep + "output", "disable", "certs", '11') assert avi_config_dict with open('%s%soutput%sConversionStatus.csv' % (dir_path, os.path.sep, os.path.sep)) as csvfile: reader = csv.DictReader(csvfile) for row in reader: assert row['Status'] != '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 = 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() 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)