From 0672a17787eeb55effae940364a2e529a21d1c98 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 7 Oct 2014 19:12:06 +0200 Subject: [PATCH] Feature #3227: Add CLI support for hybrid IP display --- src/cli/one_helper/onevm_helper.rb | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 9c6ad497d7..99dabb9bca 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -404,11 +404,41 @@ class OneVMHelper < OpenNebulaHelper::OneHelper end if !options[:all] end - if vm.has_elements?("/VM/TEMPLATE/NIC") + 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['GUEST_IP'] if vm_tmplt['IP_ADDRESS'] + when "azure" + nic.IP = vm_tmplt['GUEST_IP'] if vm_tmplt['IPADDRESS'] + when "softlayer" + nic.IP = vm_tmplt['GUEST_IP'] if vm_tmplt['PRIMARYIPADDRESS'] + else + isHybrid = false + end + + vm_nics = [nic] + end + end + + if vm.has_elements?("/VM/TEMPLATE/NIC") || vm_nics puts CLIHelper.print_header(str_h1 % "VM NICS",false) - vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten + vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten if !vm_nics nic_default = {"NETWORK" => "-", "IP" => "-",