diff --git a/src/sunstone/models/sunstone_guac.rb b/src/sunstone/models/sunstone_guac.rb index 294e14e513..63e4895a9e 100644 --- a/src/sunstone/models/sunstone_guac.rb +++ b/src/sunstone/models/sunstone_guac.rb @@ -194,9 +194,7 @@ class SunstoneGuac return error(400, error_message) end else - hostname = vm_resource[ - '/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME' - ] + hostname = vm_resource['/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME'] end { @@ -208,13 +206,15 @@ class SunstoneGuac 'hostname' => hostname, 'port' => vm_resource['TEMPLATE/GRAPHICS/PORT'], 'password' => vm_resource['TEMPLATE/GRAPHICS/PASSWD'] - } + }.compact ) end def get_config_rdp(vm_resource) - hostname = vm_resource["TEMPLATE/NIC[RDP='YES'][1]/IP"] || - vm_resource["TEMPLATE/NIC_ALIAS[RDP='YES'][1]/IP"] + hostname = vm_resource["TEMPLATE/NIC[RDP='YES'][1]/EXTERNAL_IP"] || + vm_resource["TEMPLATE/NIC[RDP='YES'][1]/IP"] || + vm_resource["TEMPLATE/NIC_ALIAS[RDP='YES'][1]/EXTERNAL_IP"] || + vm_resource["TEMPLATE/NIC_ALIAS[RDP='YES'][1]/IP"] if hostname.nil? error_message = 'Wrong configuration. Cannot find a NIC with RDP' @@ -232,13 +232,15 @@ class SunstoneGuac 'port' => vm_resource['TEMPLATE/CONTEXT/RDP_PORT'], 'username' => vm_resource['TEMPLATE/CONTEXT/USERNAME'], 'password' => vm_resource['TEMPLATE/CONTEXT/PASSWORD'] - } + }.compact ) end def get_config_ssh(vm_resource) - hostname = vm_resource["TEMPLATE/NIC[SSH='YES'][1]/IP"] || - vm_resource["TEMPLATE/NIC_ALIAS[SSH='YES'][1]/IP"] + hostname = vm_resource["TEMPLATE/NIC[SSH='YES'][1]/EXTERNAL_IP"] || + vm_resource["TEMPLATE/NIC[SSH='YES'][1]/IP"] || + vm_resource["TEMPLATE/NIC_ALIAS[SSH='YES'][1]/EXTERNAL_IP"] || + vm_resource["TEMPLATE/NIC_ALIAS[SSH='YES'][1]/IP"] if hostname.nil? error_message = 'Wrong configuration. Cannot find a NIC with SSH' @@ -256,7 +258,7 @@ class SunstoneGuac 'port' => vm_resource['TEMPLATE/CONTEXT/SSH_PORT'], 'username' => vm_resource['TEMPLATE/CONTEXT/USERNAME'], 'password' => vm_resource['TEMPLATE/CONTEXT/PASSWORD'] - } + }.compact ) end diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 74cfa02b0c..c7a27a8d5e 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -1238,6 +1238,7 @@ define(function(require) { */ function isConnectionSupported(element, typeConnection) { var isEnabled = false; + if ( $.inArray(String(typeConnection).toLowerCase(), ['rdp', 'ssh']) > -1 && element && element.TEMPLATE && element.TEMPLATE.GRAPHICS && element.LCM_STATE @@ -1267,7 +1268,7 @@ define(function(require) { nic[typeConnection] && String(nic[typeConnection]).toLowerCase() === "yes" ) { - activated = nic; + activated = nic.EXTERNAL_IP || nic.IP; } }); diff --git a/src/sunstone/public/app/tabs/provision-tab/vms/list.js b/src/sunstone/public/app/tabs/provision-tab/vms/list.js index 2ec2bdf17d..7dcfa55de5 100644 --- a/src/sunstone/public/app/tabs/provision-tab/vms/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/vms/list.js @@ -759,7 +759,7 @@ define(function(require) { context.on("click", ".provision_rdp_button", function() { var vm = $(".provision_info_vm", context).data("vm") || {}; - var rdp = OpenNebulaVM.isConnectionSupported(vm, 'rdp') || {}; + var rdpIp = OpenNebulaVM.isConnectionSupported(vm, 'rdp'); var username, password; if (vm.TEMPLATE && vm.TEMPLATE.CONTEXT) { @@ -773,7 +773,7 @@ define(function(require) { Sunstone.runAction("VM.save_rdp", JSON.parse(JSON.stringify({ name: vm.NAME, - ip: rdp.IP, + ip: rdpIp, username: username, password: password, }))); diff --git a/src/sunstone/public/app/tabs/vms-tab/actions.js b/src/sunstone/public/app/tabs/vms-tab/actions.js index 53ff8afd7c..df9b46175a 100644 --- a/src/sunstone/public/app/tabs/vms-tab/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/actions.js @@ -194,6 +194,7 @@ define(function(require) { type: "custom", call: function(args) { var vm = Sunstone.getElementRightInfo(TAB_ID); + var rdpIp = OpenNebulaVM.isConnectionSupported(vm, 'rdp'); if (args && args.ip && args.name) { var credentials = {}; @@ -201,20 +202,8 @@ define(function(require) { args.password && (credentials["PASSWORD"] = args.password); Files.downloadRdpFile(args.ip, args.name, credentials); } - else if (vm && vm.NAME && vm.TEMPLATE && vm.TEMPLATE.NIC) { + else if (vm && vm.NAME && vm.TEMPLATE && rdpIp) { var name = vm.NAME; - var nics = vm.TEMPLATE.NIC; - nics = Array.isArray(nics) ? vm.TEMPLATE.NIC : [vm.TEMPLATE.NIC]; - - // append nic_alias in nics - if (vm.TEMPLATE.NIC_ALIAS) { - var alias = vm.TEMPLATE.NIC_ALIAS; - alias = Array.isArray(alias) ? alias : [alias]; - nics = $.merge(alias, nics) - } - - var nic = nics.find(function(n) { return n.RDP && String(n.RDP).toUpperCase() === "YES" }); - var ip = nic && nic.IP ? nic.IP : ''; var credentials = {}; if (vm.TEMPLATE.CONTEXT) { @@ -226,7 +215,7 @@ define(function(require) { } } - nic && Files.downloadRdpFile(ip, name, credentials); + Files.downloadRdpFile(rdpIp, name, credentials); } else { Notifier.notifyError(Locale.tr("Data for rdp file isn't correct")); return false; diff --git a/src/sunstone/public/app/utils/remote-actions.js b/src/sunstone/public/app/utils/remote-actions.js index 37247bccd6..90cf754468 100644 --- a/src/sunstone/public/app/utils/remote-actions.js +++ b/src/sunstone/public/app/utils/remote-actions.js @@ -226,8 +226,8 @@ define(function(require) { var wFile = OpenNebulaVM.isWFileSupported(vm); actions += wFile ? buttonWFile(vm.ID, wFile) : ''; - var rdp = OpenNebulaVM.isConnectionSupported(vm, 'rdp'); - actions += rdp ? dropdownRDP(vm.ID, rdp.IP, vm) : ''; + var rdpIp = OpenNebulaVM.isConnectionSupported(vm, 'rdp'); + actions += rdpIp ? dropdownRDP(vm.ID, rdpIp, vm) : ''; var ssh = OpenNebulaVM.isConnectionSupported(vm, 'ssh'); actions += ssh && Config.isTabActionEnabled("vms-tab", "VM.rdp") ? buttonSSH(vm.ID) : '';