summaryrefslogtreecommitdiffstats
path: root/src/bcfg2meta
blob: 4b5e94a9717738f55d2c62d5863b3b8fcf23c6a9 (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
51
52
53
54
55
56
57
#!/usr/bin/env python

# $Id: $

from getopt import getopt, GetoptError
from string import join
from sys import argv, exit

from Metadata import MetadataStore

def dgetopt(arglist, opt, vopt):
    r = {}
    for o in opt.values() + vopt.values():
        r[o] = False
    gstr = join(opt.keys()) + join([x+':' for x in vopt.keys()])
    try:
        (o, a) = getopt(arglist, gstr)
    except GetoptError, g:
        print g
        print "bcfg2 Usage:"
        for (k,v) in opt.iteritems():
            print " -%s %s"%(k,v)
        for (k,v) in  vopt.iteritems():
            print " -%s <%s>"%(k,v)
        exit(1)
    for (gopt,garg) in o:
        option = gopt[1:]
        if opt.has_key(option):
            r[opt[option]] = True
        else:
            r[vopt[option]] = garg
    return r

class StaticMetadataStore(MetadataStore):
    def __init__(self, filename):
        self.data = open(filename).read()
        self.Index()

if __name__ == '__main__':
    vopts = {'g':'get', 's':'set', 'i':'image', 'c':'classes'}
    setup = dgetopt(argv[1:], {}, vopts)

    ops = filter(lambda x:setup[x], ['get','set'])
    if len(filter(lambda x:setup[x], ['get','set'])) != 1:
        print "confused"
        exit(1)

    op = ops[0]

    data = StaticMetadataStore('/home/desai/data/b2/common/metadata.xml')

    client = setup[op] 

    if op == 'get':
        if data.clients.has_key(client):
            m = data.clients[client]
            print "Host: %s\t\tImage: %s\n\tClasses: %s\n\tBundles: %s"%(client, m.image, join(m.classes,','), join(m.bundles,','))