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 ##############################################################################
17 if len(sys.argv) != 4:
18 sys.stderr.write("Usage: "+sys.argv[0]+" <infile> <deafile> <nodeid>\n")
22 if not os.path.exists(infile):
23 sys.stderr.write("ERROR: The file "+infile+" could not be opened\n")
27 if not os.path.exists(deafile):
28 sys.stderr.write("ERROR: The file "+deafile+" could not be opened\n")
31 nodeid = int(sys.argv[3])
33 namespace = "interfaces"
35 f1 = open(infile, 'r')
39 f2 = open(deafile, 'r')
44 # Create lookup table network name -> id for current setup
46 for interface in doc1:
49 for network in interface["assigned_networks"]:
50 nwlookup[network["name"]] = network["id"]
52 # Find network information in DEA for this node
54 for node in doc2["nodes"]:
55 if node["id"] == nodeid:
57 print "Found nodeinfo for node %d" % nodeid
60 out["interfaces"] = {}
62 for interface in doc1:
65 interface["assigned_networks"] = []
66 for nwname in nodeInfo["interfaces"][interface["name"]]:
68 iface["id"] = nwlookup[nwname]
69 iface["name"] = nwname
70 interface["assigned_networks"].append(iface)
72 f3 = open(infile, 'w')
73 f3.write(yaml.dump(doc1, default_flow_style=False))