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["opnfv"]["spaces"]):
76 brtype = getFromDict(labcfg, ["opnfv","spaces",c,"type"])
77 brname = getFromDict(labcfg, ["opnfv","spaces",c,"bridge"])
78 brcidr = getFromDict(labcfg, ["opnfv","spaces",c,"cidr"])
81 ethbrAdmin = getFromDict(labcfg, ["opnfv","spaces",c,"bridge"])
82 brgway = getFromDict(labcfg, ["opnfv","spaces",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, ["opnfv","spaces",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, ["opnfv","spaces",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"]):
156 # setup value of name and tags accordigly
157 noderoleslist = labcfg["labconfig"]["nodes"][c]["roles"]
158 noderoles = " ".join(noderoleslist)
160 valuetype = getFromDict(labcfg, ["labconfig","nodes",c, "power", "type"])
161 namevalue = labcfg["labconfig"]["nodes"][c]["name"]
162 valuearc = getFromDict(labcfg, ["labconfig","nodes",c, "architecture"])
163 # setup value of architecture
164 if valuearc == "x86_64":
165 valuearc="amd64/generic"
167 if valuetype == "wakeonlan":
168 macvalue = getFromDict(labcfg, ["labconfig","nodes",c, "power", "mac_address"])
169 power={"type": "ether_wake", "mac_address": macvalue}
170 if valuetype == "ipmi":
171 valueaddr = getFromDict(labcfg, ["labconfig","nodes",c, "power", "address"])
172 valueuser = getFromDict(labcfg, ["labconfig","nodes",c, "power", "user"])
173 valuepass = getFromDict(labcfg, ["labconfig","nodes",c, "power", "pass"])
174 valuedriver = "LAN_2_0"
175 power={"type": valuetype, "address": valueaddr,"user": valueuser,\
176 "pass": valuepass, "driver": valuedriver}
178 opnfvcfg["demo-maas"]["maas"]["nodes"].append({"name": namevalue, \
179 "architecture":valuearc,"interfaces":[],"mac_addresses":[],\
180 "power":power,'tags':noderoles})
182 while y < len(labcfg["labconfig"]["nodes"][c]["nics"]):
183 valueifname = labcfg["labconfig"]["nodes"][c]["nics"][y]["ifname"]
184 valueifmac = labcfg["labconfig"]["nodes"][c]["nics"][y]["mac"][0]
185 valuemac += labcfg["labconfig"]["nodes"][c]["nics"][y]["mac"]
186 opnfvcfg["demo-maas"]["maas"]["nodes"][c]["interfaces"]\
187 .append({"name":valueifname,"mac_address":valueifmac,"mode": "auto"})
192 opnfvcfg["demo-maas"]["maas"]["nodes"][c]['mac_addresses']=valuemac
196 with open('deployment.yaml', 'wa') as opnfvf:
197 yaml.dump(opnfvcfg, opnfvf, default_flow_style=False)