Beispiel #1
0
def sync_task(args):
    """ Sync bedeutet, die pakete von einem in einen anderen Status zu heben, wenn das vorher auf dem Masterserver auch passiert ist.
        Hier die Liste der möglichen Änderungen:
            install   -> deinstall, purge, hold
            deinstall -> install
            purge     -> install
            hold      -> install
        Im Status "unknown" tun wir nichts... vorerst :)
    """
    master_list = list()
    master_dist = ''
    for server in servers:
        try:
            print colorize(leet_equal_signs(server.get('host')), color and YELLOW)
            apt_cmd = AptMachine(apt_command=args.apt_executable, debug=args.verbose, simulate=args.simulate, **server)
            full_lists = args.full_lists
            package_list = apt_cmd.get_all_packages()
            print 'Operating System:', apt_cmd.distribution
            print 'Packages listed:', len(package_list)
            if server.get('reference'):
                master_dist = apt_cmd.distribution
                print colorize('This server is reference, generating master list.', color and BLUE)
                master_list = package_list
            elif master_list:
                try:
                    print colorize('This server will now be synchronized with the master server.', color and BLUE)
                    if apt_cmd.distribution != master_dist:
                        print colorize("WARNING operating system differs from master server", color and YELLOW)
                    print colorize("[01/16] (missing) unknown => install", color and GREEN)
                    print colorize("[02/16] (missing) unknown => hold", color and GREEN)
                    print colorize("[03/16] (missing) remove => purge", color and GREEN)
                    print colorize("[04/16] (missing) remove => hold", color and GREEN)
                    print colorize("[05/16] (missing) purge => hold", color and GREEN)
                    print colorize("[06/16] (missing) hold => install", color and GREEN)
                    print colorize("[07/16] (missing) hold => remove", color and GREEN)
                    print colorize("[08/16] (missing) hold => purge", color and GREEN)
                    print colorize("[09/16 apt-get update]", color and GREEN)
                    apt_cmd.execute_apt('update')
                    print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)

                try:
                    missing_packages = apt_cmd.get_missing_packages(master_list)
                    print colorize("[10/16 remove, purge => install]", color and GREEN), list_print(missing_packages, full_lists)
                    if missing_packages:
                        print apt_cmd.install(missing_packages)
                        print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)

                try:
                    redundant_packages = apt_cmd.get_redundant_packages(master_list)
                    print colorize("[11/16 install => remove]", color and GREEN), list_print(redundant_packages, full_lists)
                    if redundant_packages:
                        print apt_cmd.remove(redundant_packages)
                        print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)

                try:
                    purged_packages = apt_cmd.get_purged_packages(master_list)
                    print colorize("[12/16 install => purge]", color and GREEN), list_print(purged_packages, full_lists)
                    if purged_packages:
                        print apt_cmd.remove(purged_packages, purge=True)
                        print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)
Beispiel #2
0
                        print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)

                try:
                    purged_packages = apt_cmd.get_purged_packages(master_list)
                    print colorize("[12/16 install => purge]", color and GREEN), list_print(purged_packages, full_lists)
                    if purged_packages:
                        print apt_cmd.remove(purged_packages, purge=True)
                        print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)

                try:
                    held_packages = apt_cmd.get_hold_packages(master_list)
                    print colorize("[13/16 install => hold]", color and GREEN), list_print(held_packages, full_lists)
                    if held_packages:
                        print apt_cmd.hold(held_packages)
                        print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)

                # some cleanup tasks
                try:
                    print colorize("[14/16 autoremove]", color and GREEN)
                    apt_cmd.execute_apt('autoremove')
                    print colorize('[OK]', color and GREEN)
                except Exception, e:
                    print_errors(e, color)
                try:
                    print colorize("[15/16 clean]", color and GREEN)