diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 003f4bd515c..4983cf90f70 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -192,6 +192,29 @@ def show_ar(vn, ar_id) puts template end + def check_orphans + orphans = [] + xpath = '/VMTEMPLATE_POOL/VMTEMPLATE/TEMPLATE/NIC' + + pool = factory_pool + tmpl_pool = OpenNebula::TemplatePool.new(@client, -2) + + pool.info + tmpl_pool.info + + pool.each do |img| + attrs = { :id => img['ID'], + :name => img['NAME'], + :uname => img['UNAME'] } + + orphans << img['ID'] if check_orphan(tmpl_pool, + xpath, + 'NETWORK', attrs) + end + + orphans + end + private def factory(id=nil) diff --git a/src/cli/onevnet b/src/cli/onevnet index 3694ec64b30..1611b75c59e 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -429,4 +429,14 @@ CommandParser::CmdParser.new(ARGV) do vnet.unlock end end + + show_desc = <<-EOT.unindent + Shows orphans vnets (i.e vnets not referenced in any template). + EOT + + command :orphans, show_desc do + puts helper.check_orphans + + return 0 + end end