clients.py
The snippet can be accessed without any authentication.
Authored by
alex
clients.py 1.91 KiB
#!/usr/bin/python
import Bcfg2.Options
import Bcfg2.Client.Proxy
class _ClientCmd(Bcfg2.Options.Subcommand):
pass
def output_clients(clients):
for client in clients:
print client
class Group(_ClientCmd):
""" List all clients that are in the specified groups. """
options = [Bcfg2.Options.PositionalArgument(
'group', nargs='*', help='Groups to query.')]
def run(self, setup):
proxy = Bcfg2.Client.Proxy.ComponentProxy()
clients = proxy.Metadata.get_client_names_by_groups(setup.group)
output_clients(clients)
class Bundle(_ClientCmd):
""" List all clients that have a list of bundles. """
options = [Bcfg2.Options.PositionalArgument(
'bundle', nargs='*')]
def run(self, setup):
proxy = Bcfg2.Client.Proxy.ComponentProxy()
clients = proxy.Metadata.get_client_names_by_bundles(setup.bundle)
output_clients(clients)
class Remove(_ClientCmd):
""" Remove the given client. """
options = [Bcfg2.Options.PositionalArgument(
'client',
help='Name of the client, that should be removed.')]
def run(self, setup):
proxy = Bcfg2.Client.Proxy.ComponentProxy()
proxy.Metadata.remove_client(setup.client)
class List(_ClientCmd):
""" List all clients. """
def run(self, setup):
proxy = Bcfg2.Client.Proxy.ComponentProxy()
output_clients(proxy.Metadata.list_clients())
class ManageClients(Bcfg2.Options.CommandRegistry):
def __init__(self):
Bcfg2.Options.CommandRegistry.__init__(self)
self.register_commands(globals().values(), parent=_ClientCmd)
parser = Bcfg2.Options.get_parser(
description="Manage clients of a running Bcfg2 server",
components=[Bcfg2.Client.Proxy.ComponentProxy, self])
parser.add_options(self.subcommand_options)
parser.parse()
ManageClients().runcommand()
Please register or sign in to comment