コード例 #1
0
    def test_error_and_warning_count_on_file_v10(self):
        set_update_count()
        f5_conv(bigip_config_file=setup.get('config_file_name_v10'),
                f5_config_version=setup.get('file_version_v10'),
                controller_version=setup.get('controller_version_v17'),
                output_file_path=setup.get('output_file_path'))

        assert get_count('error') == 0
        assert get_count('warning') == 0
コード例 #2
0
    def test_error_and_warning_count(self):
        set_update_count()
        netscaler_conv(config_file_name=setup.get('config_file_name'),
                       tenant=file_attribute['tenant'],
                       cloud_name=file_attribute['cloud_name'],
                       output_file_path=setup.get('output_file_path'),
                       controller_version=setup.get('controller_version_v17'))

        assert get_count('error') == 0
        assert get_count('warning') == 5
コード例 #3
0
ファイル: test_migrationtool.py プロジェクト: avinetworks/sdk
    def test_error_and_warning_count(self):
        set_update_count()
        netscaler_conv(config_file_name=setup.get('config_file_name'),
                       tenant=file_attribute['tenant'],
                       cloud_name=file_attribute['cloud_name'],
                       output_file_path=setup.get('output_file_path'),
                       controller_version=setup.get('controller_version_v17'))

        assert get_count('error') == 0
        assert get_count('warning') == 5
コード例 #4
0
    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')
コード例 #5
0
ファイル: f5_converter.py プロジェクト: avinetworks/sdk
    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')
コード例 #6
0
                        help='Enable test vip for ansible generated file '
                        'It will replace the original vip '
                        'Note: The actual ip will vary from input to output'
                        'use it with caution ')
    parser.add_argument('-u', '--user',
                        help='controller username for auto upload',
                        default='admin')
    parser.add_argument('--version',
                        help='Print product version and exit',
                        action='store_true')
    # Support for vrf and segroups
    parser.add_argument('--vrf',
                        help='Update the available vrf ref with the custom vrf'
                             'reference')
    # Added command line args to execute vs_filter.py with vs_name.
    parser.add_argument('--vs_filter', help='comma seperated names of '
                                            'virtualservices')
    parser.add_argument('--vs_level_status', action='store_true',
                        help='Add columns of vs reference and overall skipped '
                             'settings in status excel sheet')

    args = parser.parse_args()
    netscaler_converter = NetscalerConverter(args)
    # print avi netscaler converter version
    if args.version:
        netscaler_converter.print_pip_and_controller_version()
        exit(0)
    netscaler_converter.convert()
    print "Total Warning: ", get_count('warning')
    print "Total Errors: ", get_count('error')