From 1bb41465923063dec8e45fa8186adce7d04c8433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez?= Date: Tue, 1 Oct 2019 15:34:49 +0200 Subject: [PATCH] F #3629: Add onevnet orphans (#3794) --- src/cli/one_helper/onevnet_helper.rb | 23 +++++++++++++++++++++++ src/cli/onevnet | 10 ++++++++++ 2 files changed, 33 insertions(+) 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