aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2019-04-09 16:30:57 -0400
committerParker Berberian <pberberian@iol.unh.edu>2019-05-03 11:48:22 -0400
commit04b676a8bc7209b8017395dc9bb36086283ac72c (patch)
tree381f48806f6e109784ca502f584865da72bcfe11 /src/api
parentfec940b7b8d15099b8f914ce35552c59db9eb77b (diff)
Implement OPNFV workflow
This is a counterpart to an update to network models, and allows for configuring baremetal OPNFV and Openstack deploys Change-Id: I0185dbfa6c9105d7e63a7e7d7dd1f5cf228a8877 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/api')
-rw-r--r--src/api/migrations/0007_opnfvapiconfig_opnfv_config.py20
-rw-r--r--src/api/models.py54
2 files changed, 47 insertions, 27 deletions
diff --git a/src/api/migrations/0007_opnfvapiconfig_opnfv_config.py b/src/api/migrations/0007_opnfvapiconfig_opnfv_config.py
new file mode 100644
index 0000000..46f3631
--- /dev/null
+++ b/src/api/migrations/0007_opnfvapiconfig_opnfv_config.py
@@ -0,0 +1,20 @@
+# Generated by Django 2.1 on 2019-05-01 18:53
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('resource_inventory', '0010_auto_20190430_1405'),
+ ('api', '0006_auto_20190313_1729'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='opnfvapiconfig',
+ name='opnfv_config',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.OPNFVConfig'),
+ ),
+ ]
diff --git a/src/api/models.py b/src/api/models.py
index 4ce8c3e..e17a911 100644
--- a/src/api/models.py
+++ b/src/api/models.py
@@ -23,7 +23,8 @@ from resource_inventory.models import (
Host,
Image,
Interface,
- RemoteInfo
+ RemoteInfo,
+ OPNFVConfig
)
from resource_inventory.idf_templater import IDFTemplater
from resource_inventory.pdf_templater import PDFTemplater
@@ -93,7 +94,7 @@ class LabManager(object):
return {"status": "success"}
def update_xdf(self, booking):
- booking.pdf = PDFTemplater.makePDF(booking.resource)
+ booking.pdf = PDFTemplater.makePDF(booking)
booking.idf = IDFTemplater().makeIDF(booking)
booking.save()
@@ -356,9 +357,12 @@ class OpnfvApiConfig(models.Model):
scenario = models.CharField(max_length=300)
roles = models.ManyToManyField(Host)
delta = models.TextField()
+ opnfv_config = models.ForeignKey(OPNFVConfig, null=True, on_delete=models.SET_NULL)
def to_dict(self):
d = {}
+ if not self.opnfv_config:
+ return d
if self.installer:
d['installer'] = self.installer
if self.scenario:
@@ -367,8 +371,12 @@ class OpnfvApiConfig(models.Model):
hosts = self.roles.all()
if hosts.exists():
d['roles'] = []
- for host in self.roles.all():
- d['roles'].append({host.labid: host.config.opnfvRole.name})
+ for host in hosts:
+ d['roles'].append({
+ host.labid: self.opnfv_config.host_opnfv_config.get(
+ host_config__pk=host.config.pk
+ ).role.name
+ })
return d
@@ -818,6 +826,7 @@ class JobFactory(object):
)
cls.makeSoftware(
hosts=hosts,
+ booking=booking,
job=job
)
all_users = list(booking.collaborators.all())
@@ -908,28 +917,19 @@ class JobFactory(object):
network_config.save()
@classmethod
- def makeSoftware(cls, hosts=[], job=Job()):
- def init_config(host):
- opnfv_config = OpnfvApiConfig()
- if host is not None:
- opnfv = host.config.bundle.opnfv_config.first()
- opnfv_config.installer = opnfv.installer.name
- opnfv_config.scenario = opnfv.scenario.name
- opnfv_config.save()
- return opnfv_config
-
- try:
- host = None
- if len(hosts) > 0:
- host = hosts[0]
- opnfv_config = init_config(host)
+ def makeSoftware(cls, hosts=[], booking=None, job=Job()):
- for host in hosts:
- opnfv_config.roles.add(host)
- software_config = SoftwareConfig.objects.create(opnfv=opnfv_config)
- software_config.save()
- software_relation = SoftwareRelation.objects.create(job=job, config=software_config)
- software_relation.save()
- return software_relation
- except Exception:
+ if not booking.opnfv_config:
return None
+
+ opnfv_api_config = OpnfvApiConfig.objects.create(
+ opnfv_config=booking.opnfv_config,
+ installer=booking.opnfv_config.installer,
+ scenario=booking.opnfv_config.scenario,
+ )
+
+ for host in hosts:
+ opnfv_api_config.roles.add(host)
+ software_config = SoftwareConfig.objects.create(opnfv=opnfv_api_config)
+ software_relation = SoftwareRelation.objects.create(job=job, config=software_config)
+ return software_relation