summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/Client.py
blob: 9d75a6ab3004a2b55f6a4cbb4a1180c822f8d584 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import lxml.etree

import Bcfg2.Server.Admin

class Client(Bcfg2.Server.Admin.Mode):
    __shorthelp__ = 'bcfg2-admin client add <client> attr1=val1 attr2=val2\nbcfg2-admin client del <client>'
    __longhelp__ = __shorthelp__ + '\n\tCreate or delete client entries'
    def __init__(self):
        Bcfg2.Server.Admin.Mode.__init__(self)
        try:
            self.bcore = Bcfg2.Server.Core.Core(self.repo, [], ['Metadata'],
                                                'foo', False)
        except Bcfg2.Server.Core.CoreInitError, msg:
            self.errExit("Core load failed because %s" % msg)
        [bcore.fam.Service() for _ in range(5)]
        while bcore.fam.Service():
            pass

    def __call__(self, args):
        Bcfg2.Server.Admin.Mode.__call__(self, args)
        if args[0] == 'add':
            attr_d = {}
            for i in args[1:]:
                attr, val = i.split('=', 1)
                if attr not in ['profile', 'uuid', 'password', 'address',
                                'secure', 'location']:
                    print "Attribute %s unknown" % attr
                    raise SystemExit(1)
                attr_d[attr] = val
            self.AddClient(args[1], attr_d)
        elif args[0] in ['delete', 'remove', 'del', 'rm']:
            self.DelClient(args[1])
        else:
            print "No command specified"
            raise SystemExit(1)
        self.tree.write(self.get_repo_path() + '/Metadata/clients.xml')        
    
    def AddClient(self, client, attrs):
        '''add a new client'''
        # FIXME add a dup client check
        element = lxml.etree.Element("Client", name=client)
        for key, val in attrs.iteritems():
            element.set(key, val)
        self.root.append(element)

    def DelClient(self, client):
        '''delete an existing client'''
        # FIXME DelClient not implemented
        pass