summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Admin/Client.py
blob: 34dfd755040a9a358b0046b80c6820cd128e42f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import lxml.etree
import Bcfg2.Server.Admin
from Bcfg2.Server.Plugins.Metadata import MetadataConsistencyError


class Client(Bcfg2.Server.Admin.MetadataCore):
    __shorthelp__ = "Create, delete, or list client entries"
    __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin client add <client> "
                                    "\nbcfg2-admin client list"
                                    "\nbcfg2-admin client del <client>\n")
    __usage__ = ("bcfg2-admin client [options] [add|del|list] [attr=val]")

    def __call__(self, args):
        Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
        if len(args) == 0:
            self.errExit("No argument specified.\n"
                         "Usage: %s" % self.usage)
        if args[0] == 'add':
            try:
                self.metadata.add_client(args[1])
            except MetadataConsistencyError:
                print("Error in adding client")
                raise SystemExit(1)
        elif args[0] in ['delete', 'remove', 'del', 'rm']:
            try:
                self.metadata.remove_client(args[1])
            except MetadataConsistencyError:
                print("Error in deleting client")
                raise SystemExit(1)
        elif args[0] in ['list', 'ls']:
            for client in self.metadata.list_clients():
                print(client.hostname)
        else:
            print("No command specified")
            raise SystemExit(1)