Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / deploy / functions / deaParse.py
1 #!/usr/bin/python
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 import yaml
13 import re
14 import sys
15 import os
16
17 def test(arr):
18     print "Nodes"
19     nodes = doc["nodes"]
20     for node in nodes:
21         print "Node %d " % node["id"]
22         print "  Mac: %s" % node["adminMac"]
23         print "  Role: %s" % node["role"]
24
25 def getNodeRole(arg):
26     for node in doc["nodes"]:
27         print node
28         try:
29             if node["role"] == arg[0]:
30                 print doc["id"]
31         except KeyError:
32             exit(1)
33
34 def getNodes(arg):
35     for node in doc["nodes"]:
36         print node["id"]
37
38
39 def getProperty(arg):
40     result = doc
41     for level in arg:
42         result = result[level]
43     print result
44
45 def getNodeRole(arg):
46     for node in doc["nodes"]:
47         if int(arg[0]) == node["id"]:
48             print node["role"]
49
50 def getNode(arg):
51     id=arg[0]
52     key=arg[1]
53     for node in doc["nodes"]:
54         if int(node["id"]) == int(id):
55             print node[key]
56
57     # for node in doc["nodes"]:
58     #     if int(node["id"]) == int(arg[0]):
59     #         print node
60
61 infile = sys.argv[1]
62
63 if not os.path.exists(infile):
64     sys.stderr.write("ERROR: The file "+infile+" could not be opened\n")
65     sys.exit(1)
66
67
68 f1 = open(infile, 'r')
69 doc = yaml.load(f1)
70 f1.close()
71
72 cmd = sys.argv[2]
73 args = sys.argv[3:]
74
75 if cmd == "getProperty":
76     getProperty(args)
77 elif cmd == "getNodeRole":
78     getNodeRole(args)
79 elif cmd == "getNode":
80     getNode(args)
81 elif cmd == "get":
82     get(args)
83 else:
84   print "No such command: %s" % cmd
85   exit(1)