sleep 20
done
+ maas $PROFILE tags create name='bootstrap'
+ maas $PROFILE tags create name='compute'
+ maas $PROFILE tags create name='control'
+ maas $PROFILE tags create name='storage'
+}
+
+enablesubnetand dhcp(){
+
+ SUBNET_PREFIX="192.168.122"
+ SUBNET_CIDR="($SUBNET_PREFIX).0/24"
+
IP_STATIC_RANGE_LOW="192.168.122.1"
IP_STATIC_RANGE_HIGH="192.168.122.49"
maas $PROFILE ipranges create type=reserved \
comment='This is a reserved range'
IP_DYNAMIC_RANGE_LOW="192.168.122.50"
- IP_DYNAMIC_RANGE_HIGH="192.168.122.80"
+ IP_DYNAMIC_RANGE_HIGH="192.168.122.240"
maas $PROFILE ipranges create type=dynamic \
start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
comment='This is a reserved dynamic range'
+
FABRIC_ID=$(maas $PROFILE subnet read $SUBNET_CIDR \
| grep fabric | cut -d ' ' -f 10 | cut -d '"' -f 2)
maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER
- SUBNET_CIDR="192.168.122.0/24"
MY_GATEWAY="192.168.122.1"
MY_NAMESERVER=192.168.122.1
maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$MY_GATEWAY
maas $PROFILE subnet update $SUBNET_CIDR dns_servers=$MY_NAMESERVER
- maas $PROFILE tags create name='bootstrap'
- maas $PROFILE tags create name='compute'
- maas $PROFILE tags create name='control'
- maas $PROFILE tags create name='storage'
+
+}
+
+## derived from https://gist.github.com/epiloque/8cf512c6d64641bde388
+## works for arrays of hashes, as long as the hashes do not have arrays
+parse_yaml2() {
+ local prefix=$2
+ local s
+ local w
+ local fs
+ s='[[:space:]]*'
+ w='[a-zA-Z0-9_]*'
+ fs="$(echo @|tr @ '\034')"
+ sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
+ -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
+ awk -F"$fs" '{
+ indent = length($1)/2;
+ if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
+ vname[indent] = $2;
+ for (i in vname) {if (i > indent) {delete vname[i]}}
+ if (length($3) > 0) {
+ vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
+ printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
+ }
+ }' | sed 's/_=/+=/g'
}
addnodes(){
--- /dev/null
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+This script generates a maas deployer config based on lab config file.
+
+Parameters:
+ -l, --lab : lab config file
+"""
+
+from optparse import OptionParser
+from jinja2 import Environment, FileSystemLoader
+from distutils.version import LooseVersion, StrictVersion
+import os
+import subprocess
+import yaml
+from pprint import pprint as pp
+import socket
+import fcntl
+import struct
+
+#
+# Parse parameters
+#
+
+parser = OptionParser()
+parser.add_option("-l", "--lab", dest="lab", help="lab config file")
+(options, args) = parser.parse_args()
+labconfig_file = options.lab
+
+#
+# Set Path and configs path
+#
+
+# Capture our current directory
+jujuver = subprocess.check_output(["juju", "--version"])
+
+if LooseVersion(jujuver) >= LooseVersion('2'):
+ TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl/maas_tpl'
+else:
+ TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl/maas2/maas_tpl'
+
+HOME = os.environ['HOME']
+USER = os.environ['USER']
+
+#
+# Prepare variables
+#
+
+# Prepare a storage for passwords
+passwords_store = dict()
+
+#
+# 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)
+
+
+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
+#
+
+def installMAAS():
+ subprocess.call(["echo", i], shell=True)
+
+def configMAAS():
+
+
+# Create the jinja2 environment.
+env = Environment(loader=FileSystemLoader(TPL_DIR),
+ trim_blocks=True)
+template = env.get_template('deployment.yaml')
+
+# Render the template
+output = template.render(**config)
+
+# Check output syntax
+try:
+ yaml.load(output)
+except yaml.YAMLError as exc:
+ print(exc)
+
+# print output
+print(output)