From f13f51a62e9186a5b79684a129fb76b439e81ff4 Mon Sep 17 00:00:00 2001 From: Angel Luis Moya Gonzalez Date: Thu, 31 Oct 2019 17:38:04 +0100 Subject: [PATCH] B #3839: onevcenter list_all and sunstone filter (#3894) * Add onevcenter list_all command * Add a parameter as opts called filter * Sunstone will not show uplinks nor unmanaged networks. --- src/cli/onevcenter | 31 +++++++++++++++++++ src/sunstone/routes/vcenter.rb | 4 +-- .../remotes/lib/vcenter_driver/datacenter.rb | 17 ++++++---- .../remotes/lib/vcenter_driver/network.rb | 2 +- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/cli/onevcenter b/src/cli/onevcenter index 5e36988f6f..25ba8e46cc 100755 --- a/src/cli/onevcenter +++ b/src/cli/onevcenter @@ -152,6 +152,7 @@ CommandParser::CmdParser.new(ARGV) do :options => [OBJECT, HOST, DATASTORE, VCENTER, USER, PASS] do begin args = helper.parse_opts(options) + args[:filter] = true vi_client = VCenterDriver::VIClient.new_from_host(options[:host]) importer = VCenterDriver::VcImporter .new_child(helper.client, vi_client, options[:object]) @@ -166,6 +167,36 @@ CommandParser::CmdParser.new(ARGV) do exit 0 end + list_desc = <<-EOT.unindent + Show a list with unimported vCenter objects excluding all filters + + Examples: + - listing networks including uplinks: + + onevcenter list_all -o networks -h + + EOT + + command :list_all, + list_desc, + :options => [OBJECT, HOST, DATASTORE, VCENTER, USER, PASS] do + begin + args = helper.parse_opts(options) + args[:filter] = false + vi_client = VCenterDriver::VIClient.new_from_host(options[:host]) + importer = VCenterDriver::VcImporter + .new_child(helper.client, vi_client, options[:object]) + + list = importer.retrieve_resources(args) + + helper.list_object(options, list) + rescue StandardError => e + puts e.message + end + + exit 0 + end + import_desc = <<-EOT.unindent Import the the desired vCenter object diff --git a/src/sunstone/routes/vcenter.rb b/src/sunstone/routes/vcenter.rb index 998ed6d2f3..9ca43b208f 100644 --- a/src/sunstone/routes/vcenter.rb +++ b/src/sunstone/routes/vcenter.rb @@ -186,8 +186,8 @@ end get '/vcenter/networks' do begin new_vcenter_importer("networks") - - [200, $importer.retrieve_resources.to_json] + opts = {:filter => true} + [200, $importer.retrieve_resources(opts).to_json] rescue Exception => e logger.error("[vCenter] " + e.message) error = Error.new(e.message) diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb b/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb index 790c8fc3e6..987f8191ca 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb @@ -331,7 +331,7 @@ class DatacenterFolder { vcenter_instance_name => template_objects } end - def get_unimported_networks(npool,vcenter_instance_name, hpool) + def get_unimported_networks(npool,vcenter_instance_name, hpool, args) vcenter_uuid = get_vcenter_instance_uuid pc = @vi_client.vim.serviceContent.propertyCollector @@ -373,11 +373,16 @@ class DatacenterFolder next if exist - # Exclude networks without hosts - next if r.obj['host'].empty? - # Exclude uplinks - unless r.obj['tag'].empty? - next if r.obj['tag'][0][:key] == 'SYSTEM/DVS.UPLINKPG' + if args[:filter] + # Exclude networks without hosts + next if r.obj['host'].empty? + + # Exclude DVS uplinks + unless r.obj['tag'].empty? + next if r.obj['tag'][0][:key] == 'SYSTEM/DVS.UPLINKPG' + end + # Exclude NSX uplinks + next if r.obj['name'].match(/^vxw-vmknicPg-dvs-(.*)/) end networks[r.obj._ref] = r.to_hash if r.obj.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) || r.obj.is_a?(RbVmomi::VIM::Network) || r.obj.is_a?(RbVmomi::VIM::OpaqueNetwork) diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/network.rb b/src/vmm_mad/remotes/lib/vcenter_driver/network.rb index facb3cd4d6..1a15bdc7c8 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/network.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/network.rb @@ -367,7 +367,7 @@ class NetImporter < VCenterDriver::VcImporter raise "Could not get OpenNebula HostPool: #{hpool.message}" end - rs = dc_folder.get_unimported_networks(npool, @vi_client.vc_name,hpool) + rs = dc_folder.get_unimported_networks(npool, @vi_client.vc_name,hpool, args) @list = rs end