1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

F #5335: Add remotes connections with EXTERNAL_IP (#1099)

This commit is contained in:
Sergio Betanzos 2021-04-14 11:22:12 +02:00 committed by Ruben S. Montero
parent 04fd2da4c9
commit d634bb5aa6
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
5 changed files with 21 additions and 29 deletions

View File

@ -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

View File

@ -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;
}
});

View File

@ -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,
})));

View File

@ -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;

View File

@ -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) : '';