display ssh command in sliver detail view
Scott Baker [Mon, 26 Jan 2015 06:16:13 +0000 (22:16 -0800)]
planetstack/core/admin.py
planetstack/core/models/sliver.py
planetstack/core/xoslib/objects/sliceplus.py

index 577719c..8ec00a9 100644 (file)
@@ -1107,9 +1107,9 @@ class TagAdmin(PlanetStackBaseAdmin):
 class SliverAdmin(PlanetStackBaseAdmin):
     form = SliverForm
     fieldsets = [
-        ('Sliver Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'node', 'ip', 'instance_id', 'instance_name', 'flavor', 'image', ], 'classes': ['suit-tab suit-tab-general'], })
+        ('Sliver Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'node', 'ip', 'instance_id', 'instance_name', 'flavor', 'image', 'ssh_command'], 'classes': ['suit-tab suit-tab-general'], })
     ]
-    readonly_fields = ('backend_status_text', )
+    readonly_fields = ('backend_status_text', 'ssh_command', )
     list_display = ['backend_status_icon', 'ip', 'instance_id', 'instance_name', 'slice', 'flavor', 'image', 'node', 'deployment']
     list_display_links = ('backend_status_icon', 'ip',)
 
@@ -1119,6 +1119,13 @@ class SliverAdmin(PlanetStackBaseAdmin):
 
     user_readonly_fields = ['slice', 'deployment', 'node', 'ip', 'instance_name', 'flavor', 'image']
 
+    def ssh_command(self, obj):
+        ssh_command = obj.get_ssh_command()
+        if ssh_command:
+            return ssh_command
+        else:
+            return "(not available)"
+
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'slice':
             kwargs['queryset'] = Slice.select_by_user(request.user)
@@ -1134,11 +1141,9 @@ class SliverAdmin(PlanetStackBaseAdmin):
     def get_formsets(self, request, obj=None):
         # make some fields read only if we are updating an existing record
         if obj == None:
-            #self.readonly_fields = ('ip', 'instance_name')
-            self.readonly_fields = ('backend_status_text',)
+            self.readonly_fields = ('backend_status_text', 'ssh_command', )
         else:
-            self.readonly_fields = ('backend_status_text',)
-            #self.readonly_fields = ('ip', 'instance_name', 'slice', 'image', 'key')
+            self.readonly_fields = ('backend_status_text', 'ssh_command',)
 
         for inline in self.get_inline_instances(request, obj):
             # hide MyInline in the add view
index d2f794f..61924cf 100644 (file)
@@ -155,3 +155,9 @@ class Sliver(PlCoreBase):
     def get_node_stats(self):
         # Note sure what should go back here
         return 1
+
+    def get_ssh_command(self):
+        if (not self.instance_id) or (not self.node) or (not self.instance_name):
+            return None
+        else:
+            return 'ssh -o "ProxyCommand ssh -q %s@%s" ubuntu@%s' % (self.instance_id, self.node.name, self.instance_name)
index 0c66258..6bbbfa2 100644 (file)
@@ -31,9 +31,9 @@ class SlicePlus(Slice, PlusObjectMixin):
                 used_deployments[deployment.name] = used_deployments.get(deployment.name, 0) + 1
                 sliverCount = sliverCount + 1
 
-                if (sliver.instance_id and sliver.instance_name):
-                    sshCommand = 'ssh -o "ProxyCommand ssh -q %s@%s" ubuntu@%s' % (sliver.instance_id, sliver.node.name, sliver.instance_name)
-                    sshCommands.append(sshCommand);
+                sshCommand = sliver.get_ssh_command()
+                if sshCommand:
+                    sshCommands.append(sshCommand)
 
                     ready_sites[site.name] = ready_sites.get(site.name, 0) + 1