diff options
-rw-r--r-- | src/laas_dashboard/model_test.py | 110 | ||||
-rw-r--r-- | src/resource_inventory/admin.py | 16 | ||||
-rw-r--r-- | src/resource_inventory/forms.py | 31 | ||||
-rw-r--r-- | src/resource_inventory/models.py | 28 | ||||
-rw-r--r-- | src/resource_inventory/resource_manager.py | 20 | ||||
-rw-r--r-- | src/workflow/booking_workflow.py | 38 | ||||
-rw-r--r-- | src/workflow/models.py | 18 | ||||
-rw-r--r-- | src/workflow/workflow_factory.py | 3 |
8 files changed, 194 insertions, 70 deletions
diff --git a/src/laas_dashboard/model_test.py b/src/laas_dashboard/model_test.py new file mode 100644 index 0000000..ba3ef35 --- /dev/null +++ b/src/laas_dashboard/model_test.py @@ -0,0 +1,110 @@ +############################################################################## +# Copyright (c) 2020 Sawyer Bergeron, Parker Berberian, Sean Smith, and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +from resource_inventory.models import ( + ResourceProfile, + ResourceQuery, + Image, + DiskProfile, + CpuProfile, + RamProfile, + InterfaceProfile, +) + + +def rp_has_all_components(): + """ + Check that every ResourceProfile has an InterfaceProfile, + DiskProfile, CpuProfile, and RamProfile. + """ + + result = True + + for rp in ResourceProfile.objects.all(): + ip = InterfaceProfile.objects.filter(host=rp).exists() + dp = DiskProfile.objects.filter(host=rp).exists() + cp = CpuProfile.objects.filter(host=rp).exists() + ram = RamProfile.objects.filter(host=rp).exists() + + if not ip: + print("No InterfaceProfiles for host", rp.name) + result = False + + if not dp: + print("No DiskProfile for host", rp.name) + result = False + + if not cp: + print("No CpuProfile for host", rp.name) + result = False + + if not ram: + print("No RamProfile for host", rp.name) + result = False + + return result + + +def ip_for_all_ifaces(): + """ + Check that every InterfaceProfile for a Resource has + an Interface. + """ + + result = True + + for res in ResourceQuery.filter(): + iface_set = res.get_interfaces() + iface_profile_set = InterfaceProfile.objects.filter(host=res.profile) + + # find out what profiles we have + curr_profiles = [iface.profile for iface in iface_set] + missing_profiles = set(iface_profile_set) - set(curr_profiles) + + if missing_profiles: + print('No interface for profiles', missing_profiles, 'for host', res.name) + result = False + + return result + + +def rp_has_image(): + """ + Make sure every ResourceProfile has an Image. + """ + + result = True + + rp_set = ResourceProfile.objects.all() + image_set = Image.objects.all() + image_profiles = set([image.host_type for image in image_set]) + + for rp in rp_set: + if rp not in image_profiles: + print("ResourceProfile", rp.name, "has no image associated with it.") + result = False + return result + + +def run_test(test): + print('RUNNING TEST', test) + result = test() + if result: + print(test, 'WAS A SUCCESS!') + else: + print(test, 'FAILED') + print('============================================') + + +def run_tests(): + tests = [rp_has_all_components, ip_for_all_ifaces, rp_has_image] + + for test in tests: + run_test(test) diff --git a/src/resource_inventory/admin.py b/src/resource_inventory/admin.py index 439dad3..2444a98 100644 --- a/src/resource_inventory/admin.py +++ b/src/resource_inventory/admin.py @@ -10,6 +10,8 @@ from django.contrib import admin +from resource_inventory.forms import InterfaceConfigurationForm + from resource_inventory.models import ( ResourceProfile, InterfaceProfile, @@ -32,9 +34,10 @@ from resource_inventory.models import ( Image, RemoteInfo, PhysicalNetwork, - NetworkConnection + NetworkConnection, ) + admin.site.register([ ResourceProfile, InterfaceProfile, @@ -43,7 +46,6 @@ admin.site.register([ RamProfile, ResourceTemplate, ResourceConfiguration, - InterfaceConfiguration, Server, Interface, Network, @@ -57,4 +59,12 @@ admin.site.register([ Image, PhysicalNetwork, NetworkConnection, - RemoteInfo]) + RemoteInfo] +) + + +class InterfaceConfigurationAdmin(admin.ModelAdmin): + form = InterfaceConfigurationForm + + +admin.site.register(InterfaceConfiguration, InterfaceConfigurationAdmin) diff --git a/src/resource_inventory/forms.py b/src/resource_inventory/forms.py new file mode 100644 index 0000000..fb8c102 --- /dev/null +++ b/src/resource_inventory/forms.py @@ -0,0 +1,31 @@ +############################################################################## +# Copyright (c) 2020 Sawyer Bergeron, Sean Smith, and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from django.core.exceptions import ValidationError +from django import forms + +from resource_inventory.models import Network, InterfaceConfiguration + + +class InterfaceConfigurationForm(forms.ModelForm): + class Meta: + model = InterfaceConfiguration + fields = ['profile', 'resource_config', 'connections'] + + def clean(self): + connections = self.cleaned_data.get('connections') + resource_config = self.cleaned_data.get('resource_config') + + valid_nets = set(Network.objects.filter(bundle=resource_config.template)) + curr_nets = set([conn.network for conn in connections]) + + if not curr_nets.issubset(valid_nets): + raise ValidationError("Cannot have network connection to network outside pod") + + return self.cleaned_data diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py index d1b7a75..557a4fc 100644 --- a/src/resource_inventory/models.py +++ b/src/resource_inventory/models.py @@ -1,5 +1,6 @@ ############################################################################## # Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others. +# Copyright (c) 2020 Sawyer Bergeron, Sean Smith, others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -162,7 +163,7 @@ class ResourceTemplate(models.Model): description = models.CharField(max_length=1000, default="") public = models.BooleanField(default=False) temporary = models.BooleanField(default=False) - copy_of = models.ForeignKey("ResourceTemplate", null=True, on_delete=models.SET_NULL) + copy_of = models.ForeignKey("ResourceTemplate", blank=True, null=True, on_delete=models.SET_NULL) def getConfigs(self): configs = self.resourceConfigurations.all() @@ -212,7 +213,7 @@ class ResourceConfiguration(models.Model): name = models.CharField(max_length=3000, default="<Hostname>") def __str__(self): - return "config with " + str(self.template) + " and image " + str(self.image) + return str(self.name) def get_default_remote_info(): @@ -238,9 +239,9 @@ class Resource(models.Model): class Meta: abstract = True - bundle = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, null=True) + bundle = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, blank=True, null=True) profile = models.ForeignKey(ResourceProfile, on_delete=models.CASCADE) - config = models.ForeignKey(ResourceConfiguration, on_delete=models.SET_NULL, null=True) + config = models.ForeignKey(ResourceConfiguration, on_delete=models.SET_NULL, blank=True, null=True) working = models.BooleanField(default=True) vendor = models.CharField(max_length=100, default="unknown") model = models.CharField(max_length=150, default="unknown") @@ -413,11 +414,17 @@ class PhysicalNetwork(models.Model): # vlan_manager = self.bundle.lab.vlan_manager return False + def __str__(self): + return 'Physical Network for ' + self.generic_network.name + class NetworkConnection(models.Model): network = models.ForeignKey(Network, on_delete=models.CASCADE) vlan_is_tagged = models.BooleanField() + def __str__(self): + return 'Connection to ' + self.network.name + class Vlan(models.Model): id = models.AutoField(primary_key=True) @@ -434,7 +441,7 @@ class InterfaceConfiguration(models.Model): id = models.AutoField(primary_key=True) profile = models.ForeignKey(InterfaceProfile, on_delete=models.CASCADE) resource_config = models.ForeignKey(ResourceConfiguration, on_delete=models.CASCADE, related_name='interface_configs') - connections = models.ManyToManyField(NetworkConnection) + connections = models.ManyToManyField(NetworkConnection, blank=True) def __str__(self): return "type " + str(self.profile) + " on host " + str(self.resource_config) @@ -504,12 +511,21 @@ class Interface(models.Model): mac_address = models.CharField(max_length=17) bus_address = models.CharField(max_length=50) config = models.ManyToManyField(Vlan) - acts_as = models.OneToOneField(InterfaceConfiguration, null=True, on_delete=models.SET_NULL) + acts_as = models.OneToOneField(InterfaceConfiguration, blank=True, null=True, on_delete=models.CASCADE) profile = models.ForeignKey(InterfaceProfile, on_delete=models.CASCADE) def __str__(self): return self.mac_address + " on host " + str(self.profile.host.name) + def clean(self, *args, **kwargs): + if self.acts_as and self.acts_as.profile != self.profile: + raise ValidationError("Interface Configuration's Interface Profile does not match Interface Profile chosen for Interface.") + super().clean(*args, **kwargs) + + def save(self, *args, **kwargs): + self.full_clean() + super().save(*args, **kwargs) + """ Some Enums for dealing with global constants. diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py index 4d539bd..9300040 100644 --- a/src/resource_inventory/resource_manager.py +++ b/src/resource_inventory/resource_manager.py @@ -82,7 +82,7 @@ class ResourceManager: networks[network.name] = vlan return networks - def instantiateTemplate(self, resource_template, config=None): + def instantiateTemplate(self, resource_template): """ Convert a ResourceTemplate into a ResourceBundle. @@ -114,14 +114,16 @@ class ResourceManager: def configureNetworking(self, resource, vlan_map): for physical_interface in resource.interfaces.all(): # assign interface configs - iface_configs = InterfaceConfiguration.objects.filter(profile=physical_interface.profile, resource_config=resource.config) - if iface_configs.count() != 1: - continue + + iface_configs = InterfaceConfiguration.objects.filter( + profile=physical_interface.profile, + resource_config=resource.config + ) + iface_config = iface_configs.first() physical_interface.acts_as = iface_config physical_interface.acts_as.save() - #if not iface_config: - # continue + physical_interface.config.clear() for connection in iface_config.connections.all(): physicalNetwork = PhysicalNetwork.objects.create( @@ -139,7 +141,11 @@ class ResourceManager: # private interface def acquireHost(self, resource_config): - resources = resource_config.profile.get_resources(lab=resource_config.template.lab, unreserved=True) + resources = resource_config.profile.get_resources( + lab=resource_config.template.lab, + unreserved=True + ) + try: resource = resources[0] # TODO: should we randomize and 'load balance' the servers? resource.config = resource_config diff --git a/src/workflow/booking_workflow.py b/src/workflow/booking_workflow.py index 128f179..ef89804 100644 --- a/src/workflow/booking_workflow.py +++ b/src/workflow/booking_workflow.py @@ -1,5 +1,6 @@ ############################################################################## # Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others. +# Copyright (c) 2020 Sawyer Bergeron, Sean Smith, and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -13,7 +14,7 @@ from datetime import timedelta from booking.models import Booking from workflow.models import WorkflowStep, AbstractSelectOrCreate -from workflow.forms import ResourceSelectorForm, SWConfigSelectorForm, BookingMetaForm, OPNFVSelectForm +from workflow.forms import ResourceSelectorForm, BookingMetaForm, OPNFVSelectForm from resource_inventory.models import OPNFVConfig, ResourceTemplate from django.db.models import Q @@ -65,41 +66,6 @@ class Booking_Resource_Select(Abstract_Resource_Select): workflow_type = "booking" -class SWConfig_Select(AbstractSelectOrCreate): - title = "Select Software Configuration" - description = "Choose the software and related configurations you want to have used for your deployment" - short_title = "pod config" - form = SWConfigSelectorForm - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.select_repo_key = self.repo.SELECTED_CONFIG_BUNDLE - self.confirm_key = "booking" - - def alert_bundle_missing(self): - self.set_invalid("Please select a valid pod config") - - def get_form_queryset(self): - user = self.repo_get(self.repo.SESSION_USER) - grb = self.repo_get(self.repo.SELECTED_RESOURCE_TEMPLATE) - qs = ResourceTemplate.objects.filter(Q(hidden=False) & (Q(owner=user) | Q(public=True))).filter(bundle=grb) - return qs - - def put_confirm_info(self, bundle): - confirm_dict = self.repo_get(self.repo.CONFIRMATION) - if self.confirm_key not in confirm_dict: - confirm_dict[self.confirm_key] = {} - confirm_dict[self.confirm_key]["Software Configuration"] = bundle.name - self.repo_put(self.repo.CONFIRMATION, confirm_dict) - - def get_page_context(self): - return { - 'select_type': 'swconfig', - 'select_type_title': 'Software Config', - 'addable_type_num': 2 - } - - class OPNFV_EnablePicker(object): pass diff --git a/src/workflow/models.py b/src/workflow/models.py index 173fdba..4a5616e 100644 --- a/src/workflow/models.py +++ b/src/workflow/models.py @@ -368,7 +368,6 @@ class Repository(): RESOURCE_SELECT = "resource_select" CONFIRMATION = "confirmation" SELECTED_RESOURCE_TEMPLATE = "selected resource template pk" - SELECTED_CONFIG_BUNDLE = "selected config bundle pk" SELECTED_OPNFV_CONFIG = "selected opnfv deployment config" RESOURCE_TEMPLATE_MODELS = "generic_resource_template_models" RESOURCE_TEMPLATE_INFO = "generic_resource_template_info" @@ -456,15 +455,6 @@ class Repository(): self.el[self.RESULT_KEY] = self.SELECTED_RESOURCE_TEMPLATE return - if self.CONFIG_MODELS in self.el: - errors = self.make_software_config_bundle() - if errors: - return errors - else: - self.el[self.HAS_RESULT] = True - self.el[self.RESULT_KEY] = self.SELECTED_CONFIG_BUNDLE - return - if self.OPNFV_MODELS in self.el: errors = self.make_opnfv_config() if errors: @@ -585,11 +575,6 @@ class Repository(): else: return "BOOK, no selected resource. CODE:0x000e" - if self.SELECTED_CONFIG_BUNDLE not in self.el: - return "BOOK, no selected config bundle. CODE:0x001f" - - booking.config_bundle = self.el[self.SELECTED_CONFIG_BUNDLE] - if not booking.start: return "BOOK, booking has no start. CODE:0x0010" if not booking.end: @@ -602,7 +587,8 @@ class Repository(): else: return "BOOK, collaborators not defined. CODE:0x0013" try: - resource_bundle = ResourceManager.getInstance().convertResourceBundle(selected_grb, config=booking.config_bundle) + res_manager = ResourceManager.getInstance() + resource_bundle = res_manager.instantiateTemplate(selected_grb) except ResourceAvailabilityException as e: return "BOOK, requested resources are not available. Exception: " + str(e) + " CODE:0x0014" except ModelValidationException as e: diff --git a/src/workflow/workflow_factory.py b/src/workflow/workflow_factory.py index 04ed280..e688510 100644 --- a/src/workflow/workflow_factory.py +++ b/src/workflow/workflow_factory.py @@ -8,7 +8,7 @@ ############################################################################## -from workflow.booking_workflow import Booking_Resource_Select, SWConfig_Select, Booking_Meta, OPNFV_Select +from workflow.booking_workflow import Booking_Resource_Select, Booking_Meta, OPNFV_Select from workflow.resource_bundle_workflow import Define_Hardware, Define_Nets, Resource_Meta_Info, Define_Software from workflow.snapshot_workflow import Select_Host_Step, Image_Meta_Step from workflow.opnfv_workflow import Pick_Installer, Assign_Network_Roles, Assign_Host_Roles, OPNFV_Resource_Select, MetaInfo @@ -73,7 +73,6 @@ class Workflow(object): class WorkflowFactory(): booking_steps = [ Booking_Resource_Select, - SWConfig_Select, Booking_Meta, OPNFV_Select, ] |