def autoconfig_setup(ask_questions=True): """ The auto configuration setup function. We will copy the configuration files to the dryrun directory. """ global rootdir distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': rootdir = '/usr/local' else: rootdir = '/usr' # If there is a system configuration file use that, if not use the initial auto-config file filename = rootdir + VPP_AUTO_CONFIGURATION_FILE if os.path.isfile(filename) is True: acfg = AutoConfig(rootdir, VPP_AUTO_CONFIGURATION_FILE) else: raise RuntimeError( 'The Auto configuration file does not exist {}'.format(filename)) if ask_questions: print("\nWelcome to the VPP system configuration utility") print("\nThese are the files we will modify:") print(" /etc/vpp/startup.conf") print(" /etc/sysctl.d/80-vpp.conf") print(" /etc/default/grub") print("\nBefore we change them, we'll create working copies in " "{}".format(rootdir + VPP_DRYRUNDIR)) print("Please inspect them carefully before applying the actual " "configuration (option 3)!") nodes = acfg.get_nodes() for i in nodes.items(): node = i[1] if (os.path.isfile(rootdir + VPP_STARTUP_FILE) is not True) and \ (os.path.isfile(VPP_REAL_STARTUP_FILE) is True): autoconfig_cp(node, VPP_REAL_STARTUP_FILE, '{}'.format(rootdir + VPP_STARTUP_FILE)) if (os.path.isfile(rootdir + VPP_HUGE_PAGE_FILE) is not True) and \ (os.path.isfile(VPP_REAL_HUGE_PAGE_FILE) is True): autoconfig_cp(node, VPP_REAL_HUGE_PAGE_FILE, '{}'.format(rootdir + VPP_HUGE_PAGE_FILE)) if (os.path.isfile(rootdir + VPP_GRUB_FILE) is not True) and \ (os.path.isfile(VPP_REAL_GRUB_FILE) is True): autoconfig_cp(node, VPP_REAL_GRUB_FILE, '{}'.format(rootdir + VPP_GRUB_FILE)) # Be sure the uio_pci_generic driver is installed cmd = 'modprobe uio_pci_generic' (ret, stdout, stderr) = VPPUtil.exec_command(cmd) if ret != 0: logging.warning('{} failed on node {} {}'.format( cmd, node['host'], stderr))
def autoconfig_grub_apply(node, ask_questions=True): """ Apply the grub configuration. :param node: The node structure :type node: dict :param ask_questions: When True ask the user questions :type ask_questions: bool :returns: -1 if the caller should return, 0 if not :rtype: int """ print "\nThe configured grub cmdline looks like this:" configured_cmdline = node['grub']['default_cmdline'] current_cmdline = node['grub']['current_cmdline'] print configured_cmdline print "\nThe current boot cmdline looks like this:" print current_cmdline if ask_questions: question = "\nDo you want to keep the current boot cmdline [Y/n]? " answer = autoconfig_yn(question, 'y') if answer == 'y': return node['grub']['keep_cmdline'] = False # Diff the file diffs = autoconfig_diff(node, VPP_REAL_GRUB_FILE, rootdir + VPP_GRUB_FILE) if diffs != '': print "These are the changes we will apply to" print "the GRUB file ({}).\n".format(VPP_REAL_GRUB_FILE) print diffs if ask_questions: answer = autoconfig_yn( "\nAre you sure you want to apply these changes [y/N]? ", 'n') if answer == 'n': return -1 # Copy and update grub autoconfig_cp(node, rootdir + VPP_GRUB_FILE, VPP_REAL_GRUB_FILE) distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': cmd = "update-grub" else: cmd = "grub2-mkconfig -o /boot/grub2/grub.cfg" (ret, stdout, stderr) = VPPUtil.exec_command(cmd) if ret != 0: raise RuntimeError('{} failed on node {} {} {}'.format( cmd, node['host'], stdout, stderr)) print "There have been changes to the GRUB config a", print "reboot will be required." return -1 else: print '\nThere are no changes to the GRUB config.' return 0
def autoconfig_setup(ask_questions=True): """ The auto configuration setup function. We will copy the configuration files to the dryrun directory. """ global rootdir distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': rootdir = '/usr/local' else: rootdir = '/usr' # If there is a system configuration file use that, if not use the initial auto-config file filename = rootdir + VPP_AUTO_CONFIGURATION_FILE if os.path.isfile(filename) is True: acfg = AutoConfig(rootdir, VPP_AUTO_CONFIGURATION_FILE) else: raise RuntimeError('The Auto configuration file does not exist {}'. format(filename)) if ask_questions: print ("\nWelcome to the VPP system configuration utility") print ("\nThese are the files we will modify:") print (" /etc/vpp/startup.conf") print (" /etc/sysctl.d/80-vpp.conf") print (" /etc/default/grub") print ( "\nBefore we change them, we'll create working copies in " "{}".format(rootdir + VPP_DRYRUNDIR)) print ( "Please inspect them carefully before applying the actual " "configuration (option 3)!") nodes = acfg.get_nodes() for i in nodes.items(): node = i[1] if (os.path.isfile(rootdir + VPP_STARTUP_FILE) is not True) and \ (os.path.isfile(VPP_REAL_STARTUP_FILE) is True): autoconfig_cp(node, VPP_REAL_STARTUP_FILE, '{}'.format(rootdir + VPP_STARTUP_FILE)) if (os.path.isfile(rootdir + VPP_HUGE_PAGE_FILE) is not True) and \ (os.path.isfile(VPP_REAL_HUGE_PAGE_FILE) is True): autoconfig_cp(node, VPP_REAL_HUGE_PAGE_FILE, '{}'.format(rootdir + VPP_HUGE_PAGE_FILE)) if (os.path.isfile(rootdir + VPP_GRUB_FILE) is not True) and \ (os.path.isfile(VPP_REAL_GRUB_FILE) is True): autoconfig_cp(node, VPP_REAL_GRUB_FILE, '{}'.format(rootdir + VPP_GRUB_FILE)) # Be sure the uio_pci_generic driver is installed cmd = 'modprobe uio_pci_generic' (ret, stdout, stderr) = VPPUtil.exec_command(cmd) if ret != 0: logging.warning('{} failed on node {} {}'. format(cmd, node['host'], stderr))
def autoconfig_grub_apply(node, ask_questions=True): """ Apply the grub configuration. :param node: The node structure :type node: dict :param ask_questions: When True ask the user questions :type ask_questions: bool :returns: -1 if the caller should return, 0 if not :rtype: int """ print ("\nThe configured grub cmdline looks like this:") configured_cmdline = node['grub']['default_cmdline'] current_cmdline = node['grub']['current_cmdline'] print (configured_cmdline) print ("\nThe current boot cmdline looks like this:") print (current_cmdline) if ask_questions: question = "\nDo you want to keep the current boot cmdline [Y/n]? " answer = autoconfig_yn(question, 'y') if answer == 'y': return node['grub']['keep_cmdline'] = False # Diff the file diffs = autoconfig_diff(node, VPP_REAL_GRUB_FILE, rootdir + VPP_GRUB_FILE) if diffs != '': print ("These are the changes we will apply to") print ("the GRUB file ({}).\n".format(VPP_REAL_GRUB_FILE)) print (diffs) if ask_questions: answer = autoconfig_yn("\nAre you sure you want to apply these changes [y/N]? ", 'n') if answer == 'n': return -1 # Copy and update grub autoconfig_cp(node, rootdir + VPP_GRUB_FILE, VPP_REAL_GRUB_FILE) distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': cmd = "update-grub" else: cmd = "grub2-mkconfig -o /boot/grub2/grub.cfg" (ret, stdout, stderr) = VPPUtil.exec_command(cmd) if ret != 0: raise RuntimeError('{} failed on node {} {} {}'. format(cmd, node['host'], stdout, stderr)) print ("There have been changes to the GRUB config a", end=' ') print ("reboot will be required.") return -1 else: print ('\nThere are no changes to the GRUB config.') return 0
def autoconfig_setup(ask_questions=True): """ The auto configuration setup function. We will copy the configuration files to the dryrun directory. """ global rootdir logging.basicConfig(level=logging.ERROR) distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': rootdir = '/usr/local' else: rootdir = '/usr' # If there is a system configuration file use that, if not use the initial auto-config file filename = rootdir + VPP_AUTO_CONFIGURATION_FILE if os.path.isfile(filename) is True: acfg = AutoConfig(rootdir, VPP_AUTO_CONFIGURATION_FILE) else: raise RuntimeError( 'The Auto configuration file does not exist {}'.format(filename)) if ask_questions: print "\nWelcome to the VPP system configuration utility" print "\nThese are the files we will modify:" print " /etc/vpp/startup.conf" print " /etc/sysctl.d/80-vpp.conf" print " /etc/default/grub" print "\nBefore we change them, we'll create working copies in {}".format( rootdir + VPP_DRYRUNDIR) print "Please inspect them carefully before applying the actual configuration (option 3)!" nodes = acfg.get_nodes() for i in nodes.items(): node = i[1] if (os.path.isfile(rootdir + VPP_STARTUP_FILE) is not True) and \ (os.path.isfile(VPP_REAL_STARTUP_FILE) is True): autoconfig_cp(node, VPP_REAL_STARTUP_FILE, '{}'.format(rootdir + VPP_STARTUP_FILE)) if (os.path.isfile(rootdir + VPP_HUGE_PAGE_FILE) is not True) and \ (os.path.isfile(VPP_REAL_HUGE_PAGE_FILE) is True): autoconfig_cp(node, VPP_REAL_HUGE_PAGE_FILE, '{}'.format(rootdir + VPP_HUGE_PAGE_FILE)) if (os.path.isfile(rootdir + VPP_GRUB_FILE) is not True) and \ (os.path.isfile(VPP_REAL_GRUB_FILE) is True): autoconfig_cp(node, VPP_REAL_GRUB_FILE, '{}'.format(rootdir + VPP_GRUB_FILE))
def __init__(self, node): distro = VPPUtil.get_linux_distro() if distro[0] == "Ubuntu": node["cpu"]["grubcmdline"] = "GRUB_CMDLINE_LINUX_DEFAULT" else: node["cpu"]["grubcmdline"] = "GRUB_CMDLINE_LINUX" self._node = node self._current_cmdline = "" self._default_cmdline = "" self._get_current_cmdline() self._get_default_cmdline()
def __init__(self, node): distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': node['cpu']['grubcmdline'] = 'GRUB_CMDLINE_LINUX_DEFAULT' else: node['cpu']['grubcmdline'] = 'GRUB_CMDLINE_LINUX' self._node = node self._current_cmdline = "" self._default_cmdline = "" self._get_current_cmdline() self._get_default_cmdline()
def __init__(self, node): distro = VPPUtil.get_linux_distro() if distro[0] == 'Ubuntu': node['cpu']['grubcmdline'] = 'GRUB_CMDLINE_LINUX_DEFAULT' else: node['cpu']['grubcmdline'] = 'GRUB_CMDLINE_LINUX' self._node = node self._current_cmdline = "" self._default_cmdline = "" self._get_current_cmdline() self._get_default_cmdline()
def autoconfig_grub_apply(node, ask_questions=True): """ Apply the grub configuration. :param node: The node structure :type node: dict :param ask_questions: When True ask the user questions :type ask_questions: bool :returns: -1 if the caller should return, 0 if not :rtype: int """ print("\nThe configured grub cmdline looks like this:") configured_cmdline = node["grub"]["default_cmdline"] current_cmdline = node["grub"]["current_cmdline"] print(configured_cmdline) print("\nThe current boot cmdline looks like this:") print(current_cmdline) if ask_questions: question = "\nDo you want to keep the current boot cmdline [Y/n]? " answer = autoconfig_yn(question, "y") if answer == "y": return node["grub"]["keep_cmdline"] = False # Diff the file diffs = autoconfig_diff(node, VPP_REAL_GRUB_FILE, rootdir + VPP_GRUB_FILE) if diffs != "": print("These are the changes we will apply to") print("the GRUB file ({}).\n".format(VPP_REAL_GRUB_FILE)) print(diffs) if ask_questions: answer = autoconfig_yn( "\nAre you sure you want to apply these changes [y/N]? ", "n" ) if answer == "n": return -1 # Copy and update grub autoconfig_cp(node, rootdir + VPP_GRUB_FILE, VPP_REAL_GRUB_FILE) distro = VPPUtil.get_linux_distro() if distro[0] == "Ubuntu": cmd = "update-grub" else: cmd = "grub2-mkconfig -o /boot/grub2/grub.cfg" (ret, stdout, stderr) = VPPUtil.exec_command(cmd) if ret != 0: raise RuntimeError( "{} failed on node {} {} {}".format(cmd, node["host"], stdout, stderr) ) print("There have been changes to the GRUB config a", end=" ") print("reboot will be required.") return -1 else: print("\nThere are no changes to the GRUB config.") return 0