Exemple #1
0
def _upgrade(system_name):
    """
    Do the actual upgrade.
    """

    # Get the path to the cache files which contain the information on what
    # is to be upgraded. Also, get the command by which the system is to be
    # upgraded.
    pippy_cachedir = get_config_option(__pluginname__, "pippy_cachedir")
    py_upgrade_cmd = get_config_option(__pluginname__, "py_upgrade_cmd")

    # Get the list of packages that need to be upgraded.
    updates = _get_updates(pippy_cachedir + os.sep + system_name)
 
    # Do the actual upgrade.
    if updates:
        if system_name == "base":
            for update in updates:
                HERE
                execute_command(["%s %s" % (py_upgrade_cmd, update.split()[0])])
        else:
            # It means we operate on jails now.
            for update in updates:
                execute_command(["jexec %s %s %s" % \
                                (system_name, py_upgrade_cmd, \
                                 update.split()[0])])

        # Do postupgrade update if specified in the config.
        _postupgrade_update(system_name)
    else:
        print colored("->", "green"), \
              colored("Nothing to upgrade.", attrs=["bold"])
    def get_updates(self, system_name=None):
        """
        Get the information which python packages need to be updated. Use 
        "yolk -U" to get this info.

        Attributes:

        system_name = give the name of the base system or a jail in order to
                      process just one unit. REMINDER: system_name must be given
                      as a list. Thus, get_updates("jail") will not work, while
                      get_updates(["jail"]) will.
        """

        self.jails = system_name

        if self.jails == None:
            # Get the names of the jails. Afterwards, list and save the update list.
            self.jails = get_config_option("pippy", "jails")

        # Show updates for the base system.
        if "base" in self.jails:
            update, error = execute_command(["yolk -U"], func_return=True)
            self._save_updates("base", update)

            # Remove "base" from the list, so it is not invoked in the loop
            # below.
            self.jails.remove("base")

        for jail in self.jails:
            update, error = execute_command(["jexec %s yolk -U" % \
                                            jail], func_return=True)

            self._save_updates(jail, update)
    def __init__(self):
        """
        Check whether the infrastructure exists.
        """

        # Get the path to the cache dir.
        self.pippy_cachedir = get_config_option("pippy", "pippy_cachedir")

        # If the directory does not exist, create one. Recursively.
        if not os.path.exists(self.pippy_cachedir):
            os.makedirs(self.pippy_cachedir, 0700)
Exemple #4
0
def upgrade(params):
    """
    Upgrade base system and some of the jails. Get the list of systems to 
    upgrade from the command line. Usage:
    
        # czokomaster ports upgrade base jail1 jail2
      
    This would upgrade the base system only:
    
        # czokomaster ports upgrade base
          
    This would upgrade all jails. Caution! Jails' names must be put into
    the config file:
    
        # czokomaster ports upgrade all
    """

    # Get base or/and jails that are to be upgraded.
    # normalize_params() requires config section, config variable and params.
    jails = normalize_params(__pluginname__, "jails", params)

    # Get the upgrade command.
    ports_upgrade_cmd = get_config_option(__pluginname__, "ports_upgrade_cmd")

    # If the base system is to be upgraded as well, do it now. In order
    # to upgrade the base system, add "base" to the "jails" option within
    # the config file.
    if "base" in jails:
        # Both "colored(...)" shall be displayed as one text line.
        print colored("\n==>", "green"), \
              colored("Upgrading the base system", attrs=["bold"]) + \
              colored(":\n", attrs=["bold"])

        execute_command([ports_upgrade_cmd])

        # Drop "base" from the list, so it does not interfere with the loop below.
        # Print new line as well.
        jails.remove("base")
        print ""

    # Upgrade specified jails.
    for jail in jails:
        print colored("\n==>", "green"), \
              colored("Upgrading", attrs=["bold"]), \
              colored(jail, "cyan") + colored(":\n", attrs=["bold"])
        
        execute_command(["jexec %s %s" % (jail, ports_upgrade_cmd)])

    # Print new line.
    print ""
Exemple #5
0
def diff(params):
    """
    Show the ports that need to be updated.
    """

    jails = normalize_params(__pluginname__, "jails", params)
    
    # Get the command to show the ports that need updating.
    show_updates_cmd = get_config_option(__pluginname__, "show_updates_cmd")

    # First, the base system, if it is supplied either on the command line
    # or in the config file.
    if "base" in jails:
        print "Available updates for", colored("the base system", "cyan") + ":"

        # Pass the 'func_return=True' as a function argument, so the output is
        # not printed but returned to stdout and stderr variables.
        stdout, stderr = execute_command([show_updates_cmd], func_return=True)

        # If stdout is nil, don't print red '->'. Print green '-> None'.
        if stdout:
            print colored("->", "red"), stdout[:-2].replace("\n", \
                  colored("\n-> ", "red"))
        else:
            print colored("->", "green"), colored("None", "white", \
                                                  attrs=["bold"])

        # Remove "base", so it does not interfere with the loop below.
        jails.remove("base")

    for jail in jails:
        # Print available updates.
        print "\nAvailable updates for", \
              colored(jail, "cyan") + ":"

        stdout, stderr = execute_command(["jexec %s %s" % (jail,
                         show_updates_cmd)], func_return=True)

        # If stdout is nil, don't print red '->'. Print green '-> None'.
        if stdout:
            print colored("->", "red"), stdout[:-2].replace("\n", \
                  colored("\n-> ", "red"))
        else:
            print colored("->", "green"), colored("None", attrs=["bold"])
Exemple #6
0
def _postupgrade_update(system_name):
    """
    If update_after_upgrade is set to "yes", update the py packages list
    that need upgrading after the upgrade is complete.
    """

    config = get_config_option(__pluginname__, "update_after_upgrade")

    if config.lower() == "yes":
        from czokomaster.plugins.plugin_helpers.pippy_cron_helper import \
             PythonUpdateChecker

        print colored("->", "blue"), \
              colored("Updating the cache file...", attrs=["bold"])

        update = PythonUpdateChecker()
        update.get_updates([system_name])
        print colored("->", "green"), colored("Done.", attrs=["bold"])
        print ""
Exemple #7
0
def diff(params):
    """
    Show the ports that need to be updated.
    """

    # Get the path to the cache files which contain the information on what
    # is to be upgraded. Also, get the jajil names (which are at the same time
    # the file names in the cache directory).
    jails = normalize_params(__pluginname__, "jails", params)
    pippy_cachedir = get_config_option(__pluginname__, "pippy_cachedir")

    if "base" in jails:
        # Print the packages that need to be updated.
        _print_updates(pippy_cachedir + os.sep + "base", "the base system")

        # Remove "base", so it does not interfere with the loop below.
        jails.remove("base")

    for jail in jails:
        _print_updates(pippy_cachedir + os.sep + jail, jail)