Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / create_templates / generate_node_info.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 if len(sys.argv) != 5:
18     sys.stderr.write("Usage: "+sys.argv[0]+" <nodeid> <role> <infile> <dhafile>\n")
19     sys.exit(1)
20
21 infile = sys.argv[3]
22 if not os.path.exists(infile):
23     sys.stderr.write("ERROR: The file "+infile+" could not be opened\n")
24     sys.exit(1)
25
26 nodeId=int(sys.argv[1])
27 nodeRole=sys.argv[2]
28 dhafile=sys.argv[4]
29
30 f1 = open(infile, 'r')
31 doc = yaml.load(f1)
32 f1.close()
33
34 out = {}
35
36 node = {}
37 node["id"] = nodeId
38 node["role"] = nodeRole
39 node["interfaces"] = {}
40
41
42 for interface in doc:
43   iface = {}
44   networks = []
45   for network in interface["assigned_networks"]:
46     networks.append(network["name"])
47     if network["name"] == "fuelweb_admin":
48       dhaMac = interface["mac"]
49   if networks:
50     node["interfaces"][interface["name"]] = networks
51
52 out = [node]
53
54 sys.stdout.write(yaml.dump(out, default_flow_style=False))
55
56 # Write contribution to DHA file
57 f2 = open(dhafile, 'a')
58 f2.write("- id: " + str(nodeId) + "\n")
59 f2.write("  pxeMac: " + dhaMac + "\n")
60 f2.close()
61