diff options
author | Narinder Gupta <narinder.gupta@canonical.com> | 2016-05-17 19:55:56 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2016-05-17 19:55:56 +0000 |
commit | a72a52456135c2e298feeef6d75745ed657216c5 (patch) | |
tree | 5c0dd4ebf42e010dfd3255f969214056e7ed814f /ci | |
parent | 07437a3f83edef9102b526961004b64f93bb9e8b (diff) | |
parent | 943a83ac552121d599476661634d250a44be590b (diff) |
Merge "added new labconfig file for each lab also the default config file. User can send the url also to deployment.yaml file to the script. If can not copy the file then will use the file from labconfig directory."
Diffstat (limited to 'ci')
-rwxr-xr-x | ci/02-maasdeploy.sh | 17 | ||||
-rw-r--r-- | ci/deploy.py | 173 | ||||
-rwxr-xr-x | ci/maas/deployment.yaml | 94 |
3 files changed, 247 insertions, 37 deletions
diff --git a/ci/02-maasdeploy.sh b/ci/02-maasdeploy.sh index be978667..20357803 100755 --- a/ci/02-maasdeploy.sh +++ b/ci/02-maasdeploy.sh @@ -4,12 +4,17 @@ set -ex virtinstall=0 +cp maas/deployment.yaml ./deployment.yaml +cp ../labconfig/intel/pod6/labconfig.yaml ./ + case "$1" in 'intelpod5' ) cp maas/intel/pod5/deployment.yaml ./deployment.yaml ;; 'intelpod6' ) - cp maas/intel/pod6/deployment.yaml ./deployment.yaml + cp ../labconfig/intel/pod6/labconfig.yaml ./ + #to be removed later once converted for all labs. + python deploy.py ;; 'intelpod9' ) cp maas/intel/pod9/deployment.yaml ./deployment.yaml @@ -39,9 +44,6 @@ case "$1" in ;; esac -#just make sure the ssh keys added into maas for the current user -sed --i "s@/home/ubuntu@$HOME@g" ./deployment.yaml -sed --i "s@qemu+ssh://ubuntu@qemu+ssh://$USER@g" ./deployment.yaml #make sure no password asked during the deployment. @@ -145,6 +147,13 @@ crnodevlanint() { done } +#convert labconfig file to deployment.yaml to consume by MAAS. +#python deploy.py + +#just make sure the ssh keys added into maas for the current user +sed --i "s@/home/ubuntu@$HOME@g" ./deployment.yaml +sed --i "s@qemu+ssh://ubuntu@qemu+ssh://$USER@g" ./deployment.yaml + sudo maas-deployer -c deployment.yaml -d --force sudo chown $USER:$USER environments.yaml diff --git a/ci/deploy.py b/ci/deploy.py index d52bd609..c1a714d8 100644 --- a/ci/deploy.py +++ b/ci/deploy.py @@ -1,12 +1,24 @@ import yaml import pprint - -with open('example.yaml', 'r') as f: - doc = yaml.load(f) -txt = doc["nodes"][0]["power"] - -with open('deployment.yaml', 'r') as ft: - doc1 = yaml.load(ft) +import socket +import fcntl +import struct +import os +import getpass + +def get_ip_address(ifname): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', ifname[:15]) + )[20:24]) + +with open('labconfig.yaml', 'r') as labf: + labcfg = yaml.load(labf) + +with open('deployment.yaml', 'r') as opnfvf: + opnfvcfg = yaml.load(opnfvf) def setInDict(dataDict, mapList, value): getFromDict(dataDict, mapList[:-1])[mapList[-1]] = value @@ -14,46 +26,141 @@ def setInDict(dataDict, mapList, value): def getFromDict(dataDict, mapList): return reduce(lambda d, k: d[k], mapList, dataDict) -if len(doc["nodes"]) > len(doc1["demo-maas"]["maas"]["nodes"]): - exit 0 +if len(labcfg["labconfig"]["nodes"]) < 3: + print("minimum three nodes are needed for opnfv architecture deployment") + exit() + +# lets modify the maas general settings: + +updns = getFromDict(labcfg, ["labconfig","labsettings","upstream_dns"]) +setInDict(opnfvcfg, ["demo-maas", "maas", "settings", "upstream_dns"], updns) +value = getFromDict(labcfg, ["labconfig","lab_location"]) +setInDict(opnfvcfg, ["demo-maas", "maas", "settings", "maas_name"], value) +setInDict(opnfvcfg, ["demo-maas", "maas", "name"], "opnfv-"+value) + +#lets figure out the interfaces data + +ethbrAdm="" +ethbrAdmin="" c=0 -while c < len(doc["nodes"]): +y=0 +z=0 + +while c < len(labcfg["labconfig"]["bridges"]): + brtype = getFromDict(labcfg, ["labconfig","bridges",c,"type"]) + brname = getFromDict(labcfg, ["labconfig","bridges",c,"bridge"]) + brcidr = getFromDict(labcfg, ["labconfig","bridges",c,"cidr"]) + if brtype == "admin": + 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" + 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' + ' iface eth'+str(y)+' inet static\n' + ' address '+tmpcidr+'5\n' + ' netmask 255.255.255.0\n' + ' gateway '+brgway+'\n' + ' dns-nameservers '+updns+' '+tmpcidr+'5 127.0.0.1\n') + z=z+1 + y=y+1 + elif brtype: + opnfvcfg["demo-maas"]["maas"]["interfaces"].append("bridge="+brname+",model=virtio") + brgway = getFromDict(labcfg, ["labconfig","bridges",c,"gateway"]) + if brtype != "external": + 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" + 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') + if brtype == "public": + opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio") + z=z+1 + if brtype == "external": + ipaddress = getFromDict(labcfg, ["labconfig","bridges",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") + z=z+1 + y=y+1 + - value = getFromDict(doc, ["nodes",c, "name"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "name"], value) + c=c+1 - value = getFromDict(doc, ["nodes",c, "tags"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "tags"], value) +setInDict(opnfvcfg, ["demo-maas", "maas", "network_config"], ethbrAdm) - value = getFromDict(doc, ["nodes",c, "arch"]) - if value == "x86_64": - value="amd64/generic" - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "architecture"], value) +# lets modify the maas general settings: +value = get_ip_address(ethbrAdmin) +value = "qemu+ssh://"+getpass.getuser()+"@"+value+"/system" +setInDict(opnfvcfg, ["demo-maas", "maas", "virsh", "uri"], value) - value = getFromDict(doc, ["nodes",c, "mac_address"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "mac_addresses"], value) +#lets insert the node details here: +c=0 - value = getFromDict(doc, ["nodes",c, "power", "type"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "power", "type"], value) +while c < len(labcfg["labconfig"]["nodes"]): + # setup value of name and tags accordigly + value = getFromDict(labcfg, ["labconfig","nodes",c, "type"]) + namevalue = "node" + str(c+1) + "-" + value + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["name"] = namevalue + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["tags"] = value + # setup value of architecture + value = getFromDict(labcfg, ["labconfig","nodes",c, "architecture"]) + if value == "x86_64": + value="amd64/generic" + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["architecture"] = value + + # setup mac_addresses + value = getFromDict(labcfg, ["labconfig","nodes",c, "pxe_mac_address"]) + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["mac_addresses"] = value + + value = getFromDict(labcfg, ["labconfig","nodes",c, "power", "type"]) + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["power"]["type"] = value if value == "wakeonlan": - value = getFromDict(doc, ["nodes",c, "power", "mac_address"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "power", "mac_address"], value) + value = getFromDict(labcfg, ["labconfig","nodes",c, "power", "mac_address"]) + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["power"]["mac_address"] = value if value == "ipmi": - value = getFromDict(doc, ["nodes",c, "power", "address"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "power", "address"], value) - - value = getFromDict(doc, ["nodes",c, "power", "user"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "power", "user"], value) + value = getFromDict(labcfg, ["labconfig","nodes",c, "power", "address"]) + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["power"]["address"] = value + value = getFromDict(labcfg, ["labconfig","nodes",c, "power", "user"]) + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["power"]["user"] = value + value = getFromDict(labcfg, ["labconfig","nodes",c, "power", "pass"]) + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["power"]["pass"] = value + opnfvcfg["demo-maas"]["maas"]["nodes"][c]["power"]["driver"] = "LAN_2_0" - value = getFromDict(doc, ["nodes",c, "power", "pass"]) - setInDict(doc1, ["demo-maas", "maas", "nodes", c, "power", "pass"], value) c=c+1 -with open('deployment.yaml', 'w') as ft: - yaml.dump(doc1, ft) +with open('deployment.yaml', 'w') as opnfvf: + yaml.dump(opnfvcfg, opnfvf, default_flow_style=False) diff --git a/ci/maas/deployment.yaml b/ci/maas/deployment.yaml new file mode 100755 index 00000000..82f49b81 --- /dev/null +++ b/ci/maas/deployment.yaml @@ -0,0 +1,94 @@ +demo-maas: + juju-bootstrap: + arch: amd64 + disk_size: 120G + interfaces: + - bridge=brAdm,model=virtio + memory: 4096 + name: bootstrap + pool: default + vcpus: 4 + maas: + apt_http_proxy: null + apt_sources: + - ppa:maas/stable + - ppa:juju/stable + arch: amd64 + boot_source: + keyring_filename: /usr/share/keyrings/ubuntu-cloudimage-keyring.gpg + selections: + 1: + arches: amd64 + labels: release + os: ubuntu + release: xenial + subarches: '*' + url: http://maas.ubuntu.com/images/ephemeral-v2/releases/ + disk_size: 160G + interfaces: + - bridge=brAdm,model=virtio + ip_address: + memory: 4096 + name: opnfv-intelpod6 + 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: + - architecture: + mac_addresses: + - + power: + address: + - architecture: + mac_addresses: + - + power: + address: + - architecture: + mac_addresses: + - + power: + address: + - architecture: + mac_addresses: + - + power: + address: + - architecture: + mac_addresses: + - + power: + address: + password: ubuntu + pool: default + release: trusty + settings: + maas_name: + main_archive: http://us.archive.ubuntu.com/ubuntu + upstream_dns: + user: ubuntu + vcpus: 4 + virsh: + rsa_priv_key: /home/ubuntu/.ssh/id_rsa + rsa_pub_key: /home/ubuntu/.ssh/id_rsa.pub + uri: |