aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory
diff options
context:
space:
mode:
Diffstat (limited to 'src/resource_inventory')
-rw-r--r--src/resource_inventory/admin.py6
-rw-r--r--src/resource_inventory/migrations/0013_auto_20200218_1536.py2
-rw-r--r--src/resource_inventory/migrations/0015_resourcetemplate_copy_of.py19
-rw-r--r--src/resource_inventory/models.py17
-rw-r--r--src/resource_inventory/pdf_templater.py2
-rw-r--r--src/resource_inventory/resource_manager.py21
6 files changed, 54 insertions, 13 deletions
diff --git a/src/resource_inventory/admin.py b/src/resource_inventory/admin.py
index 13afd99..439dad3 100644
--- a/src/resource_inventory/admin.py
+++ b/src/resource_inventory/admin.py
@@ -30,7 +30,9 @@ from resource_inventory.models import (
OPNFVConfig,
OPNFVRole,
Image,
- RemoteInfo
+ RemoteInfo,
+ PhysicalNetwork,
+ NetworkConnection
)
admin.site.register([
@@ -53,4 +55,6 @@ admin.site.register([
OPNFVConfig,
OPNFVRole,
Image,
+ PhysicalNetwork,
+ NetworkConnection,
RemoteInfo])
diff --git a/src/resource_inventory/migrations/0013_auto_20200218_1536.py b/src/resource_inventory/migrations/0013_auto_20200218_1536.py
index d9dcbd6..053453b 100644
--- a/src/resource_inventory/migrations/0013_auto_20200218_1536.py
+++ b/src/resource_inventory/migrations/0013_auto_20200218_1536.py
@@ -15,7 +15,7 @@ def clear_resource_bundles(apps, schema_editor):
def create_default_template(apps, schema_editor):
ResourceTemplate = apps.get_model('resource_inventory', 'ResourceTemplate')
- ResourceTemplate.objects.create(id=1, name="Default Template")
+ ResourceTemplate.objects.create(name="Default Template", hidden=True)
def populate_servers(apps, schema_editor):
diff --git a/src/resource_inventory/migrations/0015_resourcetemplate_copy_of.py b/src/resource_inventory/migrations/0015_resourcetemplate_copy_of.py
new file mode 100644
index 0000000..322dc00
--- /dev/null
+++ b/src/resource_inventory/migrations/0015_resourcetemplate_copy_of.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.2 on 2020-04-13 13:56
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('resource_inventory', '0014_auto_20200305_1415'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='resourcetemplate',
+ name='copy_of',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.ResourceTemplate'),
+ ),
+ ]
diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py
index 7115ece..d1b7a75 100644
--- a/src/resource_inventory/models.py
+++ b/src/resource_inventory/models.py
@@ -155,16 +155,18 @@ class ResourceTemplate(models.Model):
# TODO: template might not be a good name because this is a collection of lots of configured resources
id = models.AutoField(primary_key=True)
- name = models.CharField(max_length=300, unique=True)
+ name = models.CharField(max_length=300)
xml = models.TextField()
owner = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL, related_name="resourcetemplates")
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)
def getConfigs(self):
- return list(self.resourceConfigurations.all())
+ configs = self.resourceConfigurations.all()
+ return list(configs)
def __str__(self):
return self.name
@@ -191,6 +193,13 @@ class ResourceBundle(models.Model):
# TODO
pass
+ def get_template_name(self):
+ if not self.template:
+ return ""
+ if not self.template.temporary:
+ return self.template.name
+ return self.template.copy_of.name
+
class ResourceConfiguration(models.Model):
"""Model to represent a complete configuration for a single physical Resource."""
@@ -200,7 +209,7 @@ class ResourceConfiguration(models.Model):
image = models.ForeignKey("Image", on_delete=models.PROTECT)
template = models.ForeignKey(ResourceTemplate, related_name="resourceConfigurations", null=True, on_delete=models.CASCADE)
is_head_node = models.BooleanField(default=False)
- # name?
+ name = models.CharField(max_length=3000, default="<Hostname>")
def __str__(self):
return "config with " + str(self.template) + " and image " + str(self.image)
@@ -428,7 +437,7 @@ class InterfaceConfiguration(models.Model):
connections = models.ManyToManyField(NetworkConnection)
def __str__(self):
- return "type " + str(self.profile) + " on host " + str(self.host)
+ return "type " + str(self.profile) + " on host " + str(self.resource_config)
"""
diff --git a/src/resource_inventory/pdf_templater.py b/src/resource_inventory/pdf_templater.py
index 367ba43..27a264e 100644
--- a/src/resource_inventory/pdf_templater.py
+++ b/src/resource_inventory/pdf_templater.py
@@ -10,7 +10,7 @@
from django.template.loader import render_to_string
import booking
-from resource_inventory.models import Server, InterfaceProfile
+from resource_inventory.models import Server
class PDFTemplater:
diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py
index 4310f8c..4d539bd 100644
--- a/src/resource_inventory/resource_manager.py
+++ b/src/resource_inventory/resource_manager.py
@@ -17,6 +17,7 @@ from resource_inventory.models import (
Network,
Vlan,
PhysicalNetwork,
+ InterfaceConfiguration,
)
@@ -33,10 +34,12 @@ class ResourceManager:
ResourceManager.instance = ResourceManager()
return ResourceManager.instance
- def getAvailableResourceTemplates(self, lab, user):
- templates = ResourceTemplate.objects.filter(lab=lab)
- templates = templates.filter(Q(owner=user) | Q(public=True)).filter(temporary=False)
- return templates
+ def getAvailableResourceTemplates(self, lab, user=None):
+ filter = Q(public=True)
+ if user:
+ filter = filter | Q(owner=user)
+ filter = filter & Q(temporary=False) & Q(lab=lab)
+ return ResourceTemplate.objects.filter(filter)
def templateIsReservable(self, resource_template):
"""
@@ -110,9 +113,15 @@ class ResourceManager:
def configureNetworking(self, resource, vlan_map):
for physical_interface in resource.interfaces.all():
- iface_config = physical_interface.acts_as
- if not iface_config:
+ # assign interface configs
+ iface_configs = InterfaceConfiguration.objects.filter(profile=physical_interface.profile, resource_config=resource.config)
+ if iface_configs.count() != 1:
continue
+ 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(