return backend status in sliceplus object
diff --git a/planetstack/core/xoslib/methods/plus.py b/planetstack/core/xoslib/methods/plus.py
new file mode 100644
index 0000000..1e4cdf5
--- /dev/null
+++ b/planetstack/core/xoslib/methods/plus.py
@@ -0,0 +1,22 @@
+from rest_framework import serializers
+
+""" PlusSerializerMixin
+
+ Implements Serializer fields that are common to all OpenCloud objects. For
+ example, stuff related to backend fields.
+"""
+
+class PlusSerializerMixin():
+ backendIcon = serializers.SerializerMethodField("getBackendIcon")
+ backendHtml = serializers.SerializerMethodField("getBackendHtml")
+
+ # This will cause a descendant class to pull in the methods defined
+ # above. See rest_framework/serializers.py: _get_declared_fields().
+ base_fields = {"backendIcon": backendIcon, "backendHtml": backendHtml}
+
+ def getBackendIcon(self, obj):
+ return obj.getBackendIcon()
+
+ def getBackendHtml(self, obj):
+ return obj.getBackendHtml()
+
diff --git a/planetstack/core/xoslib/methods/sliceplus.py b/planetstack/core/xoslib/methods/sliceplus.py
index f990275..bb93dc6 100644
--- a/planetstack/core/xoslib/methods/sliceplus.py
+++ b/planetstack/core/xoslib/methods/sliceplus.py
@@ -6,8 +6,9 @@
from core.models import *
from django.forms import widgets
from core.xoslib.objects.sliceplus import SlicePlus
+from plus import PlusSerializerMixin
-class SlicePlusIdSerializer(serializers.ModelSerializer):
+class SlicePlusIdSerializer(serializers.ModelSerializer, PlusSerializerMixin):
id = serializers.Field()
sliceInfo = serializers.SerializerMethodField("getSliceInfo")
@@ -20,7 +21,7 @@
class Meta:
model = SlicePlus
- fields = ('id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','sliceInfo')
+ fields = ('id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','sliceInfo','backendIcon','backendHtml')
class SlicePlusList(generics.ListCreateAPIView):
queryset = SlicePlus.objects.select_related().all()
diff --git a/planetstack/core/xoslib/objects/plus.py b/planetstack/core/xoslib/objects/plus.py
new file mode 100644
index 0000000..f183f33
--- /dev/null
+++ b/planetstack/core/xoslib/objects/plus.py
@@ -0,0 +1,22 @@
+""" PlusObjectMixin
+
+ Implements fields that are common to all OpenCloud objects. For example,
+ stuff related to backend icons.
+"""
+
+class PlusObjectMixin:
+ def getBackendIcon(self):
+ if (self.enacted is not None) and self.enacted >= self.updated:
+ return "/static/admin/img/icon_success.gif"
+ else:
+ if self.backend_status == "Provisioning in progress" or self.backend_status=="":
+ return "/static/admin/img/icon_clock.gif"
+ else:
+ return "/static/admin/img/icon_error.gif"
+
+ def getBackendHtml(self):
+ if (self.enacted is not None) and self.enacted >= self.updated:
+ return '<img src="%s">' % self.getBackendIcon()
+ else:
+ return '<div title="%s"><img src="%s"></div>' % (self.backend_status, self.getBackendIcon())
+
diff --git a/planetstack/core/xoslib/objects/sliceplus.py b/planetstack/core/xoslib/objects/sliceplus.py
index 2542fd7..a5d7a7e 100644
--- a/planetstack/core/xoslib/objects/sliceplus.py
+++ b/planetstack/core/xoslib/objects/sliceplus.py
@@ -1,6 +1,7 @@
from core.models.slice import Slice
+from plus import PlusObjectMixin
-class SlicePlus(Slice):
+class SlicePlus(Slice, PlusObjectMixin):
class Meta:
proxy = True