Exemple #1
0
    def _confirm_spp(self, vars_file):
        yobj = yaml.load(open(vars_file))
        target_params = {'spp_ver': None}
        for param in target_params.keys():
            if param == 'spp_ver':
                if yobj[param] is None:
                    if self.di_conf["SPP_VER"] is None:
                        ver = ''
                    else:
                        ver = self.di_conf["SPP_VER"]
                    print("> use default SPP version '{}' ? [Y/n]".format(ver))
                    if sys.version_info.major == 2:
                        ans = raw_input().strip()
                    elif sys.version_info.major == 3:
                        ans = input().strip()
                    if ans == '':
                        ans = 'y'
                    if (ans.lower() == "n" or ans.lower() == "no" or
                            not (ans.lower() == "y" or ans.lower() == "yes")):
                        print(ans)
                        print("> input pktgen version, or empty for latest")
                        if sys.version_info.major == 2:
                            ans = raw_input().strip()
                        elif sys.version_info.major == 3:
                            ans = input().strip()
                        spp_ver = ans
                    else:
                        spp_ver = self.di_conf["SPP_VER"]

                    target_params[param] = spp_ver
                    make_utils.update_var(vars_file, param, spp_ver, False)
                else:
                    target_params[param] = yobj[param]
Exemple #2
0
    def clean_spp():
        """Clean params for SPP."""

        for dist in OS_DISTS:
            target_params = ["spp_ver"]
            vars_file = "group_vars/{}_spp".format(dist)
            for key in target_params:
                make_utils.update_var(vars_file, key, "", True)
                print("> clean '%s' in '%s'" % (key, vars_file))
Exemple #3
0
    def clean_pktgen():
        """Clean params for pktgen."""

        for dist in OS_DISTS:
            if not dist.startswith('centos'):
                target_params = ["pktgen_ver"]
                vars_file = "group_vars/{}_pktgen".format(dist)
                for key in target_params:
                    make_utils.update_var(vars_file, key, "", True)
                    print("> clean '%s' in '%s'" % (key, vars_file))
Exemple #4
0
    def clean_proxy():
        """Clean proxy environments."""
        target_params = ['http_proxy', 'https_proxy', 'no_proxy']

        # remove ssh user account form vars file.
        for dist in OS_DISTS:
            vars_file = "group_vars/{}_common".format(dist)
            for key in target_params:
                make_utils.update_var(vars_file, key, "", True)
                print("> clean '%s' in '%s'" % (key, vars_file))
Exemple #5
0
    def clean_dpdk():
        """Clean params for DPDK."""

        for dist in OS_DISTS:
            target_params = [
                "hugepage_size", "nr_hugepages", "dpdk_ver", "dpdk_target",
                "dpdk_interfaces"
            ]
            vars_file = "group_vars/{}_common".format(dist)
            for key in target_params:
                make_utils.update_var(vars_file, key, "", True)
                print("> clean '%s' in '%s'" % (key, vars_file))
Exemple #6
0
    def clean_account():
        """Clean username and password."""
        target_params = [
            "remote_user", "ansible_ssh_pass", "ansible_sudo_pass"
        ]

        # remove ssh user account form vars file.
        for dist in OS_DISTS:
            vars_file = "group_vars/{}_common".format(dist)
            for key in target_params:
                make_utils.update_var(vars_file, key, "", True)
                print("> clean '%s' in '%s'" % (key, vars_file))
Exemple #7
0
    def _confirm_dpdk(self, vars_file):
        """Check DPDK's params.

        Setup for hugepages and network interfaces defined in "group_vars/"
        by asking user some questions.

        It only asks for dpdk role and not others because all of
        vars are included in dpdk's var file. It's needed to be asked for
        other files if they include vars not included dpdk.
        """

        yobj = yaml.load(open(vars_file))
        if yobj is None:
            return None

        target_params = {
            'hugepage_size': None,
            'nr_hugepages': None,
            'dpdk_ver': None,
            'dpdk_target': None,
            'dpdk_interfaces': None
        }

        for param in target_params.keys():
            if param == 'hugepage_size':
                if yobj['hugepage_size'] is None:
                    print("> input hugepage_size (must be 2m(2M) or 1g(1G)):")
                    ans = ""
                    while not (ans == "2M" or ans == "1G"):

                        if sys.version_info.major == 2:
                            ans = raw_input().strip().upper()
                        elif sys.version_info.major == 3:
                            ans = input().strip().upper()

                        if not (ans == "2M" or ans == "1G"):
                            print("> Error! Invalid parameter")
                            print("> hugepage_size (2m(2M) or 1g(1G)):")

                    hp_size = ans
                    make_utils.update_var(vars_file, "hugepage_size", hp_size,
                                          False)
                    target_params[param] = hp_size
                    # print("hugepage_size: #{hp_size}")
                else:
                    target_params[param] = yobj[param]

            # [NOTE] "hugepage_size" must be decided before "nr_hugepages"
            #  because it's required for.
            elif param == 'nr_hugepages':
                if yobj['nr_hugepages'] is None:
                    print("> input nr_hugepages")
                    if sys.version_info.major == 2:
                        ans = raw_input().strip()
                    elif sys.version_info.major == 3:
                        ans = input().strip()
                    while re.match(r'\d+', ans) is None:
                        print("> input nr_hugepages")
                        if sys.version_info.major == 2:
                            ans = raw_input().strip()
                        elif sys.version_info.major == 3:
                            ans = input().strip()
                    nr_hp = ans

                    hp_size = target_params['hugepage_size']

                    if hp_size == '2M':
                        total_hpmem = 2 * 1000 * 1000 * int(nr_hp)
                    elif hp_size == "1G":
                        total_hpmem = 1000 * 1000 * 1000 * int(nr_hp)
                    else:
                        print("Error! Invalid hugepage_size: %s" % hp_size)

                    total_hpmem = make_utils.pretty_memsize(total_hpmem)
                    print("> total hugepages mem: %s" % total_hpmem)
                    make_utils.update_var(vars_file, "nr_hugepages", nr_hp,
                                          False)
                    target_params[param] = nr_hp
                else:
                    target_params[param] = yobj[param]

            elif param == 'dpdk_ver':
                if yobj.has_key(param) and yobj[param] is None:
                    print("> use default DPDK version '%s' ? [Y/n]" %
                          self.di_conf["DPDK_VER"])

                    if sys.version_info.major == 2:
                        ans = raw_input().strip()
                    elif sys.version_info.major == 3:
                        ans = input().strip()

                    if ans == '':
                        ans = 'y'
                    if (ans.lower() == "n" or ans.lower() == "no" or
                            not (ans.lower() == "y" or ans.lower() == "yes")):
                        print(ans)
                        print("> input DPDK version, or empty for latest")
                        if sys.version_info.major == 2:
                            ans = raw_input().strip()
                        elif sys.version_info.major == 3:
                            ans = input().strip()
                        dpdk_ver = ans
                    else:
                        dpdk_ver = self.di_conf["DPDK_VER"]

                    target_params[param] = dpdk_ver
                    make_utils.update_var(vars_file, param, dpdk_ver, False)
                else:
                    target_params[param] = yobj[param]

            elif param == 'dpdk_target':
                if yobj[param] is None:
                    print("> use DPDK target '{}' ? [Y/n]".format(
                        self.di_conf["DPDK_TARGET"]))

                    if sys.version_info.major == 2:
                        ans = raw_input().strip()
                    elif sys.version_info.major == 3:
                        ans = input().strip()

                    if ans == '':
                        ans = 'y'
                    if (ans.lower() == "n" or ans.lower() == "no" or
                            not (ans.lower() == "y" or ans.lower() == "yes")):
                        print("> input DPDK target")

                        if sys.version_info.major == 2:
                            ans = raw_input().strip()
                        elif sys.version_info.major == 3:
                            ans = input().strip()

                        while ans == '':
                            print("> input DPDK target")

                            if sys.version_info.major == 2:
                                ans = raw_input().strip()
                            elif sys.version_info.major == 3:
                                ans = input().strip()

                        dpdk_target = ans
                    dpdk_target = self.di_conf["DPDK_TARGET"]
                    target_params[param] = dpdk_target
                    make_utils.update_var(vars_file, param, dpdk_target, False)
                else:
                    target_params[param] = yobj[param]

            elif param == 'dpdk_interfaces':
                if yobj[param] is None:
                    msg = "> input dpdk_interfaces (separate by white space)" \
                            + ", or empty:"
                    print(msg)
                    if sys.version_info.major == 2:
                        ans = raw_input().strip()
                    elif sys.version_info.major == 3:
                        ans = input().strip()
                    nw_ifs = re.sub(r'\s+', ' ', ans)
                    if nw_ifs == ' ':
                        nw_ifs = ''

                    make_utils.update_var(vars_file, 'dpdk_interfaces', nw_ifs,
                                          False)
                    target_params[param] = nw_ifs
                else:
                    target_params[param] = yobj[param]