From 491d268009938eb6ce21ad4636bdd5130935f011 Mon Sep 17 00:00:00 2001 From: Narinder Gupta Date: Tue, 22 Nov 2016 00:08:26 -0600 Subject: modified to accomodate the MAAS 2.0 Change-Id: Id17ba35d82103b082136b91a694bf3a6f18d9c8d Signed-off-by: Narinder Gupta --- ci/03-maasdeploy.sh | 44 +++++++++++++++++++---- ci/depMAAS.py | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 ci/depMAAS.py diff --git a/ci/03-maasdeploy.sh b/ci/03-maasdeploy.sh index 3ee955df..1e5fcf69 100755 --- a/ci/03-maasdeploy.sh +++ b/ci/03-maasdeploy.sh @@ -207,6 +207,17 @@ configuremaas(){ 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 \ @@ -214,11 +225,12 @@ configuremaas(){ 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) @@ -226,16 +238,36 @@ configuremaas(){ 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= 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) -- cgit 1.2.3-korg