aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/models.py')
-rw-r--r--src/api/models.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/api/models.py b/src/api/models.py
index c61341e..df9bbf7 100644
--- a/src/api/models.py
+++ b/src/api/models.py
@@ -331,7 +331,7 @@ class Job(models.Model):
return {"id": self.id, "payload": d}
def get_tasklist(self, status="all"):
- if status == "all":
+ if status != "all":
return JobTaskQuery.filter(job=self, status=status)
return JobTaskQuery.filter(job=self)
@@ -408,7 +408,7 @@ class BridgeConfig(models.Model):
def to_dict(self):
d = {}
- hid = self.interfaces.first().host.labid
+ hid = ResourceQuery.get(interface__pk=self.interfaces.first().pk).labid
d[hid] = {}
for interface in self.interfaces.all():
d[hid][interface.mac_address] = []
@@ -611,7 +611,7 @@ class HardwareConfig(TaskConfig):
def get_delta(self):
return self.format_delta(
- self.hosthardwarerelation.host.get_configuration(self.state),
+ self.hosthardwarerelation.get_resource().get_configuration(self.state),
self.hosthardwarerelation.lab_token)
@@ -623,7 +623,7 @@ class NetworkConfig(TaskConfig):
def to_dict(self):
d = {}
- hid = self.hostnetworkrelation.host.labid
+ hid = self.hostnetworkrelation.resource_id
d[hid] = {}
for interface in self.interfaces.all():
d[hid][interface.mac_address] = []
@@ -652,7 +652,7 @@ class NetworkConfig(TaskConfig):
def add_interface(self, interface):
self.interfaces.add(interface)
d = json.loads(self.delta)
- hid = self.hostnetworkrelation.host.labid
+ hid = self.hostnetworkrelation.resource_id
if hid not in d:
d[hid] = {}
d[hid][interface.mac_address] = []
@@ -809,6 +809,9 @@ class HostHardwareRelation(TaskRelation):
raise ValidationError("resource_id " + str(self.resource_id) + " does not refer to a single resource")
super().save(*args, **kwargs)
+ def get_resource(self):
+ return ResourceQuery.get(labid=self.resource_id)
+
class HostNetworkRelation(TaskRelation):
resource_id = models.CharField(max_length=200, default="default_id")
@@ -827,6 +830,9 @@ class HostNetworkRelation(TaskRelation):
raise ValidationError("resource_id " + str(self.resource_id) + " does not refer to a single resource")
super().save(*args, **kwargs)
+ def get_resource(self):
+ return ResourceQuery.get(labid=self.resource_id)
+
class SnapshotRelation(TaskRelation):
snapshot = models.ForeignKey(Image, on_delete=models.CASCADE)
@@ -1011,7 +1017,7 @@ class JobFactory(object):
@classmethod
def make_bridge_config(cls, booking):
- if booking.resource.hosts.count() < 2:
+ if len(booking.resource.get_resources()) < 2:
return None
try:
jumphost_config = ResourceOPNFVConfig.objects.filter(
@@ -1049,7 +1055,7 @@ class JobFactory(object):
opnfv_api_config.set_xdf(booking, False)
opnfv_api_config.save()
- for host in booking.resource.hosts.all():
+ for host in booking.resource.get_resources():
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)