#! /usr/bin/env python
'''Change or list the hosts using a given storage server.'''

from __future__ import print_function
import sys
import bacula_tools


def usage():
    '''Usage: %s storageserver [client [client...]]
    Given just a storageserver, list all of the clients using this storageserver.

    If given one or more clients, switch them to this storageserver.'''
    print(usage.__doc__ % sys.argv[0])
    exit()

# Actual program is here.

if len(sys.argv) < 2 or '-h' in sys.argv or '--help' in sys.argv:
    usage()
storage = sys.argv[1]
clients = sys.argv[2:]

storage_unit = bacula_tools.Storage().search(storage)

if clients:
    for host in clients:
        storage_unit.move(host)
else:
    storage_unit.list_clients()
