From 2ee0a05504d8e9f48ea25652e8aba518fb734964 Mon Sep 17 00:00:00 2001
From: Narinder Gupta <narinder.gupta@canonical.com>
Date: Tue, 17 May 2016 18:47:10 -0500
Subject: modified to support the custom lab where data will be provided fom
 labconfig.yaml file.

Change-Id: Ic6ff690175de1029909b89590226847b78b6e437
Signed-off-by: Narinder Gupta <narinder.gupta@canonical.com>
---
 ci/02-maasdeploy.sh     | 50 ++++++++++++++++++++++++++++++++++++++----------
 ci/deploy.py            | 51 ++++++++++++++++++++++++++++---------------------
 ci/maas/deployment.yaml | 20 -------------------
 3 files changed, 69 insertions(+), 52 deletions(-)

(limited to 'ci')

diff --git a/ci/02-maasdeploy.sh b/ci/02-maasdeploy.sh
index d5691543..131e7056 100755
--- a/ci/02-maasdeploy.sh
+++ b/ci/02-maasdeploy.sh
@@ -4,8 +4,44 @@ set -ex
 
 virtinstall=0
 
+#install the packages needed
+sudo apt-add-repository ppa:maas-deployers/stable -y
+sudo apt-add-repository ppa:juju/stable -y
+sudo apt-add-repository ppa:maas/stable -y
+sudo apt-add-repository cloud-archive:liberty -y
+sudo apt-get update -y
+sudo apt-get dist-upgrade -y
+sudo apt-get install openssh-server git maas-deployer juju juju-deployer maas-cli python-pip python-openstackclient gsutil -y
+
 cp maas/deployment.yaml ./deployment.yaml
-cp ../labconfig/intel/pod6/labconfig.yaml ./
+
+#first parameter should be custom and second should be either 
+# absolute location of file (including file name) or url of the 
+# file to download.
+
+if [ "$1" == "custom" ]; then
+    if [ -e $2 ]; then
+        cp $2 ./labconfig.yaml || true
+        python deploy.py
+    else
+        wget $2 -t 3 -T 10 -O ./labconfig.yaml || true
+        count=`wc -l labconfig.yaml  | cut -d " " -f 1`
+
+        if [ $count -lt 10 ]; then
+            rm -rf labconfig.yaml
+        else
+            python deploy.py
+        fi
+    fi
+
+    if [ ! -e ./labconfig.yaml ]; then
+        virtinstall=1
+        cp ../labconfig/default/labconfig.yaml ./
+        python deploy.py
+    fi
+fi
+
+exit 1
 
 case "$1" in
     'intelpod5' )
@@ -19,7 +55,9 @@ case "$1" in
         python deploy.py
         ;;
     'intelpod9' )
-        cp maas/intel/pod9/deployment.yaml ./deployment.yaml
+        cp ../labconfig/intel/pod6/labconfig.yaml ./
+        #to be removed later once converted for all labs.
+        python deploy.py
         ;;
     'orangepod1' )
         cp maas/orange/pod1/deployment.yaml ./deployment.yaml
@@ -78,14 +116,6 @@ sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ |
 sudo virsh pool-start default || true
 sudo virsh pool-autostart default || true
 
-sudo apt-add-repository ppa:maas-deployers/stable -y
-sudo apt-add-repository ppa:juju/stable -y
-sudo apt-add-repository ppa:maas/stable -y
-sudo apt-add-repository cloud-archive:liberty -y
-sudo apt-get update -y
-sudo apt-get dist-upgrade -y
-sudo apt-get install openssh-server git maas-deployer juju juju-deployer maas-cli python-pip python-openstackclient gsutil -y
-
 # To avoid problem between apiclient/maas_client and apiclient from google
 # we remove the package google-api-python-client from yardstick installer
 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
diff --git a/ci/deploy.py b/ci/deploy.py
index a4e23031..83992b42 100644
--- a/ci/deploy.py
+++ b/ci/deploy.py
@@ -26,9 +26,6 @@ def setInDict(dataDict, mapList, value):
 def getFromDict(dataDict, mapList):
     return reduce(lambda d, k: d[k], mapList, dataDict)
 
-if len(labcfg["labconfig"]["nodes"]) < 3:
-    print("minimum three nodes are needed for opnfv architecture deployment")
-    exit() 
 
 # lets modify the maas general settings:
 
@@ -52,21 +49,23 @@ while c < len(labcfg["labconfig"]["bridges"]):
     brname = getFromDict(labcfg, ["labconfig","bridges",c,"bridge"])
     brcidr = getFromDict(labcfg, ["labconfig","bridges",c,"cidr"])
     if brtype == "admin":
+        if c > 0:
+            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append({})
         ethbrAdmin = getFromDict(labcfg, ["labconfig","bridges",c,"bridge"])
         brgway = getFromDict(labcfg, ["labconfig","bridges",c,"gateway"])
         tmpcidr = brcidr[:-4]
         setInDict(opnfvcfg, ["demo-maas", "maas", "ip_address"], tmpcidr+"5")
         opnfvcfg["demo-maas"]["maas"]["interfaces"][y] = "bridge="+brname+",model=virtio" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["device"] = "eth"+str(y) 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["ip"] = tmpcidr+"5" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["subnet_mask"] = "255.255.255.0" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["broadcast_ip"] = tmpcidr+"255" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["router_ip"] = brgway 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["static_range"]["low"] = tmpcidr+"50" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["static_range"]["high"] = tmpcidr+"80" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["dynamic_range"]["low"] = tmpcidr+"81" 
-        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["dynamic_range"]["high"] = tmpcidr+"250" 
+
+        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"}}
+
+        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y] = nodegroup
+
         opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"][z] = "bridge="+brname+",model=virtio" 
+
         ethbrAdm = ('auto lo\n'
                     '    iface lo inet loopback\n\n'
                     'auto eth'+str(y)+'\n'
@@ -81,18 +80,21 @@ while c < len(labcfg["labconfig"]["bridges"]):
         opnfvcfg["demo-maas"]["maas"]["interfaces"].append("bridge="+brname+",model=virtio")
         brgway = getFromDict(labcfg, ["labconfig","bridges",c,"gateway"])
         if brtype != "external":
+            if c > 0:
+                opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append({})
             tmpcidr = brcidr[:-4]
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["device"] = "eth"+str(y) 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["ip"] = tmpcidr+"5" 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["subnet_mask"] = "255.255.255.0" 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["broadcast_ip"] = tmpcidr+"255" 
             if brgway:
-                opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["router_ip"] = brgway 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["management"] = 1 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["static_range"]["low"] = tmpcidr+"20" 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["static_range"]["high"] = tmpcidr+"150" 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["dynamic_range"]["low"] = tmpcidr+"151" 
-            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"][y]["dynamic_range"]["high"] = tmpcidr+"200" 
+                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"][y] = nodegroup
             ethbrAdm  = (ethbrAdm+'\n'
                         'auto eth'+str(y)+'\n'
                         '    iface eth'+str(y)+' inet static\n'
@@ -122,6 +124,11 @@ value = get_ip_address(ethbrAdmin)
 value = "qemu+ssh://"+getpass.getuser()+"@"+value+"/system"
 setInDict(opnfvcfg, ["demo-maas", "maas", "virsh", "uri"], value)
 
+if len(labcfg["labconfig"]["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
 
diff --git a/ci/maas/deployment.yaml b/ci/maas/deployment.yaml
index 87eb9e25..e7df95c6 100755
--- a/ci/maas/deployment.yaml
+++ b/ci/maas/deployment.yaml
@@ -33,26 +33,6 @@ demo-maas:
     network_config: 
     node_group_ifaces:
     - broadcast_ip: 
-      dynamic_range:
-        high: 
-        low: 
-      static_range:
-        high: 
-        low: 
-    - broadcast_ip: 
-      dynamic_range:
-        high: 
-        low: 
-      static_range:
-        high: 
-        low: 
-    - broadcast_ip: 
-      dynamic_range:
-        high: 
-        low: 
-      static_range:
-        high: 
-        low: 
     nodes:
     - name: 
     password: ubuntu
-- 
cgit 1.2.3-korg