display count of ready slivers in tenant view
Scott Baker [Thu, 22 Jan 2015 23:21:24 +0000 (15:21 -0800)]
planetstack/core/xoslib/methods/sliceplus.py
planetstack/core/xoslib/objects/sliceplus.py
planetstack/core/xoslib/static/js/xosTenant.js

index 9e93e6d..0a8852a 100644 (file)
@@ -43,6 +43,7 @@ class SlicePlusIdSerializer(serializers.ModelSerializer, PlusSerializerMixin):
         humanReadableName = serializers.SerializerMethodField("getHumanReadableName")\r
         network_ports = NetworkPortsField(required=False)\r
         site_allocation = DictionaryField(required=False)\r
+        site_ready = DictionaryField(required=False)\r
         users = ListField(required=False)\r
         user_names = ListField(required=False) # readonly = True ?\r
         current_user_can_see = serializers.SerializerMethodField("getCurrentUserCanSee")\r
@@ -66,7 +67,7 @@ class SlicePlusIdSerializer(serializers.ModelSerializer, PlusSerializerMixin):
             model = SlicePlus\r
             fields = ('humanReadableName', 'id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','service','network','mount_data_sets',
                       'default_image', 'default_flavor',
-                      'serviceClass','creator','networks','sliceInfo','network_ports','backendIcon','backendHtml','site_allocation','users',"user_names","current_user_can_see")
+                      'serviceClass','creator','networks','sliceInfo','network_ports','backendIcon','backendHtml','site_allocation','site_ready','users',"user_names","current_user_can_see")
 
 class SlicePlusList(PlusListCreateAPIView):
     queryset = SlicePlus.objects.select_related().all()
index 94174b4..d3e618d 100644 (file)
@@ -19,6 +19,7 @@ class SlicePlus(Slice, PlusObjectMixin):
     def getSliceInfo(self, user=None):
         if not self._sliceInfo:
             used_sites = {}
+            ready_sites = {}
             used_deployments = {}
             sliverCount = 0
             sshCommands = []
@@ -33,6 +34,8 @@ class SlicePlus(Slice, PlusObjectMixin):
                     sshCommand = 'ssh -o "ProxyCommand ssh -q %s@%s" ubuntu@%s' % (sliver.instance_id, sliver.node.name, sliver.instance_name)
                     sshCommands.append(sshCommand);
 
+                    ready_sites[site.name] = ready_sites.get(site.name, 0) + 1
+
             users = {}
             for priv in SlicePrivilege.objects.filter(slice=self):
                 if not (priv.user.id in users.keys()):
@@ -51,6 +54,7 @@ class SlicePlus(Slice, PlusObjectMixin):
                     networkPorts = network.ports
 
             self._sliceInfo= {"sitesUsed": used_sites,
+                    "sitesReady": ready_sites,
                     "deploymentsUsed": used_deployments,
                     "sliverCount": sliverCount,
                     "siteCount": len(used_sites.keys()),
@@ -67,6 +71,14 @@ class SlicePlus(Slice, PlusObjectMixin):
         return self._sliceInfo
 
     @property
+    def site_ready(self):
+        return self.getSliceInfo()["sitesReady"]
+
+    @site_ready.setter
+    def site_ready(self, value):
+        pass
+
+    @property
     def site_allocation(self):
         return self._site_allocation
 
index 0182f9f..79e093e 100644 (file)
@@ -5,7 +5,7 @@ XOSTenantSite = XOSModel.extend( {
 });
 
 XOSTenantSiteCollection = XOSCollection.extend( {
-    listFields: ["name", "allocated"],
+    listFields: ["name", "allocated", "ready"],
     modelName: "tenantSite",
     collectionName: "tenantSites",
 
@@ -14,17 +14,33 @@ XOSTenantSiteCollection = XOSCollection.extend( {
         var id = 0;
         for (siteName in slice.attributes.site_allocation) {
             allocated = slice.attributes.site_allocation[siteName];
-            tenantSites.push(new XOSTenantSite( { name: siteName, allocated: allocated, id: id} ));
+            ready = slice.attributes.site_ready[siteName] || 0;
+            tenantSites.push(new XOSTenantSite( { name: siteName, allocated: allocated, ready: ready, id: id} ));
             id = id + 1;
         }
         for (index in xos.tenantview.models[0].attributes.blessed_site_names) {
             siteName = xos.tenantview.models[0].attributes.blessed_site_names[index];
             if (! (siteName in slice.attributes.site_allocation)) {
-                tenantSites.push(new XOSTenantSite( { name: siteName, allocated: 0, id: id} ));
+                tenantSites.push(new XOSTenantSite( { name: siteName, allocated: 0, ready: 0, id: id} ));
                 id = id + 1;
             }
         }
         this.set(tenantSites);
+
+        var that=this;
+        this.listenTo(slice, 'change', function() { that.getReadyFromSlice(slice); })
+    },
+
+    getReadyFromSlice: function(slice) {
+        for (siteName in slice.attributes.site_ready) {
+            ready = slice.attributes.site_ready[siteName];
+            for (index in this.models) {
+                tenantSite = this.models[index];
+                if (tenantSite.attributes.name == siteName) {
+                    tenantSite.set("ready", ready);
+                }
+            }
+        }
     },
 
     putToSlice: function(slice) {
@@ -135,7 +151,7 @@ XOSTenantApp.buildViews = function() {
 \r
      tenantSummaryClass = XOSTenantSummaryView.extend({template: "#xos-detail-template",\r
                                                 app: XOSTenantApp,\r
-                                                detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"],\r
+                                                detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports"],\r
                                                 fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image", "mount_data_sets": "Data Sets"},\r
                                                 helpText: {"serviceClass": "Existing slivers will be re-instantiated if changed",\r
                                                            "default_image": "Existing slivers will be re-instantiated if changed",\r