Code Review
/
joid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
modfied to convert integer to float as default is integer
[joid.git]
/
ci
/
genBundle.py
diff --git
a/ci/genBundle.py
b/ci/genBundle.py
index
8c7d3a3
..
499cd63
100644
(file)
--- a/
ci/genBundle.py
+++ b/
ci/genBundle.py
@@
-1,84
+1,106
@@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#!/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 optparse import OptionParser
from jinja2 import Environment, FileSystemLoader
-from pprint import pprint as pp
import os
import random
import yaml
import os
import random
import yaml
-import sys
, traceback
+import sys
-#
#
-#
#
Parse parameters
-#
#
+#
+# Parse parameters
+#
parser = OptionParser()
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
(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
scenarioconfig_file = 'default_deployment_config.yaml'
# Capture our current directory
-TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/bundle_tpl'
+TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/
config_tpl/
bundle_tpl'
-#
#
-#
#
Prepare variables
-#
#
+#
+# Prepare variables
+#
# Prepare a storage for passwords
passwords_store = dict()
# Prepare a storage for passwords
passwords_store = dict()
-##
-## Local Functions
-##
+#
+# Local Functions
+#
+
def load_yaml(filepath):
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)
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():
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
global config
if config['os']['ha']['mode'] == 'ha':
return config['os']['ha']['cluster_size']
else:
return 1
+
def unit_ceph_qty():
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:
global config
if config['os']['ha']['mode'] == 'ha':
return config['os']['ha']['cluster_size']
else:
- return 2
+ if config['opnfv']['units'] >= 3:
+ 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:
global config
if not qty:
- 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 )
+ qty = config['os']['ha']['cluster_size'] if \
+ config['os']['ha']['mode'] == 'ha' else 1
+ if config['os']['hyperconverged']:
+ return random.sample(range(0, config['opnfv']['units']), qty)
else:
else:
- return random.sample(range(0,2),qty )
+ return random.sample(range(0, qty), qty)
+
def get_password(key, length=16, special=False):
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()
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 += "+-,;./:?!*"
pwlist = []
if special:
char_list += "+-,;./:?!*"
@@
-88,16
+110,16
@@
def get_password(key, length=16, special=False):
passwords_store[key] = "".join(pwlist)
return passwords_store[key]
passwords_store[key] = "".join(pwlist)
return passwords_store[key]
-#
#
-#
#
Config import
-#
#
+#
+# Config import
+#
-#Load scenario Config
+#
Load scenario Config
config = load_yaml(scenarioconfig_file)
config = load_yaml(scenarioconfig_file)
-#Load lab Config
+#
Load lab Config
config.update(load_yaml(labconfig_file))
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
config['opnfv']['spaces_dict'] = dict()
for space in config['opnfv']['spaces']:
config['opnfv']['spaces_dict'][space['type']] = space
@@
-105,9
+127,9
@@
config['opnfv']['storage_dict'] = dict()
for storage in config['opnfv']['storage']:
config['opnfv']['storage_dict'][storage['type']] = storage
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:
# Set default scenario name
if not scenario:
@@
-127,9
+149,9
@@
except ValueError as err:
'"os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]" format')
sys.exit(1)
'"os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]" format')
sys.exit(1)
-#
#
-#
#
Update config with scenario name
-#
#
+#
+# Update config with scenario name
+#
# change ha mode
config['os']['ha']['mode'] = hamode
# change ha mode
config['os']['ha']['mode'] = hamode
@@
-154,6
+176,8
@@
if 'bgpvpn' in features:
config['os']['network']['bgpvpn'] = True
if 'odll3' in features:
config['os']['network']['odll3'] = True
config['os']['network']['bgpvpn'] = True
if 'odll3' in features:
config['os']['network']['odll3'] = True
+if 'dishypcon' in features:
+ config['os']['hyperconverged'] = False
# Set beta option from extra
if 'publicapi' in extra:
# Set beta option from extra
if 'publicapi' in extra:
@@
-166,12
+190,12
@@
if 'trusty' in extra:
config['ubuntu']['release'] = 'trusty'
if 'liberty' in extra:
config['os']['release'] = 'liberty'
config['ubuntu']['release'] = 'trusty'
if 'liberty' in extra:
config['os']['release'] = 'liberty'
+if 'dishypcon' in extra:
+ config['os']['hyperconverged'] = False
-# 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),
# Create the jinja2 environment.
env = Environment(loader=FileSystemLoader(TPL_DIR),
@@
-185,4
+209,13
@@
env.globals.update(unit_ceph_qty=unit_ceph_qty)
env.globals.update(to_select=to_select)
# Render the template
env.globals.update(to_select=to_select)
# Render the template
-print(template.render(**config))
+output = template.render(**config)
+
+# Check output syntax
+try:
+ yaml.load(output)
+except yaml.YAMLError as exc:
+ print(exc)
+
+# print output
+print(output)