SSH commands dialog
Scott Baker [Tue, 20 Jan 2015 09:02:08 +0000 (01:02 -0800)]
planetstack/core/xoslib/dashboards/xosTenant.html
planetstack/core/xoslib/objects/sliceplus.py
planetstack/core/xoslib/static/js/xosTenant.js

index 6735da3..141e3ee 100644 (file)
@@ -22,6 +22,7 @@
     <button class="btn btn-high btn-tenant-create">Create New Slice</button>
     <button class="btn btn-high btn-tenant-delete">Delete Slice</button>
     <button class="btn btn-high btn-tenant-add-user">Edit Users</button>
+    <button class="btn btn-high btn-tenant-download-ssh">SSH Commands</button>
     <button class="btn btn-high btn-tenant-save">Save</button>
   </div>
 </script>
 <div id="tenant-edit-users-dialog" title="Edit Users">\r
 <div id="tenant-edit-users-interior"></div>\r
 </div>\r
+\r
+<div id="tenant-ssh-commands-dialog" title="SSH Commands">\r
+<div id="tenant-ssh-commands-interior"></div>\r
+</div>\r
 
 <div id="xos-error-dialog" title="Error Message">
 </div>\r
index 7e9836c..9187bff 100644 (file)
@@ -19,6 +19,7 @@ class SlicePlus(Slice, PlusObjectMixin):
             used_sites = {}
             used_deployments = {}
             sliverCount = 0
+            sshCommands = []
             for sliver in self.slivers.all():
                 site = sliver.node.site_deployment.site
                 deployment = sliver.node.site_deployment.deployment
@@ -26,6 +27,10 @@ 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);
+
             users = {}
             for priv in SlicePrivilege.objects.filter(slice=self):
                 if not (priv.user.id in users.keys()):
@@ -37,7 +42,8 @@ class SlicePlus(Slice, PlusObjectMixin):
                     "sliverCount": sliverCount,
                     "siteCount": len(used_sites.keys()),
                     "users": users,
-                    "roles": []}
+                    "roles": [],
+                    "sshCommands": sshCommands}
 
         if user:
             auser = self._sliceInfo["users"].get(user.id, None)
index 286537d..07762ed 100644 (file)
@@ -72,6 +72,7 @@ XOSTenantButtonView = Marionette.ItemView.extend({
                      "click button.btn-tenant-delete": "deleteClicked",
                      "click button.btn-tenant-add-user": "addUserClicked",
                      "click button.btn-tenant-save": "saveClicked",
+                     "click button.btn-tenant-download-ssh": "downloadClicked",
                      },
 
             createClicked: function(e) {
@@ -86,6 +87,10 @@ XOSTenantButtonView = Marionette.ItemView.extend({
                      XOSTenantApp.editUsers(this.options.linkedView.model);
                      },
 
+            downloadClicked: function(e) {
+                     XOSTenantApp.downloadSSH(this.options.linkedView.model);
+                     },
+
             saveClicked: function(e) {
                      model = this.options.linkedView.model;
                      model.tenantSiteCollection.putToSlice(model);
@@ -113,6 +118,7 @@ XOSTenantApp.addRegions({
     tenantButtons: "#tenantButtons",
     tenantAddSliceInterior: "#tenant-addslice-interior",
     tenantEditUsersInterior: "#tenant-edit-users-interior",
+    tenantSSHCommandsInterior: "#tenant-ssh-commands-interior",
 });
 
 XOSTenantApp.setDirty = function(dirty) {
@@ -269,6 +275,51 @@ XOSTenantApp.editUsers = function(model) {
     $("#tenant-edit-users-dialog").dialog("open");\r
 };\r
 \r
+XOSTenantApp.downloadSSHOld = function(model) {\r
+    sshCommands = "";\r
+    for (index in model.attributes.sliceInfo.sshCommands) {\r
+         sshCommand = model.attributes.sliceInfo.sshCommands[index];\r
+         sshCommands = sshCommands + sshCommand + "\n";\r
+    }\r
+\r
+    if (sshCommands.length == 0) {\r
+         alert("this slice has no instantiated slivers yet");\r
+         return;\r
+    }\r
+\r
+    var myWindow = window.open("", "ssh_command_list",""); // "width=640, height=480");\r
+    myWindow.document.write("<html><head><title>SSH Commands</title></head><body><pre>" + sshCommands + "</pre></body></html>");\r
+    myWindow.document.close();\r
+};\r
+\r
+XOSTenantApp.downloadSSH = function(model) {\r
+    sshCommands = "";\r
+    for (index in model.attributes.sliceInfo.sshCommands) {\r
+         sshCommand = model.attributes.sliceInfo.sshCommands[index];\r
+         sshCommands = sshCommands + sshCommand + "\n";\r
+    }\r
+\r
+    if (sshCommands.length == 0) {\r
+         alert("this slice has no instantiated slivers yet");\r
+         return;\r
+    }\r
+\r
+    var htmlView = new HTMLView({html: "<pre>" + sshCommands + "</pre>"});\r
+    XOSTenantApp.tenantSSHCommandsInterior.show(htmlView);\r
+\r
+    $("#tenant-ssh-commands-dialog").dialog({\r
+       autoOpen: false,
+       modal: true,
+       width: 640,
+       buttons : {
+            "Ok" : function() {
+              $(this).dialog("close");
+            },
+          }
+        });
+    $("#tenant-ssh-commands-dialog").dialog("open");\r
+};\r
+\r
 XOSTenantApp.deleteSlice = function(model) {\r
     var app=this;\r
     app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); });\r