9 def get_ip_address(ifname):
10 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
11 return socket.inet_ntoa(fcntl.ioctl(
14 struct.pack('256s', ifname[:15])
17 with open('labconfig.yaml', 'r') as labf:
18 labcfg = yaml.load(labf)
22 def getFromDict(dataDict, mapList):
23 return reduce(lambda d, k: d[k], mapList, dataDict)
25 #lets define the bootstrap section
26 opnfvcfg['demo-maas']={'juju-bootstrap':{'memory': 4096,'name': "bootstrap",\
27 'pool': "default", 'vcpus': 4,\
28 'disk_size': "60G", 'arch': "amd64",\
30 'maas':{'memory': 4096,'pool': "default", 'vcpus': 4,\
31 'disk_size': "160G", 'arch': "amd64", 'interfaces':[],\
32 'name':"",'network_config':[],'node_group_ifaces':[],\
33 'nodes':[],'password': 'ubuntu', 'user':'ubuntu',\
34 'release': 'trusty', 'apt_sources':[],'ip_address':'',\
35 'boot_source':{'keyring_filename':\
36 "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",\
38 "http://maas.ubuntu.com/images/ephemeral-v2/releases/",\
39 'selections':{'1':{'arches':'amd64','labels':'release',\
40 'os':'ubuntu','release':'xenial',\
45 'settings':{'maas_name':'','upstream_dns':'',\
46 'main_archive':"http://us.archive.ubuntu.com/ubuntu"\
48 'virsh':{'rsa_priv_key':'/home/ubuntu/.ssh/id_rsa',
49 'rsa_pub_key':'/home/ubuntu/.ssh/id_rsa.pub',
56 opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:maas/stable")
57 opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:juju/stable")
59 # lets modify the maas general settings:
61 updns = getFromDict(labcfg, ["labconfig","labsettings","upstream_dns"])
62 opnfvcfg["demo-maas"]["maas"]["settings"]["upstream_dns"]=updns
64 value = getFromDict(labcfg, ["labconfig","lab_location"])
65 opnfvcfg["demo-maas"]["maas"]["settings"]["maas_name"]=value
66 opnfvcfg["demo-maas"]["maas"]["name"]="opnfv-"+value
75 while c < len(labcfg["labconfig"]["bridges"]):
76 brtype = getFromDict(labcfg, ["labconfig","bridges",c,"type"])
77 brname = getFromDict(labcfg, ["labconfig","bridges",c,"bridge"])
78 brcidr = getFromDict(labcfg, ["labconfig","bridges",c,"cidr"])
81 ethbrAdmin = getFromDict(labcfg, ["labconfig","bridges",c,"bridge"])
82 brgway = getFromDict(labcfg, ["labconfig","bridges",c,"gateway"])
85 nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \
86 "broadcast_ip": tmpcidr+"255", "router_ip": brgway,\
87 "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\
88 "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}}
90 ethbrAdm = ('auto lo\n'
91 ' iface lo inet loopback\n\n'
92 'auto eth'+str(y)+'\n'
93 ' iface eth'+str(y)+' inet static\n'
94 ' address '+tmpcidr+'5\n'
95 ' netmask 255.255.255.0\n'
96 ' gateway '+brgway+'\n'
97 ' dns-nameservers '+updns+' '+tmpcidr+'5 127.0.0.1\n')
99 opnfvcfg['demo-maas']['maas']['ip_address']=tmpcidr+"5"
100 opnfvcfg['demo-maas']['maas']['interfaces'].append("bridge="+brname+",model=virtio")
101 opnfvcfg['demo-maas']['juju-bootstrap']['interfaces'].append("bridge="+brname+",model=virtio")
102 opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup)
105 opnfvcfg["demo-maas"]["maas"]["interfaces"].append("bridge="+brname+",model=virtio")
106 brgway = getFromDict(labcfg, ["labconfig","bridges",c,"gateway"])
107 if brtype != "external":
108 tmpcidr = brcidr[:-4]
110 nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \
111 "broadcast_ip": tmpcidr+"255", "management": 1, "router_ip": brgway,\
112 "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\
113 "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}}
115 nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \
116 "broadcast_ip": tmpcidr+"255", "management": 1, \
117 "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\
118 "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}}
119 opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup)
120 ethbrAdm = (ethbrAdm+'\n'
121 'auto eth'+str(y)+'\n'
122 ' iface eth'+str(y)+' inet static\n'
123 ' address '+tmpcidr+'5\n'
124 ' netmask 255.255.255.0\n')
126 if brtype == "public":
127 opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio")
128 if brtype == "external":
129 ipaddress = getFromDict(labcfg, ["labconfig","bridges",c,"ipaddress"])
130 ethbrAdm = (ethbrAdm+'\n'
131 'auto eth'+str(y)+'\n'
132 ' iface eth'+str(y)+' inet static\n'
133 ' address '+ipaddress+'\n'
134 ' netmask 255.255.255.0\n')
135 opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio")
139 # lets modify the maas general settings:
140 value = get_ip_address(ethbrAdmin)
141 value = "qemu+ssh://"+getpass.getuser()+"@"+value+"/system"
142 opnfvcfg['demo-maas']['maas']['virsh']['uri']=value
143 opnfvcfg['demo-maas']['maas']['network_config']=ethbrAdm
145 if len(labcfg["labconfig"]["nodes"]) < 1:
146 print("looks like virtual deployment where nodes were not defined")
147 opnfvcfg["demo-maas"]["maas"]["nodes"].remove()
150 #lets insert the node details here:
153 while c < len(labcfg["labconfig"]["nodes"]):
154 # setup value of name and tags accordigly
155 value = getFromDict(labcfg, ["labconfig","nodes",c, "type"])
156 valuemac = getFromDict(labcfg, ["labconfig","nodes",c, "pxe_mac_address"])
157 valuetype = getFromDict(labcfg, ["labconfig","nodes",c, "power", "type"])
158 namevalue = "node" + str(c+1) + "-" + value
159 value = getFromDict(labcfg, ["labconfig","nodes",c, "architecture"])
160 # setup value of architecture
161 if value == "x86_64":
162 value="amd64/generic"
164 if valuetype == "wakeonlan":
165 macvalue = getFromDict(labcfg, ["labconfig","nodes",c, "power", "mac_address"])
166 power={"type": "ether_wake", "mac_address": macvalue}
167 if valuetype == "ipmi":
168 valueaddr = getFromDict(labcfg, ["labconfig","nodes",c, "power", "address"])
169 valueuser = getFromDict(labcfg, ["labconfig","nodes",c, "power", "user"])
170 valuepass = getFromDict(labcfg, ["labconfig","nodes",c, "power", "pass"])
171 valuedriver = "LAN_2_0"
172 power={"type": valuetype, "address": valueaddr,"user": valueuser, "pass": valuepass, "driver": valuedriver}
174 opnfvcfg["demo-maas"]["maas"]["nodes"].append({"name": namevalue, "architecture":value,"mac_addresses":[],"power":power})
177 opnfvcfg["demo-maas"]["maas"]["nodes"][c]['mac_addresses']=valuemac
181 with open('deployment.yaml', 'wa') as opnfvf:
182 yaml.dump(opnfvcfg, opnfvf, default_flow_style=False)