From 196265c1210e1c3ad0693da0282cb62d62d4a8d1 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 24 Feb 2015 16:06:29 +0100 Subject: [PATCH] bug #3612: do not consider hybrid ips as nice --- src/cli/one_helper/onevm_helper.rb | 57 +---------------------- src/sunstone/public/js/plugins/vms-tab.js | 39 ++-------------- src/sunstone/public/js/sunstone.js | 55 +++++++++++----------- 3 files changed, 33 insertions(+), 118 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 794d4520ac..a4be380b07 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -404,36 +404,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper end if !options[:all] end - if vm.has_elements?("/VM/USER_TEMPLATE/HYPERVISOR") - vm_information = vm.to_hash['VM'] - hybridvisor = vm_information['USER_TEMPLATE']['HYPERVISOR'].to_s - isHybrid = %w{vcenter ec2 azure softlayer}.include? hybridvisor - - if isHybrid - vm_tmplt = vm_information['TEMPLATE'] - nic = {"NETWORK" => "-", - "IP" => "-", - "MAC"=> "-", - "VLAN"=>"no", - "BRIDGE"=>"-"} - - case hybridvisor - when "vcenter" - nic["IP"] = vm_tmplt['GUEST_IP'] if vm_tmplt['GUEST_IP'] - when "ec2" - nic["IP"] = vm_tmplt['IP_ADDRESS'] if vm_tmplt['IP_ADDRESS'] - when "azure" - nic["IP"] = vm_tmplt['IPADDRESS'] if vm_tmplt['IPADDRESS'] - when "softlayer" - nic["IP"] = vm_tmplt['PRIMARYIPADDRESS'] if vm_tmplt['PRIMARYIPADDRESS'] - else - isHybrid = false - end - - vm_nics = [nic] - end - end - sg_nics = [] if (vm.has_elements?("/VM/TEMPLATE/NIC/SECURITY_GROUPS")) @@ -448,33 +418,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper end end - if vm.has_elements?("/VM/TEMPLATE/NIC") || vm_nics + if vm.has_elements?("/VM/TEMPLATE/NIC") puts CLIHelper.print_header(str_h1 % "VM NICS",false) - # vm_nics is defined for hybridvisors. If there are both IP from - # the hybridvisor and from OpenNebula nics check if the IP is the - # same as one of IPs generated by OpenNebula and show standard - # information. If it's a different IP show all the information. - # - # The template can already contain one NIC not controled by - # OpenNebula and we want to show also that info. - if vm_nics - if vm.has_elements?("/VM/TEMPLATE/NIC") - nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten - ips = nics.map {|n| n['IP'] } - ip = vm_nics.first['IP'] - - if ips.include? ip - vm_nics = nics - else - vm_nics += nics - end - end - else - vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten - end - nic_default = {"NETWORK" => "-", "IP" => "-", "MAC"=> "-", @@ -482,7 +429,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper "BRIDGE"=>"-"} array_id = 0 - + vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten vm_nics.each {|nic| next if nic.has_key?("CLI_DONE") diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index eb80fc264e..5bd2b22a29 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -2143,41 +2143,10 @@ function printNics(vm_info){ var nics = [] - if (isHybrid) - { - nic = {}; - nic.NIC_ID = 0; - nic.ATTACH = "NO"; - nic.NETWORK = "-"; - nic.MAC = "-"; - - switch(vm_info.USER_TEMPLATE.HYPERVISOR.toLowerCase()) - { - case "ec2": - nic.IP = vm_info.TEMPLATE.IP_ADDRESS?vm_info.TEMPLATE.IP_ADDRESS:"--"; - break; - case "azure": - nic.IP = vm_info.TEMPLATE.IPADDRESS?vm_info.TEMPLATE.IPADDRESS:"--"; - break; - case "softlayer": - nic.IP = vm_info.TEMPLATE.PRIMARYIPADDRESS?vm_info.TEMPLATE.PRIMARYIPADDRESS:"--"; - break; - default: - nic.IP = "--"; - } - - nics = [nic]; - - } - else - { - if ($.isArray(vm_info.TEMPLATE.NIC)) - nics = vm_info.TEMPLATE.NIC - else if (!$.isEmptyObject(vm_info.TEMPLATE.NIC)) - nics = [vm_info.TEMPLATE.NIC] - } - - + if ($.isArray(vm_info.TEMPLATE.NIC)) + nics = vm_info.TEMPLATE.NIC + else if (!$.isEmptyObject(vm_info.TEMPLATE.NIC)) + nics = [vm_info.TEMPLATE.NIC] if (!nics.length){ html += '\ diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 65006764c6..26a107d959 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -8273,52 +8273,51 @@ function isNICAttachSupported(vm_info){ // Return the IP or several IPs of a VM function ip_str(vm, divider){ var divider = divider || "
" - var isHybrid = calculate_isHybrid(vm); var nic = vm.TEMPLATE.NIC; + var ips = []; - if (nic == undefined) { - if (isHybrid) { - switch(vm.USER_TEMPLATE.HYPERVISOR.toLowerCase()) { - case "vcenter": - ip = vm.TEMPLATE.GUEST_IP?vm.TEMPLATE.GUEST_IP:"--"; - break; - case "ec2": - ip = vm.TEMPLATE.IP_ADDRESS?vm.TEMPLATE.IP_ADDRESS:"--"; - break; - case "azure": - ip = vm.TEMPLATE.IPADDRESS?vm.TEMPLATE.IPADDRESS:"--"; - break; - case "softlayer": - ip = vm.TEMPLATE.PRIMARYIPADDRESS?vm.TEMPLATE.PRIMARYIPADDRESS:"--"; - break; - default: - ip = "--"; - } - } else { - return '--'; - } - } else { + if (nic != undefined) { if (!$.isArray(nic)){ nic = [nic]; } - ip = ''; $.each(nic, function(index,value){ if (value.IP){ - ip += value.IP+divider; + ips.push(value.IP); } if (value.IP6_GLOBAL){ - ip += value.IP6_GLOBAL+divider; + ips.push(value.IP6_GLOBAL); } if (value.IP6_ULA){ - ip += value.IP6_ULA+divider; + ips.push(value.IP6_ULA); } }); } - return ip; + if (vm.TEMPLATE.GUEST_IP && ($.inArray(vm.TEMPLATE.GUEST_IP, ips) == -1)) { + ips.push(vm.TEMPLATE.GUEST_IP); + } + + if (vm.TEMPLATE.AWS_IP_ADDRESS) { + ips.push(vm.TEMPLATE.AWS_IP_ADDRESS); + } + + if (vm.TEMPLATE.AZ_IPADDRESS) { + ips.push(vm.TEMPLATE.AZ_IPADDRESS); + } + + if (vm.TEMPLATE.SL_PRIMARYIPADDRESS) { + ips.push(vm.TEMPLATE.SL_PRIMARYIPADDRESS); + } + + + if (ips.length > 0) { + return ips.join(divider); + } else { + return '--'; + } }; // returns true if the vnc button should be enabled