Esempio n. 1
0
    def test_lb_algorithm_match(self):
        set_update_count()
        ns_config = get_ns_conf_dict(setup.get('config_file_name'))[0]
        netscaler_conv(config_file_name=setup.get('config_file_name'),
                       tenant=file_attribute['tenant'],
                       output_file_path=setup.get('output_file_path'),
                       controller_version=setup.get('controller_version_v17'))
        
        output_file = '%s/ns-Output.json' %setup.get('output_file_path')

        with open(output_file, 'r') as file_strem:
            avi_config = json.load(file_strem)
            lb_vs_conf = ns_config.get('add lb vserver', {})
            for vs_name in lb_vs_conf.keys():
                pg_name = '%s-poolgroup' % vs_name
                pg_obj = [pg for pg in avi_config['PoolGroup'] if
                          pg['name'] == pg_name]
                if not pg_obj:
                    continue
                pg_obj = pg_obj[0]
                ns_util = NsUtil()
                ns_algo = lb_vs_conf[vs_name].get(
                    'lbMethod', 'LEASTCONNECTIONS')
                algo = ns_util.get_avi_lb_algorithm(ns_algo)
                for member in pg_obj['members']:
                    pool_name = ns_util.get_name(member['pool_ref'])
                    pool = [pool for pool in avi_config['Pool'] if
                            pool['name'] == pool_name][0]
                    assert pool['lb_algorithm'] == algo
Esempio n. 2
0
    def test_lb_algorithm_match(self):
        set_update_count()
        ns_config = get_ns_conf_dict(setup.get('config_file_name'))[0]
        netscaler_conv(config_file_name=setup.get('config_file_name'),
                       tenant=file_attribute['tenant'],
                       output_file_path=setup.get('output_file_path'),
                       controller_version=setup.get('controller_version_v17'))

        with open('./output/ns-Output.json', 'r') as file_strem:
            avi_config = json.load(file_strem)
            lb_vs_conf = ns_config.get('add lb vserver', {})
            for vs_name in lb_vs_conf.keys():
                pg_name = '%s-poolgroup' % vs_name
                pg_obj = [pg for pg in avi_config['PoolGroup'] if
                          pg['name'] == pg_name]
                if not pg_obj:
                    continue
                pg_obj = pg_obj[0]
                ns_util = NsUtil()
                ns_algo = lb_vs_conf[vs_name].get(
                    'lbMethod', 'LEASTCONNECTIONS')
                algo = ns_util.get_avi_lb_algorithm(ns_algo)
                for member in pg_obj['members']:
                    pool_name = ns_util.get_name(member['pool_ref'])
                    pool = [pool for pool in avi_config['Pool'] if
                            pool['name'] == pool_name][0]
                    assert pool['lb_algorithm'] == algo
Esempio n. 3
0
    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
Esempio n. 4
0
    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)
        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(output_dir, self.ns_host_ip,
                                       self.ns_ssh_user, self.ns_ssh_password)
            LOG.debug("Copied input files")
            source_file = output_dir + os.path.sep + "ns.conf"
        else:
            source_file = self.ns_config_file
        report_name = os.path.splitext(os.path.basename(source_file))[0]
        gslb_ns_config = dict()
        ns_config, skipped_cmds = ns_parser.get_ns_conf_dict(source_file)
        gslb_ns_config['add gslb service'] = ns_config.get('add gslb service')
        gslb_ns_config['add gslb vserver'] = ns_config.get('add gslb vserver')
        gslb_ns_config['bind gslb vserver'] = ns_config.get('bind gslb vserver')
        gslb_ns_config['add server'] = ns_config.get('add server')
        print gslb_ns_config
        # getting meta tag from superclass
        meta = self.meta(self.tenant, self.controller_version)
        avi_gslb_config = gslb_config_converter.convert(
            meta, gslb_ns_config, self.controller_ip, self.user, self.password,
            self.tenant, self.vs_state, self.output_file_path, self.version,
            report_name, self.vs_level_status)
        self.write_output(
            avi_gslb_config, output_dir, '%s-Output.json' % report_name)
Esempio n. 6
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)
        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(output_dir, self.ns_host_ip,
                                       self.ns_ssh_user, self.ns_ssh_password)
            LOG.debug("Copied input files")
            source_file = output_dir + os.path.sep + "ns.conf"
        else:
            source_file = self.ns_config_file
        report_name = os.path.splitext(os.path.basename(source_file))[0]
        gslb_ns_config = dict()
        ns_config, skipped_cmds = ns_parser.get_ns_conf_dict(source_file)
        gslb_ns_config['add gslb service'] = ns_config.get('add gslb service')
        gslb_ns_config['add gslb vserver'] = ns_config.get('add gslb vserver')
        gslb_ns_config['bind gslb vserver'] = ns_config.get('bind gslb vserver')
        gslb_ns_config['add server'] = ns_config.get('add server')
        print(gslb_ns_config)
        # getting meta tag from superclass
        meta = self.meta(self.tenant, self.controller_version)
        avi_gslb_config = gslb_config_converter.convert(
            meta, gslb_ns_config, self.controller_ip, self.user, self.password,
            self.tenant, self.vs_state, self.output_file_path, self.version,
            report_name, self.vs_level_status)
        self.write_output(
            avi_gslb_config, output_dir, '%s-Output.json' % report_name)
Esempio n. 7
0
    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