add networkPorts
Scott Baker [Fri, 9 Jan 2015 06:34:51 +0000 (22:34 -0800)]
planetstack/core/xoslib/methods/sliceplus.py
planetstack/core/xoslib/objects/sliceplus.py

index 48102df..0e0a940 100644 (file)
@@ -15,11 +15,19 @@ else:
     # rest_framework 2.x
     IdField = serializers.Field
 
+class NetworkPortsField(serializers.WritableField):   # note: maybe just Field in rest_framework 3.x instead of WritableField
+    def to_representation(self, obj):
+        return obj
+
+    def to_internal_value(self, data):
+        return data
+
 class SlicePlusIdSerializer(serializers.ModelSerializer, PlusSerializerMixin):
         id = IdField()
 \r
         sliceInfo = serializers.SerializerMethodField("getSliceInfo")\r
         humanReadableName = serializers.SerializerMethodField("getHumanReadableName")\r
+        networkPorts = NetworkPortsField()\r
 \r
         def getSliceInfo(self, slice):\r
             return slice.getSliceInfo(user=self.context['request'].user)\r
@@ -27,12 +35,12 @@ class SlicePlusIdSerializer(serializers.ModelSerializer, PlusSerializerMixin):
         def getHumanReadableName(self, obj):\r
             return str(obj)\r
 \r
-        networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')\r
-        availableNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')\r
+        networks = serializers.PrimaryKeyRelatedField(many=True, read_only=True)\r
+#        availableNetworks = serializers.PrimaryKeyRelatedField(many=True, read_only=True, view_name='network-detail')\r
 \r
         class Meta:\r
             model = SlicePlus\r
-            fields = ('humanReadableName', 'id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','image_preference','service','network','mount_data_sets','serviceClass','creator','networks','availableNetworks','sliceInfo','backendIcon','backendHtml')
+            fields = ('humanReadableName', 'id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','image_preference','service','network','mount_data_sets','serviceClass','creator','networks','sliceInfo','networkPorts','backendIcon','backendHtml')
 
 class SlicePlusList(generics.ListCreateAPIView):
     queryset = SlicePlus.objects.select_related().all()
index ddec295..f4a5e0a 100644 (file)
@@ -26,6 +26,23 @@ class SlicePlus(Slice, PlusObjectMixin):
                 "siteCount": len(used_sites.keys()),
                 "roles": roles}
 
+    @property
+    def networkPorts(self):
+        # XXX this assumes there is only one network that can have ports bound
+        # to it for a given slice. This is intended for the tenant view, which
+        # will obey this field.
+        networkPorts = ""
+        for networkSlice in self.networkslices.all():
+            network = networkSlice.network
+            if network.ports:
+                networkPorts = network.ports
+
+        return networkPorts
+
+    @networkPorts.setter
+    def networkPorts(self, value):
+        print "XXX set networkPorts to", value
+
     @staticmethod
     def select_by_user(user):
         if user.is_admin: