From 71b8525d3c19e7fe7a69947e53bd1ca2549d93e8 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Wed, 5 May 2021 16:58:57 +0200 Subject: [PATCH] F #5270: Add google cloud support into sunstone (#1184) (cherry picked from commit 2d39e552ddd6ce61ecbefde85bd668a299a76957) --- src/sunstone/models/sunstone_guac.rb | 17 +++- src/sunstone/public/app/opennebula/vm.js | 91 ++++++++++++------- .../public/app/tabs/vms-tab/panels/info.js | 3 +- .../app/tabs/vms-tab/panels/info/html.hbs | 8 ++ src/sunstone/public/scss/app.scss | 4 +- 5 files changed, 85 insertions(+), 38 deletions(-) diff --git a/src/sunstone/models/sunstone_guac.rb b/src/sunstone/models/sunstone_guac.rb index 2ad045671a..c009d52c79 100644 --- a/src/sunstone/models/sunstone_guac.rb +++ b/src/sunstone/models/sunstone_guac.rb @@ -164,6 +164,21 @@ class SunstoneGuac < SunstoneRemoteConnections vm_resource["TEMPLATE/NIC_ALIAS[SSH='YES'][1]/EXTERNAL_IP"] || vm_resource["TEMPLATE/NIC_ALIAS[SSH='YES'][1]/IP"] + external_port_range = vm_resource['TEMPLATE/ + NIC[EXTERNAL_PORT_RANGE][1]/ + EXTERNAL_PORT_RANGE'] + + if external_port_range + ip = vm_resource['HISTORY_RECORDS/ + HISTORY[HOSTNAME][last()]/ + HOSTNAME'] + + unless ip.nil? + hostname = ip + port = Integer(external_port_range.split(':')[0]) + 21 + end + end + if hostname.nil? error_message = 'Wrong configuration. Cannot find a NIC with SSH' return { :error => error(400, error_message) } @@ -177,7 +192,7 @@ class SunstoneGuac < SunstoneRemoteConnections }.merge( { 'hostname' => hostname, - 'port' => vm_resource['TEMPLATE/CONTEXT/SSH_PORT'], + 'port' => port || vm_resource['TEMPLATE/CONTEXT/SSH_PORT'], 'username' => vm_resource['TEMPLATE/CONTEXT/USERNAME'], 'password' => vm_resource['TEMPLATE/CONTEXT/PASSWORD'] } diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index f72f53893e..bfa21da3c4 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -775,28 +775,10 @@ define(function(require) { } }, "hostnameStr": function(element) { - var state = element.STATE; - var hostname = "--"; - if (state == STATES.ACTIVE || state == STATES.SUSPENDED || state == STATES.POWEROFF) { - var history = retrieveLastHistoryRecord(element); - if (history) { - hostname = history.HOSTNAME; - }; - }; - - return hostname; + return hostnameStr(element) }, "hostnameStrLink": function(element) { - var state = element.STATE; - var hostname = "--"; - if (state == STATES.ACTIVE || state == STATES.SUSPENDED || state == STATES.POWEROFF) { - var history = retrieveLastHistoryRecord(element); - if (history) { - hostname = Navigation.link(history.HOSTNAME, "hosts-tab", history.HID); - }; - }; - - return hostname; + return hostnameStr(element, true) }, "clusterStr": function(element) { var state = element.STATE; @@ -825,38 +807,75 @@ define(function(require) { "migrateActionStr": function(stateId) { return MIGRATE_ACTION_STR[stateId]; }, - "ipsStr": ipsStr, - "ipsDropdown": ipsDropdown, "groupByIpsStr": groupByIpsStr, - "retrieveExternalIPs": retrieveExternalIPs, - "retrieveExternalNetworkAttrs": retrieveExternalNetworkAttrs, - "isNICGraphsSupported": isNICGraphsSupported, + "hasConnection": hasConnection, + "ipsDropdown": ipsDropdown, + "ipsStr": ipsStr, + "getSshWithPortForwarding": getSshWithPortForwarding, + "isConnectionSupported": isConnectionSupported, "isDiskGraphsSupported": isDiskGraphsSupported, "isNICAttachSupported": isNICAttachSupported, - "isVNCSupported": isVNCSupported, - "isConnectionSupported": isConnectionSupported, - "isVMRCSupported": isVMRCSupported, + "isNICGraphsSupported": isNICGraphsSupported, "isSPICESupported": isSPICESupported, + "isVMRCSupported": isVMRCSupported, + "isVNCSupported": isVNCSupported, "isWFileSupported": isWFileSupported, - "hasConnection": hasConnection, "promiseGetVm" : _promiseGetVm, + "retrieveExternalIPs": retrieveExternalIPs, + "retrieveExternalNetworkAttrs": retrieveExternalNetworkAttrs, "getName": function(id){ return OpenNebulaAction.getName(id, RESOURCE); }, "isvCenterVM": isVCenterVM, }; - function _promiseGetVm({ id, success, async = true } = {}) { + function hostnameStr(element, navigationLink = false) { + var state = element.STATE; + var hostname = "--"; + if (state == STATES.ACTIVE || state == STATES.SUSPENDED || state == STATES.POWEROFF) { + var history = retrieveLastHistoryRecord(element); + if (history) { + hostname = navigationLink + ? Navigation.link(history.HOSTNAME, "hosts-tab", history.HID) + : history.HOSTNAME; + }; + }; + + return hostname; + } + + function getSshWithPortForwarding(vm = {}, navigationLink = false) { + var nics = vm.TEMPLATE && vm.TEMPLATE.NIC || []; + + var nic = $.grep(nics, function (v) { + return v.EXTERNAL_PORT_RANGE !== undefined; + })[0]; + + if (nic) { + var ip = '' + hostnameStr(vm, navigationLink) + ''; + var externalPortRange = '' + nic.EXTERNAL_PORT_RANGE + ''; + var internalPortRange = '' + nic.INTERNAL_PORT_RANGE.split('/')[0].replace('-', ':') + '' + + return ip + ' ports ' + externalPortRange + ' forwarded to VM ports ' + internalPortRange; + } + } + + function _promiseGetVm(options = {}) { + options = $.extend({ + id: '', + async: true + }, options); + return $.ajax({ - url: "vm/" + id, + url: "vm/" + options.id, type: "GET", success: function(response) { - if (typeof success === "function") { + if (typeof options.success === "function") { var vm = response ? response[RESOURCE] : undefined; - success(vm); + options.success(vm); } }, - async: async + async: options.async }); } @@ -1039,6 +1058,7 @@ define(function(require) { else if (ips.length === 1) return "

"+ips[0]+"

"; + var sshWithPortForwarding = getSshWithPortForwarding(element) || ''; var firstIP = ipsHtml.split("")[0]; ipsHtml = ipsHtml.split("")[1]; ipsHtml = @@ -1052,6 +1072,9 @@ define(function(require) { "
    " + ipsHtml + "
" + + "" + + sshWithPortForwarding + + "" + "" + ""; return ipsHtml; diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/info.js b/src/sunstone/public/app/tabs/vms-tab/panels/info.js index b5596a59f0..cc4d65c762 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/info.js @@ -80,6 +80,7 @@ define(function(require) { var lcmStateClass = OpenNebula.VM.lcmStateClass(this.element.LCM_STATE); var hostnameHTML = OpenNebula.VM.hostnameStrLink(this.element); var IP = OpenNebula.VM.ipsStr(this.element, { forceGroup: true }); + var sshWithPortForwarding = OpenNebula.VM.getSshWithPortForwarding(this.element, true); var vrouterHTML = "--"; @@ -139,7 +140,6 @@ define(function(require) { ""; } - return TemplateInfo({ "element": this.element, "renameTrHTML": renameTrHTML, @@ -151,6 +151,7 @@ define(function(require) { "prettyStartTime": prettyStartTime, "deployId": deployId, "IP": IP, + "sshWithPortForwarding": sshWithPortForwarding, "resched": resched, "permissionsTableHTML": permissionsTableHTML, "templateTableVcenterHTML": templateTableVcenterHTML, diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs index 85e6459685..2d2b84758e 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs @@ -69,6 +69,14 @@ + {{#if sshWithPortForwarding}} + + {{tr "Port forwarding"}} + {{{sshWithPortForwarding}}} + + + {{/if}} + {{tr "Start time"}} {{prettyStartTime}} diff --git a/src/sunstone/public/scss/app.scss b/src/sunstone/public/scss/app.scss index 3254ab131e..9c9be7d95a 100644 --- a/src/sunstone/public/scss/app.scss +++ b/src/sunstone/public/scss/app.scss @@ -179,11 +179,11 @@ textarea { } .right { - float: right !important; + float: right !important; } .left { - float: left !important; + float: left !important; } .graph {