X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2FxosTenant.js;h=4225caccbc54bf9e311c96361ba755d8d26d8348;hb=8ce133b9805597522ff5957d6a879f9b078787eb;hp=286537db1138a953573bb93393594dd64af662fd;hpb=c2d7c700233884cf21df441192598df8347994ea;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js index 286537d..4225cac 100644 --- a/planetstack/core/xoslib/static/js/xosTenant.js +++ b/planetstack/core/xoslib/static/js/xosTenant.js @@ -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) { @@ -72,6 +88,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 +103,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 +134,7 @@ XOSTenantApp.addRegions({ tenantButtons: "#tenantButtons", tenantAddSliceInterior: "#tenant-addslice-interior", tenantEditUsersInterior: "#tenant-edit-users-interior", + tenantSSHCommandsInterior: "#tenant-ssh-commands-interior", }); XOSTenantApp.setDirty = function(dirty) { @@ -129,8 +151,11 @@ XOSTenantApp.buildViews = function() { tenantSummaryClass = XOSTenantSummaryView.extend({template: "#xos-detail-template", app: XOSTenantApp, - detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"], + detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports"], fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image", "mount_data_sets": "Data Sets"}, + helpText: {"serviceClass": "Existing slivers will be re-instantiated if changed", + "default_image": "Existing slivers will be re-instantiated if changed", + "default_flavor": "Existing slivers will be re-instantiated if changed"}, onShow: function() { // the slice selector is in a different table, so make every label cell the maximal width @@ -169,6 +194,9 @@ XOSTenantApp.buildViews = function() { sliceChanged: function(id) { XOSTenantApp.navToSlice(id); }, + filter: function(slice) { + return slice.attributes.current_user_can_see; + }, }); xos.sites.fetch(); @@ -269,6 +297,42 @@ XOSTenantApp.editUsers = function(model) { $("#tenant-edit-users-dialog").dialog("open"); }; +XOSTenantApp.downloadSSH = function(model) { + var sshCommands = ""; + for (index in model.attributes.sliceInfo.sshCommands) { + sshCommand = model.attributes.sliceInfo.sshCommands[index]; + sshCommands = sshCommands + sshCommand + "\n"; + } + + if (sshCommands.length == 0) { + alert("this slice has no instantiated slivers yet"); + return; + } + + var htmlView = new HTMLView({html: '
' + sshCommands + '
'}); + XOSTenantApp.tenantSSHCommandsInterior.show(htmlView); + + $("#tenant-ssh-commands-dialog").dialog({ + autoOpen: false, + modal: true, + width: 640, + buttons : { + "Download": function() { + var dlLink = document.createElement('a'); + dlLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(sshCommands)); + dlLink.setAttribute('download', 'sshcommands.txt'); + dlLink.click(); + + //window.open('data:text/text,' + encodeURIComponent(sshCommands)); + }, + "Close" : function() { + $(this).dialog("close"); + }, + } + }); + $("#tenant-ssh-commands-dialog").dialog("open"); +}; + XOSTenantApp.deleteSlice = function(model) { var app=this; app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); });