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):
219 returns a dictionary of data from the yaml files
220 created by inspection scripts
223 for prof in ["hpe", "arm"]: # TODO
228 "description": "some LaaS servers"
230 profile_dict['host'] = host
231 profile_dict['interfaces'] = []
232 for interface in [{"name": "eno1", "speed": 1000}, {"name": "eno2", "speed": 10000}]: # TODO
234 iface_dict["name"] = interface['name']
235 iface_dict['speed'] = interface['speed']
236 profile_dict['interfaces'].append(iface_dict)
238 profile_dict['disks'] = []
239 for disk in [{"size": 1000, "type": "ssd", "name": "sda"}]: # TODO
241 disk_dict['size'] = disk['size']
242 disk_dict['type'] = disk['type']
243 disk_dict['name'] = disk['name']
244 profile_dict['disks'].append(disk_dict)
251 profile_dict['cpu'] = cpu
257 profile_dict['ram'] = ram
259 data.append(profile_dict)
263 def get_lab_data(self, lab):
265 path = "/pharos_dashboard/data/" + lab.name + "/"
266 host_file = open(path + "hostlist.json")
267 host_structure = json.loads(host_file.read())
269 for profile in host_structure['profiles'].keys():
271 prof_path = path + profile
272 for host in host_structure['profiles'][profile]:
273 host_file = open(prof_path + "/" + host + ".yaml")
274 host_data = yaml.load(host_file.read())
276 data[profile][host] = host_data
279 def make_profiles_and_hosts(self, lab, lab_data):
280 for host_profile_name, host_data_dict in lab_data.items():
281 if len(host_data_dict) < 1:
283 host_profile = HostProfile.objects.create(
284 name=host_profile_name,
287 host_profile.labs.add(lab)
288 example_host_data = list(host_data_dict.values())[0]
290 cpu_data = example_host_data['cpu']
291 CpuProfile.objects.create(
292 cores=cpu_data['cores'],
293 architecture=cpu_data['arch'],
294 cpus=cpu_data['cpus'],
298 ram_data = example_host_data['memory']
299 RamProfile.objects.create(
300 amount=int(ram_data[:-1]),
305 disks_data = example_host_data['disk']
306 for disk_data in disks_data:
309 size = int(disk_data['size'].split('.')[0])
311 size = int(disk_data['size'].split('.')[0][:-1])
312 DiskProfile.objects.create(
315 name=disk_data['name'],
319 ifaces_data = example_host_data['interface']
320 for iface_data in ifaces_data:
321 InterfaceProfile.objects.create(
322 speed=iface_data['speed'],
323 name=iface_data['name'],
327 # all profiles created
328 for hostname, host_data in host_data_dict.items():
329 host = Host.objects.create(
332 profile=host_profile,
335 for iface_data in host_data['interface']:
336 Interface.objects.create(
337 mac_address=iface_data['mac'],
338 bus_address=iface_data['busaddr'],
339 name=iface_data['name'],
344 self.labs = self.make_labs()
345 # We should use the existing users, not creating our own
346 for lab in self.labs:
347 lab_data = self.get_lab_data(lab)
348 self.make_profiles_and_hosts(lab, lab_data)
350 # We will add opnfv info and images as they are created and supported