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)
23 def getFromDict(dataDict, mapList):
24 return reduce(lambda d, k: d[k], mapList, dataDict)
26 #lets define the bootstrap section
27 opnfvcfg['demo-maas']={'juju-bootstrap':{'memory': 4096,'name': "bootstrap",\
28 'pool': "default", 'vcpus': 4,\
29 'disk_size': "60G", 'arch': "amd64",\
31 'maas':{'memory': 4096,'pool': "default", 'vcpus': 4,\
32 'disk_size': "160G", 'arch': "amd64", 'interfaces':[],\
33 'name':"",'network_config':[],'node_group_ifaces':[],\
34 'nodes':[],'password': 'ubuntu', 'user':'ubuntu',\
35 'release': 'trusty', 'apt_sources':[],'ip_address':'',\
36 'boot_source':{'keyring_filename':\
37 "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",\
39 "http://maas.ubuntu.com/images/ephemeral-v2/releases/",\
40 'selections':{'1':{'arches':'amd64','labels':'release',\
41 'os':'ubuntu','release':'xenial',\
46 'settings':{'maas_name':'','upstream_dns':'',\
47 'main_archive':"http://us.archive.ubuntu.com/ubuntu"\
49 'virsh':{'rsa_priv_key':'/home/ubuntu/.ssh/id_rsa',
50 'rsa_pub_key':'/home/ubuntu/.ssh/id_rsa.pub',
56 opnfvlabcfg['opnfv']={'ext-port':'','floating-ip-range':'','dataNetwork':'','ceph-disk':'/srv/',\
57 'storageNetwork':'','interface-enable':'','publicNetwork':''}
59 opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:maas/stable")
60 opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:juju/stable")
62 # lets modify the maas general settings:
64 updns = getFromDict(labcfg, ["lab","racks",0,"dns"])
65 opnfvcfg["demo-maas"]["maas"]["settings"]["upstream_dns"]=updns
67 location = getFromDict(labcfg, ["lab","location"])
68 rack = getFromDict(labcfg, ["lab","racks",0,"rack"])
71 opnfvcfg["demo-maas"]["maas"]["settings"]["maas_name"]=value
72 opnfvcfg["demo-maas"]["maas"]["name"]="opnfv-"+value
81 while c < len(labcfg["opnfv"]["spaces"]):
82 brtype = getFromDict(labcfg, ["opnfv","spaces",c,"type"])
83 brname = getFromDict(labcfg, ["opnfv","spaces",c,"bridge"])
84 brcidr = getFromDict(labcfg, ["opnfv","spaces",c,"cidr"])
87 ethbrAdmin = getFromDict(labcfg, ["opnfv","spaces",c,"bridge"])
88 brgway = getFromDict(labcfg, ["opnfv","spaces",c,"gateway"])
90 opnfvlabcfg["opnfv"]["admNetwork"]=tmpcidr+"2"
91 opnfvlabcfg["opnfv"]["admNetgway"]=brgway
93 nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \
94 "broadcast_ip": tmpcidr+"255", "router_ip": brgway,\
95 "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\
96 "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}}
98 ethbrAdm = ('auto lo\n'
99 ' iface lo inet loopback\n\n'
100 'auto eth'+str(y)+'\n'
101 ' iface eth'+str(y)+' inet static\n'
102 ' address '+tmpcidr+'5\n'
103 ' netmask 255.255.255.0\n'
104 ' gateway '+brgway+'\n'
105 ' dns-nameservers '+updns+' '+tmpcidr+'5 127.0.0.1\n')
107 opnfvcfg['demo-maas']['maas']['ip_address']=tmpcidr+"5"
108 opnfvcfg['demo-maas']['maas']['interfaces'].append("bridge="+brname+",model=virtio")
109 opnfvcfg['demo-maas']['juju-bootstrap']['interfaces'].append("bridge="+brname+",model=virtio")
110 opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup)
113 opnfvcfg["demo-maas"]["maas"]["interfaces"].append("bridge="+brname+",model=virtio")
114 brgway = getFromDict(labcfg, ["opnfv","spaces",c,"gateway"])
115 if brtype != "external":
116 tmpcidr = brcidr[:-4]
118 nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \
119 "broadcast_ip": tmpcidr+"255", "management": 1, "router_ip": brgway,\
120 "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\
121 "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}}
123 nodegroup={"device": "eth"+str(y), "ip": tmpcidr+"5","subnet_mask": "255.255.255.0", \
124 "broadcast_ip": tmpcidr+"255", "management": 1, \
125 "static_range":{"high":tmpcidr+"80","low":tmpcidr+"50"},\
126 "dynamic_range":{"high":tmpcidr+"250","low":tmpcidr+"81"}}
127 opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup)
128 ethbrAdm = (ethbrAdm+'\n'
129 'auto eth'+str(y)+'\n'
130 ' iface eth'+str(y)+' inet static\n'
131 ' address '+tmpcidr+'5\n'
132 ' netmask 255.255.255.0\n')
134 if brtype == "public":
135 opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio")
136 opnfvlabcfg["opnfv"]["publicNetwork"]=brcidr
137 if brtype == "external":
138 ipaddress = getFromDict(labcfg, ["opnfv","spaces",c,"ipaddress"])
139 ethbrAdm = (ethbrAdm+'\n'
140 'auto eth'+str(y)+'\n'
141 ' iface eth'+str(y)+' inet static\n'
142 ' address '+ipaddress+'\n'
143 ' netmask 255.255.255.0\n')
144 opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append("bridge="+brname+",model=virtio")
146 opnfvlabcfg["opnfv"]["dataNetwork"]=brcidr
147 if brtype == "storage":
148 opnfvlabcfg["opnfv"]["storageNetwork"]=brcidr
152 # lets modify the maas general settings:
153 value = get_ip_address(ethbrAdmin)
154 value = "qemu+ssh://"+getpass.getuser()+"@"+value+"/system"
155 opnfvcfg['demo-maas']['maas']['virsh']['uri']=value
156 opnfvcfg['demo-maas']['maas']['network_config']=ethbrAdm
158 if len(labcfg["lab"]["racks"][0]["nodes"]) < 1:
159 print("looks like virtual deployment where nodes were not defined")
160 opnfvcfg["demo-maas"]["maas"]["nodes"].remove()
163 #lets insert the node details here:
167 while c < len(labcfg["lab"]["racks"][0]["nodes"]):
170 # setup value of name and tags accordigly
171 noderoleslist = labcfg["lab"]["racks"][0]["nodes"][c]["roles"]
172 noderoles = " ".join(noderoleslist)
174 valuetype = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "type"])
175 namevalue = labcfg["lab"]["racks"][0]["nodes"][c]["name"]
176 valuearc = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "architecture"])
177 # setup value of architecture
178 if valuearc == "x86_64":
179 valuearc="amd64/generic"
181 if valuetype == "wakeonlan":
182 macvalue = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "mac_address"])
183 power={"type": "ether_wake", "mac_address": macvalue}
184 if valuetype == "ipmi":
185 valueaddr = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "address"])
186 valueuser = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "user"])
187 valuepass = getFromDict(labcfg, ["lab","racks",0,"nodes",c, "power", "pass"])
188 valuedriver = "LAN_2_0"
189 power={"type": valuetype, "address": valueaddr,"user": valueuser,\
190 "pass": valuepass, "driver": valuedriver}
192 opnfvcfg["demo-maas"]["maas"]["nodes"].append({"name": namevalue, \
193 "architecture":valuearc,"interfaces":[],"mac_addresses":[],\
194 "power":power,'tags':noderoles})
196 while y < len(labcfg["lab"]["racks"][0]["nodes"][c]["nics"]):
197 valuespaces = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["spaces"]
198 valueifname = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["ifname"]
199 if "admin" not in valuespaces:
200 ifnamelist += [valueifname]
201 valueifmac = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["mac"][0]
202 valuemac += labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["mac"]
203 opnfvcfg["demo-maas"]["maas"]["nodes"][c]["interfaces"]\
204 .append({"name":valueifname,"mac_address":valueifmac,"mode": "auto"})
209 opnfvcfg["demo-maas"]["maas"]["nodes"][c]['mac_addresses']=valuemac
213 opnfvlabcfg["opnfv"]["floating-ip-range"]=labcfg["lab"]["racks"][0]["floating-ip-range"]
214 opnfvlabcfg["opnfv"]["ext-port"]=labcfg["lab"]["racks"][0]["ext-port"]
215 opnfvlabcfg["opnfv"]["ceph-disk"]=labcfg["opnfv"]["storage"][0]["disk"]
216 opnfvlabcfg["opnfv"]["interface-enable"]=",".join(list(set(ifnamelist)))
218 with open('deployment.yaml', 'wa') as opnfvf:
219 yaml.dump(opnfvcfg, opnfvf, default_flow_style=False)
221 with open('deployconfig.yaml', 'wa') as opnfvf:
222 yaml.dump(opnfvlabcfg, opnfvf, default_flow_style=False)