X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=ci%2FgenDeploymentConfig.py;h=0d3a1c9574887e83212c33894579dbe597133910;hb=7009ee2526775339ea4630e6ef94f3f467524e0d;hp=d78c93faf13beaea237165cf472d978a8a4130ae;hpb=0f81e81552bdf0053fc0303c53dff455c17d56a6;p=joid.git diff --git a/ci/genDeploymentConfig.py b/ci/genDeploymentConfig.py index d78c93fa..0d3a1c95 100644 --- a/ci/genDeploymentConfig.py +++ b/ci/genDeploymentConfig.py @@ -10,8 +10,13 @@ Parameters: from optparse import OptionParser from jinja2 import Environment, FileSystemLoader +from distutils.version import LooseVersion, StrictVersion import os import yaml +import subprocess +import socket +import fcntl +import struct # # Parse parameters @@ -25,9 +30,8 @@ labconfig_file = options.lab # # Set Path and configs path # +TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl/juju2' -# Capture our current directory -TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl' HOME = os.environ['HOME'] USER = os.environ['USER'] @@ -51,6 +55,21 @@ def load_yaml(filepath): except yaml.YAMLError as exc: print(exc) + +def get_ip_address(ifname): + """Get local IP""" + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', bytes(ifname.encode('utf-8')[:15])) + )[20:24]) + + +# +# Config import +# + # # Config import # @@ -71,7 +90,8 @@ for storage in config['opnfv']['storage']: # Add some OS environment variables config['os'] = {'home': HOME, 'user': USER, - } + 'brAdmIP': get_ip_address(config['opnfv']['spaces_dict'] + ['admin']['bridge'])} # Prepare interface-enable, more easy to do it here ifnamelist = set() @@ -79,7 +99,7 @@ for node in config['lab']['racks'][0]['nodes']: for nic in node['nics']: if 'admin' not in nic['spaces']: ifnamelist.add(nic['ifname']) -config['lab']['racks'][0]['ifnamelist'] = ', '.join(ifnamelist) +config['lab']['racks'][0]['ifnamelist'] = ','.join(ifnamelist) # # Transform template to deployconfig.yaml according to config