From: David Blaisonneau Date: Tue, 19 Jul 2016 10:27:35 +0000 (+0200) Subject: [Joid] PEP8 cosmetic changes X-Git-Tag: colorado.1.0~86 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=8f062598d13413ac478b7f02d918ee4667aaf52c;p=joid.git [Joid] PEP8 cosmetic changes Signed-off-by: David Blaisonneau --- diff --git a/ci/deploy.py b/ci/deploy.py index 35d3c31b..901eef64 100644 --- a/ci/deploy.py +++ b/ci/deploy.py @@ -1,12 +1,19 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +Deploy JOID +""" + import yaml -import pprint import socket import fcntl import struct -import os import getpass + 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(), @@ -15,50 +22,85 @@ def get_ip_address(ifname): )[20:24]) with open('labconfig.yaml', 'r') as labf: - labcfg = yaml.load(labf) + try: + labcfg = yaml.load(labf) + except yaml.YAMLError as exc: + print(exc) -opnfvcfg={} -opnfvlabcfg={} -def getFromDict(dataDict, mapList): +opnfvcfg = {} +opnfvlabcfg = {} + + +def get_from_dict(dataDict, mapList): return reduce(lambda d, k: d[k], mapList, dataDict) -#lets define the bootstrap section -opnfvcfg['demo-maas']={'juju-bootstrap':{'memory': 4096,'name': "bootstrap",\ - 'pool': "default", 'vcpus': 4,\ - 'disk_size': "60G", 'arch': "amd64",\ - 'interfaces':[]},\ - 'maas':{'memory': 4096,'pool': "default", 'vcpus': 4,\ - 'disk_size': "160G", 'arch': "amd64", 'interfaces':[],\ - 'name':"",'network_config':[],'node_group_ifaces':[],\ - 'nodes':[],'password': 'ubuntu', 'user':'ubuntu',\ - 'release': 'trusty', 'apt_sources':[],'ip_address':'',\ - 'boot_source':{'keyring_filename':\ - "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",\ - 'url': \ - "http://maas.ubuntu.com/images/ephemeral-v2/releases/",\ - 'selections':{'1':{'arches':'amd64','labels':'release',\ - 'os':'ubuntu','release':'xenial',\ - 'subarches':'*' - }\ - }\ - },\ - 'settings':{'maas_name':'','upstream_dns':'',\ - 'main_archive':"http://archive.ubuntu.com/ubuntu"\ - },\ - 'virsh':{'rsa_priv_key':'/home/ubuntu/.ssh/id_rsa', - 'rsa_pub_key':'/home/ubuntu/.ssh/id_rsa.pub', - 'uri':'' - }\ - }\ - } - -opnfvlabcfg['opnfv']={'ext-port':'','floating-ip-range':'','dataNetwork':'','ceph-disk':'/srv/',\ - 'storageNetwork':'','interface-enable':'','publicNetwork':'',\ - 'os-domain-name':'','vip':{'rabbitmq':'','dashboard':'','glance':'',\ - 'keystone':'','ceilometer':'','mysql':'',\ - 'nova':'','neutron':'','heat':'','cinder':''}\ - } +# lets define the bootstrap section +opnfvcfg['demo-maas'] = {'juju-bootstrap': {'memory': 4096, + 'name': "bootstrap", + 'pool': "default", + 'vcpus': 4, + 'disk_size': "60G", + 'arch': "amd64", + 'interfaces': []}, + 'maas': {'memory': 4096, + 'pool': "default", + 'vcpus': 4, + 'disk_size': "160G", + 'arch': "amd64", + 'interfaces': [], + 'name': "", + 'network_config': [], + 'node_group_ifaces': [], + 'nodes': [], + 'password': 'ubuntu', + 'user': 'ubuntu', + 'release': 'trusty', + 'apt_sources': [], + 'ip_address': '', + 'boot_source': { + 'keyring_filename': "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg", + 'url': "http://maas.ubuntu.com/images/ephemeral-v2/releases/", + 'sections': { + '1': { + 'arches': 'amd64', + 'labels': 'release', + 'os': 'ubuntu', + 'release': 'xenial', + 'subarches': '*' + } + } + }, + 'settings': {'maas_name': '', + 'upstream_dns': '', + 'main_archive': "http://archive.ubuntu.com/ubuntu" + }, + 'virsh': {'rsa_priv_key': '/home/ubuntu/.ssh/id_rsa', + 'rsa_pub_key': '/home/ubuntu/.ssh/id_rsa.pub', + 'uri': '' + } + } + } + +opnfvlabcfg['opnfv'] = {'ext-port': '', + 'floating-ip-range': '', + 'dataNetwork': '', + 'ceph-disk': '/srv/', + 'storageNetwork': '', + 'interface-enable': '', + 'publicNetwork': '', + 'os-domain-name': '', + 'vip': {'rabbitmq': '', + 'dashboard': '', + 'glance': '', + 'keystone': '', + 'ceilometer': '', + 'mysql': '', + 'nova': '', + 'neutron': '', + 'heat': '', + 'cinder': ''} + } opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:maas/stable") @@ -66,39 +108,44 @@ opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:juju/stable") # lets modify the maas general settings: -updns = getFromDict(labcfg, ["lab","racks",0,"dns"]) -opnfvcfg["demo-maas"]["maas"]["settings"]["upstream_dns"]=updns +updns = get_from_dict(labcfg, ["lab", "racks", 0, "dns"]) +opnfvcfg["demo-maas"]["maas"]["settings"]["upstream_dns"] = updns -location = getFromDict(labcfg, ["lab","location"]) -rack = getFromDict(labcfg, ["lab","racks",0,"rack"]) -value=location+rack +location = get_from_dict(labcfg, ["lab", "location"]) +rack = get_from_dict(labcfg, ["lab", "racks", 0, "rack"]) +value = location+rack -opnfvcfg["demo-maas"]["maas"]["settings"]["maas_name"]=value -opnfvcfg["demo-maas"]["maas"]["name"]="opnfv-"+value +opnfvcfg["demo-maas"]["maas"]["settings"]["maas_name"] = value +opnfvcfg["demo-maas"]["maas"]["name"] = "opnfv-"+value -ethbrAdm="" -ethbrAdmin="" +ethbrAdm = "" +ethbrAdmin = "" -c=0 -y=0 -#z=0 +c = 0 +y = 0 +# z = 0 while c < len(labcfg["opnfv"]["spaces"]): - brtype = getFromDict(labcfg, ["opnfv","spaces",c,"type"]) - brname = getFromDict(labcfg, ["opnfv","spaces",c,"bridge"]) - brcidr = getFromDict(labcfg, ["opnfv","spaces",c,"cidr"]) + brtype = get_from_dict(labcfg, ["opnfv", "spaces", c, "type"]) + brname = get_from_dict(labcfg, ["opnfv", "spaces", c, "bridge"]) + brcidr = get_from_dict(labcfg, ["opnfv", "spaces", c, "cidr"]) # if brtype == "admin": - ethbrAdmin = getFromDict(labcfg, ["opnfv","spaces",c,"bridge"]) - brgway = getFromDict(labcfg, ["opnfv","spaces",c,"gateway"]) + ethbrAdmin = get_from_dict(labcfg, ["opnfv", "spaces", c, "bridge"]) + brgway = get_from_dict(labcfg, ["opnfv", "spaces", c, "gateway"]) tmpcidr = brcidr[:-4] - opnfvlabcfg["opnfv"]["admNetwork"]=tmpcidr+"2" - opnfvlabcfg["opnfv"]["admNetgway"]=brgway - - nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \ - "broadcast_ip": tmpcidr+"255", "router_ip": brgway,\ - "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\ - "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}} + opnfvlabcfg["opnfv"]["admNetwork"] = tmpcidr+"2" + opnfvlabcfg["opnfv"]["admNetgway"] = brgway + + nodegroup = {"device": "eth"+str(y), + "ip": tmpcidr+"5", + "subnet_mask": "255.255.255.0", + "broadcast_ip": tmpcidr+"255", + "router_ip": brgway, + "static_range": {"high": tmpcidr+"80", + "low": tmpcidr+"50"}, + "dynamic_range": {"high": tmpcidr+"250", + "low": tmpcidr+"81"}} ethbrAdm = ('auto lo\n' ' iface lo inet loopback\n\n' @@ -109,123 +156,163 @@ while c < len(labcfg["opnfv"]["spaces"]): ' gateway '+brgway+'\n' ' dns-nameservers '+updns+' '+tmpcidr+'5 127.0.0.1\n') - opnfvcfg['demo-maas']['maas']['ip_address']=tmpcidr+"5" - opnfvcfg['demo-maas']['maas']['interfaces'].append("bridge="+brname+",model=virtio") - opnfvcfg['demo-maas']['juju-bootstrap']['interfaces'].append("bridge="+brname+",model=virtio") + opnfvcfg['demo-maas']['maas']['ip_address'] = tmpcidr+"5" + opnfvcfg['demo-maas']['maas']['interfaces'].append( + "bridge="+brname+",model=virtio") + opnfvcfg['demo-maas']['juju-bootstrap']['interfaces'].append( + "bridge="+brname+",model=virtio") opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup) - y=y+1 + y = y+1 elif brtype: - opnfvcfg["demo-maas"]["maas"]["interfaces"].append("bridge="+brname+",model=virtio") - brgway = getFromDict(labcfg, ["opnfv","spaces",c,"gateway"]) + opnfvcfg["demo-maas"]["maas"]["interfaces"].append( + "bridge="+brname+",model=virtio") + brgway = get_from_dict(labcfg, ["opnfv", "spaces", c, "gateway"]) if brtype != "external": tmpcidr = brcidr[:-4] if brgway: - nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \ - "broadcast_ip": tmpcidr+"255", "management": 1, "router_ip": brgway,\ - "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\ - "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}} + nodegroup = {"device": "eth"+str(y), + "ip": tmpcidr+"5", + "subnet_mask": "255.255.255.0", + "broadcast_ip": tmpcidr+"255", + "management": 1, + "router_ip": brgway, + "static_range": {"high": tmpcidr+"80", + "low": tmpcidr+"50"}, + "dynamic_range": {"high": tmpcidr+"250", + "low": tmpcidr+"81"}} else: - nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \ - "broadcast_ip": tmpcidr+"255", "management": 1, \ - "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\ - "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}} - opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup) - ethbrAdm = (ethbrAdm+'\n' + nodegroup = {"device": "eth"+str(y), + "ip": tmpcidr+"5", + "subnet_mask": "255.255.255.0", + "broadcast_ip": tmpcidr+"255", + "management": 1, + "static_range": {"high": tmpcidr+"80", + "low": tmpcidr+"50"}, + "dynamic_range": {"high": tmpcidr+"250", + "low": tmpcidr+"81"}} + opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append( + nodegroup) + ethbrAdm = (ethbrAdm+'\n' 'auto eth'+str(y)+'\n' ' iface eth'+str(y)+' inet static\n' ' address '+tmpcidr+'5\n' ' netmask 255.255.255.0\n') - y=y+1 + y = y+1 if brtype == "public": - opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio") - opnfvlabcfg["opnfv"]["publicNetwork"]=brcidr + opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append( + "bridge="+brname+",model=virtio") + opnfvlabcfg["opnfv"]["publicNetwork"] = brcidr if brtype == "external": - ipaddress = getFromDict(labcfg, ["opnfv","spaces",c,"ipaddress"]) - ethbrAdm = (ethbrAdm+'\n' + ipaddress = get_from_dict(labcfg, ["opnfv", "spaces", + c, "ipaddress"]) + ethbrAdm = (ethbrAdm+'\n' 'auto eth'+str(y)+'\n' ' iface eth'+str(y)+' inet static\n' ' address '+ipaddress+'\n' ' netmask 255.255.255.0\n') - opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio") + opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append( + "bridge="+brname+",model=virtio") if brtype == "data": - opnfvlabcfg["opnfv"]["dataNetwork"]=brcidr + opnfvlabcfg["opnfv"]["dataNetwork"] = brcidr if brtype == "storage": - opnfvlabcfg["opnfv"]["storageNetwork"]=brcidr + opnfvlabcfg["opnfv"]["storageNetwork"] = brcidr - c=c+1 + c = c+1 # lets modify the maas general settings: value = get_ip_address(ethbrAdmin) value = "qemu+ssh://"+getpass.getuser()+"@"+value+"/system" -opnfvcfg['demo-maas']['maas']['virsh']['uri']=value -opnfvcfg['demo-maas']['maas']['network_config']=ethbrAdm +opnfvcfg['demo-maas']['maas']['virsh']['uri'] = value +opnfvcfg['demo-maas']['maas']['network_config'] = ethbrAdm if len(labcfg["lab"]["racks"][0]["nodes"]) < 1: print("looks like virtual deployment where nodes were not defined") opnfvcfg["demo-maas"]["maas"]["nodes"].remove() exit() -#lets insert the node details here: -c=0 -ifnamelist=[] +# lets insert the node details here: +c = 0 +ifnamelist = [] # while c < len(labcfg["lab"]["racks"][0]["nodes"]): - valuemac=[] + valuemac = [] y = 0 # setup value of name and tags accordigly noderoleslist = labcfg["lab"]["racks"][0]["nodes"][c]["roles"] noderoles = " ".join(noderoleslist) - valuetype = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "type"]) + valuetype = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", + c, "power", "type"]) namevalue = labcfg["lab"]["racks"][0]["nodes"][c]["name"] - valuearc = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "architecture"]) + valuearc = get_from_dict(labcfg, ["lab", "racks", 0, + "nodes", c, "architecture"]) # setup value of architecture if valuearc == "x86_64": - valuearc="amd64/generic" + valuearc = "amd64/generic" if valuetype == "wakeonlan": - macvalue = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "mac_address"]) - power={"type": "ether_wake", "mac_address": macvalue} + macvalue = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", + c, "power", "mac_address"]) + power = {"type": "ether_wake", "mac_address": macvalue} if valuetype == "ipmi": - valueaddr = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "address"]) - valueuser = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "user"]) - valuepass = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "pass"]) + valueaddr = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", c, + "power", "address"]) + valueuser = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", c, + "power", "user"]) + valuepass = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", c, + "power", "pass"]) valuedriver = "LAN_2_0" - power={"type": valuetype, "address": valueaddr,"user": valueuser,\ - "pass": valuepass, "driver": valuedriver} + power = {"type": valuetype, "address": valueaddr, "user": valueuser, + "pass": valuepass, "driver": valuedriver} + + opnfvcfg["demo-maas"]["maas"]["nodes"].append( + {"name": namevalue, + "architecture": valuearc, + "interfaces": [], + "mac_addresses": [], + "power": power, + 'tags': noderoles}) - opnfvcfg["demo-maas"]["maas"]["nodes"].append({"name": namevalue, \ - "architecture":valuearc,"interfaces":[],"mac_addresses":[],\ - "power":power,'tags':noderoles}) y = 0 while y < len(labcfg["lab"]["racks"][0]["nodes"][c]["nics"]): - valuespaces = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["spaces"] - valueifname = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["ifname"] + valuespaces = labcfg["lab"]["racks"][0]["nodes"][c][ + "nics"][y]["spaces"] + valueifname = labcfg["lab"]["racks"][0]["nodes"][c][ + "nics"][y]["ifname"] if "admin" not in valuespaces: ifnamelist += [valueifname] valueifmac = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["mac"][0] valuemac += labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["mac"] - opnfvcfg["demo-maas"]["maas"]["nodes"][c]["interfaces"]\ - .append({"name":valueifname,"mac_address":valueifmac,"mode": "auto"}) - - y=y+1 + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["interfaces"].append( + {"name": valueifname, + "mac_address": valueifmac, + "mode": "auto"}) + y = y+1 if valueifmac: - opnfvcfg["demo-maas"]["maas"]["nodes"][c]['mac_addresses']=valuemac - - c=c+1 - -opnfvlabcfg["opnfv"]["floating-ip-range"]=labcfg["lab"]["racks"][0]["floating-ip-range"] -opnfvlabcfg["opnfv"]["ext-port"]=labcfg["lab"]["racks"][0]["ext-port"] -opnfvlabcfg["opnfv"]["ceph-disk"]=labcfg["opnfv"]["storage"][0]["disk"] -opnfvlabcfg["opnfv"]["interface-enable"]=",".join(list(set(ifnamelist))) - -#setup vip addresss for HA -opnfvlabcfg["opnfv"]["vip"]["rabbitmq"] = opnfvlabcfg["opnfv"]["admNetwork"]+"0" -opnfvlabcfg["opnfv"]["vip"]["dashboard"] = opnfvlabcfg["opnfv"]["admNetwork"]+"1" + opnfvcfg["demo-maas"]["maas"]["nodes"][c]['mac_addresses'] = valuemac + + c = c+1 + +opnfvlabcfg["opnfv"]["floating-ip-range"] =\ + labcfg["lab"]["racks"][0]["floating-ip-range"] +opnfvlabcfg["opnfv"]["ext-port"] =\ + labcfg["lab"]["racks"][0]["ext-port"] +opnfvlabcfg["opnfv"]["ceph-disk"] =\ + labcfg["opnfv"]["storage"][0]["disk"] +opnfvlabcfg["opnfv"]["interface-enable"] =\ + ",".join(list(set(ifnamelist))) + +# setup vip addresss for HA +opnfvlabcfg["opnfv"]["vip"]["rabbitmq"] =\ + opnfvlabcfg["opnfv"]["admNetwork"]+"0" +opnfvlabcfg["opnfv"]["vip"]["dashboard"] =\ + opnfvlabcfg["opnfv"]["admNetwork"]+"1" opnfvlabcfg["opnfv"]["vip"]["glance"] = opnfvlabcfg["opnfv"]["admNetwork"]+"2" -opnfvlabcfg["opnfv"]["vip"]["keystone"] = opnfvlabcfg["opnfv"]["admNetwork"]+"3" -opnfvlabcfg["opnfv"]["vip"]["ceilometer"] = opnfvlabcfg["opnfv"]["admNetwork"]+"4" +opnfvlabcfg["opnfv"]["vip"]["keystone"] =\ + opnfvlabcfg["opnfv"]["admNetwork"]+"3" +opnfvlabcfg["opnfv"]["vip"]["ceilometer"] =\ + opnfvlabcfg["opnfv"]["admNetwork"]+"4" opnfvlabcfg["opnfv"]["vip"]["mysql"] = opnfvlabcfg["opnfv"]["admNetwork"]+"5" opnfvlabcfg["opnfv"]["vip"]["nova"] = opnfvlabcfg["opnfv"]["admNetwork"]+"6" opnfvlabcfg["opnfv"]["vip"]["neutron"] = opnfvlabcfg["opnfv"]["admNetwork"]+"7" @@ -235,17 +322,18 @@ opnfvlabcfg["opnfv"]["vip"]["cinder"] = opnfvlabcfg["opnfv"]["admNetwork"]+"9" osdomname = labcfg["lab"]["racks"][0]["osdomainname"] if osdomname: - opnfvlabcfg["opnfv"]["os-domain-name"] = labcfg["lab"]["racks"][0]["osdomainname"] + opnfvlabcfg["opnfv"]["os-domain-name"] =\ + labcfg["lab"]["racks"][0]["osdomainname"] opnfvlabcfg["opnfv"]["domain"] = labcfg["lab"]["racks"][0]["osdomainname"] -opnfvlabcfg["opnfv"]["ext_port"]=labcfg["lab"]["racks"][0]["ext-port"] -opnfvlabcfg["opnfv"]["units"]=len(labcfg["lab"]["racks"][0]["nodes"]) -opnfvlabcfg["opnfv"]["admin_password"]="openstack" -opnfvlabcfg["opnfv"]["storage"]=labcfg["opnfv"]["storage"] -opnfvlabcfg["opnfv"]["spaces"]=labcfg["opnfv"]["spaces"] +opnfvlabcfg["opnfv"]["ext_port"] = labcfg["lab"]["racks"][0]["ext-port"] +opnfvlabcfg["opnfv"]["units"] = len(labcfg["lab"]["racks"][0]["nodes"]) +opnfvlabcfg["opnfv"]["admin_password"] = "openstack" +opnfvlabcfg["opnfv"]["storage"] = labcfg["opnfv"]["storage"] +opnfvlabcfg["opnfv"]["spaces"] = labcfg["opnfv"]["spaces"] with open('deployment.yaml', 'wa') as opnfvf: - yaml.dump(opnfvcfg, opnfvf, default_flow_style=False) + yaml.dump(opnfvcfg, opnfvf, default_flow_style=False) with open('deployconfig.yaml', 'wa') as opnfvf: - yaml.dump(opnfvlabcfg, opnfvf, default_flow_style=False) + yaml.dump(opnfvlabcfg, opnfvf, default_flow_style=False) diff --git a/ci/genBundle.py b/ci/genBundle.py index 8c7d3a3c..ffa1119d 100644 --- a/ci/genBundle.py +++ b/ci/genBundle.py @@ -1,84 +1,103 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +""" +This script generates a juju deployer bundle based on +scenario name, and lab config file. + +Parameters: + -s, --scenario : scenario name + -l, --lab : lab config file +""" + from optparse import OptionParser from jinja2 import Environment, FileSystemLoader -from pprint import pprint as pp import os import random import yaml -import sys, traceback +import sys -## -## Parse parameters -## +# +# Parse parameters +# parser = OptionParser() -parser.add_option("-s", "--scenario", dest="scenario", help ="scenario name") -parser.add_option("-l", "--lab", dest="lab", help ="lab config file") +parser.add_option("-s", "--scenario", dest="scenario", help="scenario name") +parser.add_option("-l", "--lab", dest="lab", help="lab config file") (options, args) = parser.parse_args() scenario = options.scenario labconfig_file = options.lab -## -## Set Path and configs path -## +# +# Set Path and configs path +# scenarioconfig_file = 'default_deployment_config.yaml' # Capture our current directory TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/bundle_tpl' -## -## Prepare variables -## +# +# Prepare variables +# # Prepare a storage for passwords passwords_store = dict() -## -## Local Functions -## +# +# Local Functions +# + def load_yaml(filepath): + """Load YAML file""" with open(filepath, 'r') as stream: try: return yaml.load(stream) except yaml.YAMLError as exc: print(exc) -## -## Templates functions -## +# +# Templates functions +# + def unit_qty(): + """Return quantity of units to deploy""" global config if config['os']['ha']['mode'] == 'ha': return config['os']['ha']['cluster_size'] else: return 1 + def unit_ceph_qty(): + """Return size of the ceph cluster""" global config if config['os']['ha']['mode'] == 'ha': return config['os']['ha']['cluster_size'] else: return 2 -def to_select( qty = False ): + +def to_select(qty=False): + """Return a random list of machines numbers to deploy""" global config if not qty: - qty = config['os']['ha']['cluster_size'] if config['os']['ha']['mode'] == 'ha' else 1 + qty = config['os']['ha']['cluster_size'] if \ + config['os']['ha']['mode'] == 'ha' else 1 if config['os']['ha']['mode'] == 'ha': - return random.sample(range(0,config['opnfv']['units']), qty ) + return random.sample(range(0, config['opnfv']['units']), qty) else: - return random.sample(range(0,2),qty ) + return random.sample(range(0, 2), qty) + def get_password(key, length=16, special=False): + """Return a new random password or a already created one""" global passwords_store if key not in passwords_store.keys(): alphabet = "abcdefghijklmnopqrstuvwxyz" upperalphabet = alphabet.upper() - char_list = alphabet + upperalphabet + char_list = alphabet + upperalphabet + '0123456789' pwlist = [] if special: char_list += "+-,;./:?!*" @@ -88,16 +107,16 @@ def get_password(key, length=16, special=False): passwords_store[key] = "".join(pwlist) return passwords_store[key] -## -## Config import -## +# +# Config import +# -#Load scenario Config +# Load scenario Config config = load_yaml(scenarioconfig_file) -#Load lab Config +# Load lab Config config.update(load_yaml(labconfig_file)) -#We transform array to hash for an easier work +# We transform array to hash for an easier work config['opnfv']['spaces_dict'] = dict() for space in config['opnfv']['spaces']: config['opnfv']['spaces_dict'][space['type']] = space @@ -105,9 +124,9 @@ config['opnfv']['storage_dict'] = dict() for storage in config['opnfv']['storage']: config['opnfv']['storage_dict'][storage['type']] = storage -## -## Parse scenario name -## +# +# Parse scenario name +# # Set default scenario name if not scenario: @@ -127,9 +146,9 @@ except ValueError as err: '"os---[-]" format') sys.exit(1) -## -## Update config with scenario name -## +# +# Update config with scenario name +# # change ha mode config['os']['ha']['mode'] = hamode @@ -169,9 +188,9 @@ if 'trusty' in extra: # pp(config) -## -## Transform template to bundle.yaml according to config -## +# +# Transform template to bundle.yaml according to config +# # Create the jinja2 environment. env = Environment(loader=FileSystemLoader(TPL_DIR),