summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/Minestruct.py
blob: 9e91ff33e790fdbf350be2239af87967abbaf4f9 (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
import Bcfg2.Server.Admin

class Minestruct(Bcfg2.Server.Admin.Mode):
    '''Pull extra entries out of statistics'''
    __shorthelp__ = 'bcfg2-admin minestruct <client>'
    __longhelp__ = __shorthelp__ + '\n\tExtract extra entry lists from statistics'

    def __init__(self, cfile):
	Bcfg2.Server.Admin.Mode.__init__(self, cfile)

    def __call__(self, args):
        Bcfg2.Server.Admin.Mode.__call__(self, args)
        if len(args) != 1:
            self.errExit("minestruct must be called with a client name")
        extra = self.MineStruct(args[0])
        self.log.info("Found %d extra entries" % (len(extra)))
        self.log.info(["%s: %s" % (entry.tag, entry.get('name')) for entry in extra])

    def MineStruct(self, client):
        '''Pull client entries into structure'''
        stats = self.load_stats(client)
        if len(stats.getchildren()) == 2:
            # FIXME this is busted
            # client is dirty
            current = [ent for ent in stats.getchildren() if ent.get('state') == 'dirty'][0]
        else:
            current = stats.getchildren()[0]
        return current.find('Extra').getchildren()