2 # -*- coding: utf-8 -*-
5 This script generates a maas deployer config based on lab config file.
8 -l, --lab : lab config file
11 from optparse import OptionParser
12 from jinja2 import Environment, FileSystemLoader
15 from pprint import pprint as pp
24 parser = OptionParser()
25 parser.add_option("-l", "--lab", dest="lab", help="lab config file")
26 (options, args) = parser.parse_args()
27 labconfig_file = options.lab
30 # Set Path and configs path
33 # Capture our current directory
34 TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl/maas_tpl'
35 HOME = os.environ['HOME']
36 USER = os.environ['USER']
42 # Prepare a storage for passwords
43 passwords_store = dict()
50 def load_yaml(filepath):
52 with open(filepath, 'r') as stream:
54 return yaml.load(stream)
55 except yaml.YAMLError as exc:
59 def get_ip_address(ifname):
61 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
62 return socket.inet_ntoa(fcntl.ioctl(
65 struct.pack('256s', bytes(ifname.encode('utf-8')[:15]))
73 # Load scenario Config
74 config = load_yaml(labconfig_file)
75 config['opnfv']['spaces_dict'] = dict()
76 for space in config['opnfv']['spaces']:
77 config['opnfv']['spaces_dict'][space['type']] = space
78 config['os'] = {'home': HOME,
80 'brAdmIP': get_ip_address(config['opnfv']['spaces_dict']
86 # Transform template to bundle.yaml according to config
89 # Create the jinja2 environment.
90 env = Environment(loader=FileSystemLoader(TPL_DIR),
92 template = env.get_template('deployment.yaml')
95 output = template.render(**config)
100 except yaml.YAMLError as exc: