1 ##############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from account.models import Lab, UserProfile
14 from django.contrib.auth.models import User
15 from resource_inventory.models import (
35 self.host_profile_count = 0
36 self.generic_host_count = 0
37 self.host_profiles = []
38 self.generic_bundle_count = 0
39 self.booking_count = 0
41 def make_host_profile(self, lab, data):
42 hostProfile = HostProfile.objects.create(
43 host_type=data['host']['type'],
44 name=data['host']['name'],
45 description=data['host']['description']
49 for iface_data in data['interfaces']:
51 interfaceProfile = InterfaceProfile.objects.create(
52 speed=iface_data['speed'],
53 name=iface_data['name'],
56 interfaceProfile.save()
58 for disk_data in data['disks']:
60 diskProfile = DiskProfile.objects.create(
61 size=disk_data['size'],
62 media_type=disk_data['type'],
63 name=disk_data['name'],
68 cpuProfile = CpuProfile.objects.create(
69 cores=data['cpu']['cores'],
70 architecture=data['cpu']['arch'],
71 cpus=data['cpu']['cpus'],
75 ramProfile = RamProfile.objects.create(
76 amount=data['ram']['amount'],
77 channels=data['ram']['channels'],
81 hostProfile.labs.add(lab)
85 user_pberberian = User.objects.create(username="pberberian")
86 user_pberberian.save()
87 user_pberberian_prof = UserProfile.objects.create(user=user_pberberian)
88 user_pberberian_prof.save()
90 user_sbergeron = User.objects.create(username="sbergeron")
92 user_sbergeron_prof = UserProfile.objects.create(user=user_sbergeron)
93 user_sbergeron_prof.save()
94 return [user_sbergeron, user_pberberian]
97 unh_iol = User.objects.create(username="unh_iol")
101 for i in range(1, 4096):
104 iol = Lab.objects.create(
107 vlan_manager=VlanManager.objects.create(
108 vlans=json.dumps(vlans),
109 reserved_vlans=json.dumps(reserved),
110 allow_overlapping=False,
113 api_token=Lab.make_api_token(),
114 contact_email="nfv-lab@iol.unh.edu",
115 location="University of New Hampshire, Durham NH, 03824 USA"
119 def make_configurations(self):
121 scen1 = Scenario.objects.create(name="os-nosdn-nofeature-noha")
122 scen2 = Scenario.objects.create(name="os-odl-kvm-ha")
123 scen3 = Scenario.objects.create(name="os-nosdn-nofeature-ha")
126 fuel = Installer.objects.create(name="Fuel")
127 fuel.sup_scenarios.add(scen1)
128 fuel.sup_scenarios.add(scen3)
130 joid = Installer.objects.create(name="Joid")
131 joid.sup_scenarios.add(scen1)
132 joid.sup_scenarios.add(scen2)
134 apex = Installer.objects.create(name="Apex")
135 apex.sup_scenarios.add(scen2)
136 apex.sup_scenarios.add(scen3)
138 daisy = Installer.objects.create(name="Daisy")
139 daisy.sup_scenarios.add(scen1)
140 daisy.sup_scenarios.add(scen2)
141 daisy.sup_scenarios.add(scen3)
143 compass = Installer.objects.create(name="Compass")
144 compass.sup_scenarios.add(scen1)
145 compass.sup_scenarios.add(scen3)
149 ubuntu = Opsys.objects.create(name="Ubuntu")
150 ubuntu.sup_installers.add(compass)
151 ubuntu.sup_installers.add(joid)
153 centos = Opsys.objects.create(name="CentOs")
154 centos.sup_installers.add(apex)
155 centos.sup_installers.add(fuel)
157 suse = Opsys.objects.create(name="Suse")
158 suse.sup_installers.add(fuel)
162 OPNFVRole.objects.create(name="Compute", description="Does the heavy lifting")
163 OPNFVRole.objects.create(name="Controller", description="Controls everything")
164 OPNFVRole.objects.create(name="Jumphost", description="Entry Point")
166 lab = Lab.objects.first()
167 user = UserProfile.objects.first().user
168 Image.objects.create(
173 host_type=HostProfile.objects.get(name="hpe")
175 Image.objects.create(
180 host_type=HostProfile.objects.get(name="hpe")
183 Image.objects.create(
188 host_type=HostProfile.objects.get(name="hpe")
191 Image.objects.create(
196 host_type=HostProfile.objects.get(name="arm")
199 def make_lab_hosts(self, hostcount, profile, lab, data, offset=1):
200 for i in range(hostcount):
201 name = "Host_" + lab.name + "_" + profile.name + "_" + str(i + offset)
202 host = Host.objects.create(
206 labid=data[i]['labid']
208 for iface_profile in profile.interfaceprofile.all():
209 iface_data = data[i]['interfaces'][iface_profile.name]
210 Interface.objects.create(
211 mac_address=iface_data['mac'],
212 bus_address=iface_data['bus'],
213 name=iface_profile.name,
217 def make_profile_data(self):
221 returns a dictionary of data from the yaml files
222 created by inspection scripts
225 for prof in ["hpe", "arm"]: # TODO
230 "description": "some LaaS servers"
232 profile_dict['host'] = host
233 profile_dict['interfaces'] = []
234 for interface in [{"name": "eno1", "speed": 1000}, {"name": "eno2", "speed": 10000}]: # TODO
236 iface_dict["name"] = interface['name']
237 iface_dict['speed'] = interface['speed']
238 profile_dict['interfaces'].append(iface_dict)
240 profile_dict['disks'] = []
241 for disk in [{"size": 1000, "type": "ssd", "name": "sda"}]: # TODO
243 disk_dict['size'] = disk['size']
244 disk_dict['type'] = disk['type']
245 disk_dict['name'] = disk['name']
246 profile_dict['disks'].append(disk_dict)
253 profile_dict['cpu'] = cpu
259 profile_dict['ram'] = ram
261 data.append(profile_dict)
265 def get_lab_data(self, lab):
267 path = "/laas_dashboard/data/" + lab.name + "/"
268 host_file = open(path + "hostlist.json")
269 host_structure = json.loads(host_file.read())
271 for profile in host_structure['profiles'].keys():
273 prof_path = path + profile
274 for host in host_structure['profiles'][profile]:
275 host_file = open(prof_path + "/" + host + ".yaml")
276 host_data = yaml.load(host_file.read())
278 data[profile][host] = host_data
281 def make_profiles_and_hosts(self, lab, lab_data):
282 for host_profile_name, host_data_dict in lab_data.items():
283 if len(host_data_dict) < 1:
285 host_profile = HostProfile.objects.create(
286 name=host_profile_name,
289 host_profile.labs.add(lab)
290 example_host_data = list(host_data_dict.values())[0]
292 cpu_data = example_host_data['cpu']
293 CpuProfile.objects.create(
294 cores=cpu_data['cores'],
295 architecture=cpu_data['arch'],
296 cpus=cpu_data['cpus'],
300 ram_data = example_host_data['memory']
301 RamProfile.objects.create(
302 amount=int(ram_data[:-1]),
307 disks_data = example_host_data['disk']
308 for disk_data in disks_data:
311 size = int(disk_data['size'].split('.')[0])
313 size = int(disk_data['size'].split('.')[0][:-1])
314 DiskProfile.objects.create(
317 name=disk_data['name'],
321 ifaces_data = example_host_data['interface']
322 for iface_data in ifaces_data:
323 InterfaceProfile.objects.create(
324 speed=iface_data['speed'],
325 name=iface_data['name'],
329 # all profiles created
330 for hostname, host_data in host_data_dict.items():
331 host = Host.objects.create(
334 profile=host_profile,
337 for iface_data in host_data['interface']:
338 Interface.objects.create(
339 mac_address=iface_data['mac'],
340 bus_address=iface_data['busaddr'],
341 name=iface_data['name'],
346 self.labs = self.make_labs()
347 # We should use the existing users, not creating our own
348 for lab in self.labs:
349 lab_data = self.get_lab_data(lab)
350 self.make_profiles_and_hosts(lab, lab_data)
352 # We will add opnfv info and images as they are created and supported