summaryrefslogtreecommitdiffstats
path: root/test/inventory_api.py
blob: 0510862a10a3a12680f04d6c7371bae31e28578d (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
#!/usr/bin/env python

import json
import sys

from optparse import OptionParser

parser = OptionParser()
parser.add_option('-l', '--list', default=False, dest="list_hosts", action="store_true")
parser.add_option('-H', '--host', default=None, dest="host")
parser.add_option('-e', '--extra-vars', default=None, dest="extra")

options, args = parser.parse_args()

systems = {
    "ungrouped": [ "jupiter", "saturn" ],
    "greek": [ "zeus", "hera", "poseidon" ],
    "norse": [ "thor", "odin", "loki" ],
    "major-god": [ "zeus", "odin" ],
}

variables = {
    "thor": {
        "hammer": True
        },
    "zeus": {},
}

if options.list_hosts == True:
    print json.dumps(systems)
    sys.exit(0)

if options.host is not None:
    if options.extra:
        k,v = options.extra.split("=")
        variables[options.host][k] = v
    print json.dumps(variables[options.host])
    sys.exit(0)

parser.print_help()
sys.exit(1)