From 97515e6da30b39ff4248beb57fc3486f3854083a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 11 Mar 2015 18:14:59 +0100 Subject: [PATCH] Feature #3518: Add IP column to onevm list --- src/cli/etc/onevm.yaml | 5 +++ src/cli/one_helper/onevm_helper.rb | 43 ++++++++++++++++++++++ src/oca/ruby/opennebula/virtual_machine.rb | 7 ++++ 3 files changed, 55 insertions(+) diff --git a/src/cli/etc/onevm.yaml b/src/cli/etc/onevm.yaml index 348a1696d3..c84f4db58e 100644 --- a/src/cli/etc/onevm.yaml +++ b/src/cli/etc/onevm.yaml @@ -44,6 +44,11 @@ :desc: Time since the VM was submitted :size: 10 +:IP: + :desc: VM IP addresses + :left: true + :size: 15 + :default: - :ID - :USER diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index a4be380b07..a28a8478da 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -123,6 +123,45 @@ class OneVMHelper < OpenNebulaHelper::OneHelper return short_state_str end + # Return the IP or several IPs of a VM + def self.ip_str(vm) + ips = [] + + vm_nics = [] + + if !vm["TEMPLATE"]["NIC"].nil? + vm_nics = [vm["TEMPLATE"]['NIC']].flatten + end + + vm_nics.each do |nic| + if nic.has_key?("IP") + ips.push(nic["IP"]) + end + + if nic.has_key?("IP6_GLOBAL") + ips.push(nic["IP6_GLOBAL"]) + end + + if nic.has_key?("IP6_ULA") + ips.push(nic["IP6_ULA"]) + end + end + + VirtualMachine::EXTERNAL_IP_ATTRS.each do |attr| + external_ip = vm["TEMPLATE"][attr] + + if !external_ip.nil? && !ips.include?(external_ip) + ips.push(external_ip) + end + end + + if ips.empty? + return "--" + else + return ips.join(",") + end + end + def format_pool(options) config_file = self.class.table_conf @@ -208,6 +247,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.period_to_str(dtime, false) end + column :IP, "VM IP addresses", :left, :donottruncate, :size=>15 do |d| + OneVMHelper.ip_str(d) + end + default :ID, :USER, :GROUP, :NAME, :STAT, :UCPU, :UMEM, :HOST, :TIME end diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index ccf22e59b1..80d5584ba2 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -118,6 +118,13 @@ module OpenNebula delete-recreate reboot reboot-hard resched unresched poweroff poweroff-hard} + EXTERNAL_IP_ATTRS = [ + 'GUEST_IP', + 'AWS_IP_ADDRESS', + 'AZ_IPADDRESS', + 'SL_PRIMARYIPADDRESS' + ] + # Creates a VirtualMachine description with just its identifier # this method should be used to create plain VirtualMachine objects. # +id+ the id of the vm