14eec4cc675e7a0b15c192868e3b21f68fb48ccb
[genesis.git] / fuel / build / f_isoroot / f_predeployment / transform_yaml.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 # Remove control and management network transformations from file.
13 # Only to be used together with f_control_bond_example (enable in
14 # pre-deploy.sh)
15
16 import yaml
17 import re
18 import sys
19 import os
20
21 if len(sys.argv) != 2:
22     sys.stderr.write("Usage: "+sys.argv[0]+" <filename>\n")
23     sys.exit(1)
24
25 filename = sys.argv[1]
26 if not os.path.exists(filename):
27     sys.stderr.write("ERROR: The file "+filename+" could not be opened\n")
28     sys.exit(1)
29
30 ignore_values = [ "eth0", "eth1", "br-mgmt", "br-fw-admin" ]
31
32 infile = open(filename, 'r')
33 doc = yaml.load(infile)
34 infile.close()
35
36 out={}
37
38 for scheme in doc:
39     if scheme == "network_scheme":
40         mytransformation = {}
41         for operation in doc[scheme]:
42             if operation == "transformations":
43                 # We need the base bridges for l23network to be happy,
44                 # remove everything else.
45                 mytrans = [ { "action": "add-br", "name": "br-mgmt" },
46                             { "action": "add-br", "name": "br-fw-admin" } ]
47                 for trans in doc[scheme][operation]:
48                     delete = 0
49                     for ignore in ignore_values:
50                         matchObj = re.search(ignore,str(trans))
51                         if matchObj:
52                             delete = 1
53                     if delete == 0:
54                         mytrans.append(trans)
55                     else:
56                         pass
57                         #print "Deleted", trans
58
59                 mytransformation[operation] = mytrans
60             else:
61                 mytransformation[operation] = doc[scheme][operation]
62         out[scheme] = mytransformation
63     else:
64         out[scheme] = doc[scheme]
65
66 outfile = open(filename, 'w')
67 outfile.write(yaml.dump(out, default_flow_style=False))
68 outfile.close()