From 536d69b5ab017f2a04facc865d810b5c6561e485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 1 Dec 2011 07:50:37 -0800 Subject: [PATCH] Feature #602: Change onevnet show format to separate used, free and 'on hold' leases --- src/cli/one_helper/onevnet_helper.rb | 18 ++++++++++++------ src/oca/ruby/OpenNebula/XMLUtils.rb | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 71ead0d55f..3a59dac76a 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -73,13 +73,19 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts str % ["IP_END", vn['RANGE/IP_END']] end - leases_str = vn.template_like_str('/VNET/LEASES', false) + lease_types = [ ["LEASES ON HOLD", 'LEASE[USED=1 and VID=-1]'], + ["USED LEASES", 'LEASE[USED=1 and VID>-1]'], + ["FREE LEASES", 'LEASE[USED=0]'] ] - if !leases_str.empty? - puts - CLIHelper.print_header(str_h1 % ["LEASES INFORMATION"], false) - puts leases_str - end + lease_types.each { |pair| + leases_str = vn.template_like_str('/VNET/LEASES', false, pair[1]) + + if !leases_str.empty? + puts + CLIHelper.print_header(str_h1 % [pair[0]], false) + puts leases_str + end + } end def format_pool(options) diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 1dfa884532..3505fb9cc6 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -201,7 +201,7 @@ module OpenNebula template_like_str('TEMPLATE', indent) end - def template_like_str(root_element, indent=true) + def template_like_str(root_element, indent=true, xpath_exp=nil) if NOKOGIRI xml_template=@xml.xpath(root_element).to_s rexml=REXML::Document.new(xml_template).root @@ -217,7 +217,7 @@ module OpenNebula ind_tab=' ' end - str=rexml.collect {|n| + str=rexml.elements.collect(xpath_exp) {|n| if n.class==REXML::Element str_line="" if n.has_elements?