Beispiel #1
0
 def do_fetch_parent(self, inp):
     '''Fetch id of host parent from database'''
     id = pick_host(inp, "Find parent of: ")
     parent = db_fetch_parent_id('', id)
     if parent is None:
         print(f'{inp} is not a child host')
     else:
         parent = db_fetch_hostname('', parent)
         print(f'{inp} is a child of {parent}')
Beispiel #2
0
 def do_delete_app(self, inp):
     '''Remove app from specified host in db and reload host'''
     id = pick_host(inp, 'Host to modify? ')
     apps = db_fetch_apps('', id)
     hostname = db_fetch_hostname('', id)
     print(f'Configured apps on {hostname}:')
     print_out(print_cols(apps))
     app = str(input(f'App to remove? ')).lower()
     db_delete_app('', id, app)
     print('Done.')
     self.do_load(hostname)
Beispiel #3
0
 def do_reboot(self, inp):
     '''Reboot specified hosts'''
     id = pick_host(inp, "Reboot which host? ")
     hostname = db_fetch_hostname('', id)
     host = self.do_load(hostname)
     flag = str(input(f'Shutdown {hostname}? (Y/N) [default=N]: ')).lower()
     if flag == "y":
         flag = True
     else:
         flag = False
     time = input(
         "Time to reboot? (+INT minutes delay or HH:MM) [Default: +1]: ")
     if time == "":
         time = '+1'
     print_out(admin.reboot(self.hosts[hostname], time=time, halt=flag))
Beispiel #4
0
def main(argv):
    parser = argparse.ArgumentParser(
        description='Automated / interactive maintenance program.')
    parser.add_argument(
        "host",
        type=str,
        default="all",
        help="Hostname or \'all\'; \'shell\' for interactive mode")
    parser.add_argument("-db",
                        "--database",
                        type=str,
                        default="hosts.db",
                        help="SQLite3 db file to use")
    args = parser.parse_args()
    os.environ['CONN'] = args.database
    if args.host == "shell":
        NagaPrompt().cmdloop()
    elif args.host == "all":
        reboot_list = []
        config, hosts = setup()
        for host in hosts:
            host_id = db_fetch_hostid('', host)
            flag = run_host(host_id, config)
            if flag is True:
                reboot_list.append(f'\t{host}')
        if len(reboot_list) > 0:
            print(f'\n\nThe following hosts need to be rebooted:')
            print_out(reboot_list)
    else:
        config = get_sudo()
        host_id = pick_host(args.host, "Which host? ")
        flag = run_host(host_id, config)
        if flag is True:
            hostname = db_fetch_hostname('', host_id)
            print(f'\n\nHost {hostname} needs to be rebooted.')
    # Clean up
    del os.environ['CONN']
Beispiel #5
0
 def do_add_app(self, inp):
     '''Add app to specified host in db and reload host'''
     id = pick_host(inp, 'Host for new app? ')
     app = str(input("New app function? ")).lower()
     db_add_app('', id, app)
     self.do_load(db_fetch_hostname('', id))