Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / deploy / dha-adapters / dhaParse.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 get(arg):
26     try:
27         if doc[arg[0]]:
28             print doc[arg[0]]
29         else:
30             print ""
31     except KeyError:
32         print ""
33
34 def getNodes(arg):
35     for node in doc["nodes"]:
36         print node["id"]
37
38 # Get property arg2 from arg1
39 def getNodeProperty(arg):
40     id=arg[0]
41     key=arg[1]
42
43     for node in doc["nodes"]:
44         if node["id"] == int(id):
45             try:
46                 if node[key]:
47                     print node[key]
48                     exit(0)
49             except:
50                 print ""
51                 exit(0)
52     exit(1)
53
54
55
56 infile = sys.argv[1]
57
58 if not os.path.exists(infile):
59     sys.stderr.write("ERROR: The file "+infile+" could not be opened\n")
60     sys.exit(1)
61
62
63 f1 = open(infile, 'r')
64 doc = yaml.load(f1)
65 f1.close()
66
67 cmd = sys.argv[2]
68 args = sys.argv[3:]
69
70 if cmd  == "test":
71     test(args)
72 elif cmd == "getNodes":
73     getNodes(args)
74 elif cmd == "getNodeProperty":
75     getNodeProperty(args)
76 elif cmd == "get":
77     get(args)
78 else:
79   print "No such command: %s" % cmd
80   exit(1)
81
82 #print "Dumping"
83 #print yaml.dump(doc, default_flow_style=False)
84
85 #Functions:
86
87 #getIdRole