Esempio n. 1
0
def shell_task(args):
    """ eigene kommandos in der shell ausführen """
    for server in servers:
        try:
            print colorize(leet_equal_signs(server.get('host')), color and YELLOW)
            apt_cmd = AptMachine(debug=args.verbose, **server)
            print apt_cmd._execute(args.shell_command)
            print colorize('[OK]', color and GREEN)
        except Exception, ex:
            print_errors(ex, color)
        finally:
Esempio n. 2
0
def apt_task(args):
    """ apt-get ... ausführen """
    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)
            # process task to apt-get
            print apt_cmd.execute_apt(args.command, args.packages, args.apt_options)
            print colorize('[OK]', color and GREEN)
        except Exception, ex:
            print_errors(ex, color)
        finally:
Esempio n. 3
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)