2 # -*- coding: utf-8 -*-
5 This script generates a deployment config based on lab config file.
8 -l, --lab : lab config file
11 from optparse import OptionParser
12 from jinja2 import Environment, FileSystemLoader
20 parser = OptionParser()
21 parser.add_option("-l", "--lab", dest="lab", help="lab config file")
22 (options, args) = parser.parse_args()
23 labconfig_file = options.lab
26 # Set Path and configs path
29 # Capture our current directory
30 TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl'
31 HOME = os.environ['HOME']
32 USER = os.environ['USER']
38 # Prepare a storage for passwords
39 passwords_store = dict()
46 def load_yaml(filepath):
48 with open(filepath, 'r') as stream:
50 return yaml.load(stream)
51 except yaml.YAMLError as exc:
58 # Load scenario Config
59 config = load_yaml(labconfig_file)
61 # Set a dict copy of opnfv/spaces
62 config['opnfv']['spaces_dict'] = dict()
63 for space in config['opnfv']['spaces']:
64 config['opnfv']['spaces_dict'][space['type']] = space
66 # Set a dict copy of opnfv/storage
67 config['opnfv']['storage_dict'] = dict()
68 for storage in config['opnfv']['storage']:
69 config['opnfv']['storage_dict'][storage['type']] = storage
71 # Add some OS environment variables
72 config['os'] = {'home': HOME,
76 # Prepare interface-enable, more easy to do it here
78 for node in config['lab']['racks'][0]['nodes']:
79 for nic in node['nics']:
80 if 'admin' not in nic['spaces']:
81 ifnamelist.add(nic['ifname'])
82 config['lab']['racks'][0]['ifnamelist'] = ','.join(ifnamelist)
85 # Transform template to deployconfig.yaml according to config
88 # Create the jinja2 environment.
89 env = Environment(loader=FileSystemLoader(TPL_DIR),
91 template = env.get_template('deployconfig.yaml')
94 output = template.render(**config)
99 except yaml.YAMLError as exc: