From 3a7c5e46ea2b9d0b3cd3b398c12f831b1333ef1a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 24 Aug 2022 14:26:36 +0000 Subject: [PATCH 1/4] Refs #35438 - Enhance VMware listing commands and switch to cluster_name param --- lib/hammer_cli_foreman/compute_resource.rb | 64 +++++++++++++++++-- .../compute_resource/vmware.rb | 4 +- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/lib/hammer_cli_foreman/compute_resource.rb b/lib/hammer_cli_foreman/compute_resource.rb index e2f3ebc7a..9c3f2b867 100644 --- a/lib/hammer_cli_foreman/compute_resource.rb +++ b/lib/hammer_cli_foreman/compute_resource.rb @@ -121,6 +121,9 @@ class AvailableClustersCommand < HammerCLIForeman::ListCommand output do field :id, _('Id') field :name, _('Name') + field :datacenter, _('Datacenter') + field :num_host, _('Hosts') + field :full_path, _('Cluster path') end build_options @@ -130,12 +133,24 @@ class AvailableNetworksCommand < HammerCLIForeman::ListCommand action :available_networks command_name 'networks' + option '--cluster-name', "Name of cluster", _("Cluster name to search by"), + attribute_name: :option_cluster_id + output do field :id, _('Id'), Fields::Field, :max_width => 200, :hide_blank => true field :name, _('Name') + field :datacenter, _('Datacenter') + field :virtualswitch, _('Virtual switch') + field :vlanid, _('VLAN ID') end - build_options + def request_params + params = super + params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') + params + end + + build_options :without => :cluster_id end class AvailableVnicProfilesCommand < HammerCLIForeman::ListCommand @@ -158,6 +173,7 @@ class AvailableImagesCommand < HammerCLIForeman::ListCommand output do field :uuid, _('Uuid') field :name, _('Name') + field :path, _('Path'), Fields::Field, :hide_blank => true end build_options @@ -182,6 +198,10 @@ class AvailableFoldersCommand < HammerCLIForeman::ListCommand output do field :id, _('Id') field :name, _('Name') + field :parent, _('Parent') + field :datacenter, _('Datacenter') + field :path, _('Path'), Fields::Field, :max_width => 50 + field :type, _('Type') end build_options @@ -203,36 +223,66 @@ class AvailableResourcePoolsCommand < HammerCLIForeman::ListCommand action :available_resource_pools command_name 'resource-pools' + option '--cluster-name', "Name of cluster", _("Cluster name to search by"), + attribute_name: :option_cluster_id + output do field :id, _('Id') field :name, _('Name') + field :cluster, _('Cluster') + field :datacenter, _('Datacenter') end - build_options + def request_params + params = super + params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') + params + end + + build_options :without => :cluster_id end class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand action :available_storage_domains command_name 'storage-domains' + option '--cluster-name', "Name of cluster", _("Cluster name to search by"), + attribute_name: :option_cluster_id + output do field :id, _('Id') field :name, _('Name') end - build_options + def request_params + params = super + params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') + params + end + + build_options :without => :cluster_id end class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand action :available_storage_pods command_name 'storage-pods' + option '--cluster-name', "Name of cluster", _("Cluster name to search by"), + attribute_name: :option_cluster_id + output do field :id, _('Id') field :name, _('Name') + field :datacenter, _('Datacenter') end - build_options + def request_params + params = super + params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') + params + end + + build_options :without => :cluster_id end class AvailableSecurityGroupsCommand < HammerCLIForeman::ListCommand @@ -252,8 +302,10 @@ class AvailableVirtualMachinesCommand < HammerCLIForeman::ListCommand command_name 'virtual-machines' output do - field :id, _("Id") - field :name, _("Name") + field :id, _('Id') + field :name, _('Name') + field :path, _('Path'), Fields::Field, :max_width => 50 + field :state, _('State') end build_options diff --git a/lib/hammer_cli_foreman/compute_resource/vmware.rb b/lib/hammer_cli_foreman/compute_resource/vmware.rb index 5d9386a2e..76330ac5a 100644 --- a/lib/hammer_cli_foreman/compute_resource/vmware.rb +++ b/lib/hammer_cli_foreman/compute_resource/vmware.rb @@ -64,7 +64,9 @@ def interface_attributes def provider_specific_fields super + [ Fields::Field.new(:label => _('Datacenter'), :path => [:datacenter]), - Fields::Field.new(:label => _('Server'), :path => [:server]) + Fields::Field.new(:label => _('Server'), :path => [:server]), + Fields::Boolean.new(:label => _('Console password set'), :path => [:set_console_password]), + Fields::Boolean.new(:label => _('Caching enabled'), :path => [:caching_enabled]) ] end From 41dfc8c848822fce775f5e88f329611145af1b89 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 30 Aug 2022 16:47:00 +0000 Subject: [PATCH 2/4] Refs #35438 - Enhance VMware listing commands and switch to cluster_name param --- lib/hammer_cli_foreman/compute_resource.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/hammer_cli_foreman/compute_resource.rb b/lib/hammer_cli_foreman/compute_resource.rb index 9c3f2b867..b0a2719ff 100644 --- a/lib/hammer_cli_foreman/compute_resource.rb +++ b/lib/hammer_cli_foreman/compute_resource.rb @@ -136,6 +136,9 @@ class AvailableNetworksCommand < HammerCLIForeman::ListCommand option '--cluster-name', "Name of cluster", _("Cluster name to search by"), attribute_name: :option_cluster_id + option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") + + output do field :id, _('Id'), Fields::Field, :max_width => 200, :hide_blank => true field :name, _('Name') @@ -150,7 +153,7 @@ def request_params params end - build_options :without => :cluster_id + build_options end class AvailableVnicProfilesCommand < HammerCLIForeman::ListCommand @@ -226,6 +229,8 @@ class AvailableResourcePoolsCommand < HammerCLIForeman::ListCommand option '--cluster-name', "Name of cluster", _("Cluster name to search by"), attribute_name: :option_cluster_id + option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") + output do field :id, _('Id') field :name, _('Name') @@ -239,7 +244,7 @@ def request_params params end - build_options :without => :cluster_id + build_options end class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand @@ -249,6 +254,8 @@ class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand option '--cluster-name', "Name of cluster", _("Cluster name to search by"), attribute_name: :option_cluster_id + option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") + output do field :id, _('Id') field :name, _('Name') @@ -260,7 +267,7 @@ def request_params params end - build_options :without => :cluster_id + build_options end class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand @@ -270,6 +277,8 @@ class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand option '--cluster-name', "Name of cluster", _("Cluster name to search by"), attribute_name: :option_cluster_id + option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") + output do field :id, _('Id') field :name, _('Name') @@ -282,7 +291,7 @@ def request_params params end - build_options :without => :cluster_id + build_options end class AvailableSecurityGroupsCommand < HammerCLIForeman::ListCommand From 345738e38d63e6e14ca501f1855fd9317ba9538e Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 6 Sep 2022 16:00:40 +0000 Subject: [PATCH 3/4] Refs #35438 - Enhance VMware listing commands and switch to cluster_name param --- .../compute_resource_subcommand.rb | 14 ++++++++ lib/hammer_cli_foreman/compute_resource.rb | 33 +++++-------------- 2 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 lib/hammer_cli_foreman/command_extensions/compute_resource_subcommand.rb diff --git a/lib/hammer_cli_foreman/command_extensions/compute_resource_subcommand.rb b/lib/hammer_cli_foreman/command_extensions/compute_resource_subcommand.rb new file mode 100644 index 000000000..8728e1e8a --- /dev/null +++ b/lib/hammer_cli_foreman/command_extensions/compute_resource_subcommand.rb @@ -0,0 +1,14 @@ +module HammerCLIForeman + module CommandExtensions + class ComputeResourceSubcommand < HammerCLI::CommandExtensions + option '--cluster-id', 'ID', _('Cluster ID'), + deprecated: _('Use --cluster-name instead') + option '--cluster-name', 'NAME', _('Cluster name or path to search by'), + attribute_name: :option_cluster_id + + request_params do |params| + params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') if params['cluster_id'] + end + end + end +end diff --git a/lib/hammer_cli_foreman/compute_resource.rb b/lib/hammer_cli_foreman/compute_resource.rb index b0a2719ff..27c4a53d3 100644 --- a/lib/hammer_cli_foreman/compute_resource.rb +++ b/lib/hammer_cli_foreman/compute_resource.rb @@ -133,12 +133,6 @@ class AvailableNetworksCommand < HammerCLIForeman::ListCommand action :available_networks command_name 'networks' - option '--cluster-name', "Name of cluster", _("Cluster name to search by"), - attribute_name: :option_cluster_id - - option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") - - output do field :id, _('Id'), Fields::Field, :max_width => 200, :hide_blank => true field :name, _('Name') @@ -153,7 +147,8 @@ def request_params params end - build_options + build_options without: :cluster_id + extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end class AvailableVnicProfilesCommand < HammerCLIForeman::ListCommand @@ -226,11 +221,6 @@ class AvailableResourcePoolsCommand < HammerCLIForeman::ListCommand action :available_resource_pools command_name 'resource-pools' - option '--cluster-name', "Name of cluster", _("Cluster name to search by"), - attribute_name: :option_cluster_id - - option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") - output do field :id, _('Id') field :name, _('Name') @@ -244,18 +234,14 @@ def request_params params end - build_options + build_options without: :cluster_id + extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand action :available_storage_domains command_name 'storage-domains' - option '--cluster-name', "Name of cluster", _("Cluster name to search by"), - attribute_name: :option_cluster_id - - option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") - output do field :id, _('Id') field :name, _('Name') @@ -267,18 +253,14 @@ def request_params params end - build_options + build_options without: :cluster_id + extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand action :available_storage_pods command_name 'storage-pods' - option '--cluster-name', "Name of cluster", _("Cluster name to search by"), - attribute_name: :option_cluster_id - - option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") - output do field :id, _('Id') field :name, _('Name') @@ -291,7 +273,8 @@ def request_params params end - build_options + build_options without: :cluster_id + extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end class AvailableSecurityGroupsCommand < HammerCLIForeman::ListCommand From 22b01d1633cdcbdce744faf30ef349f5fa45914b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 7 Sep 2022 18:01:04 +0000 Subject: [PATCH 4/4] Refs #35438 - Enhance VMware listing commands and switch to cluster_name param --- lib/hammer_cli_foreman/command_extensions.rb | 1 + lib/hammer_cli_foreman/compute_resource.rb | 24 -------------------- test/functional/compute_resource_test.rb | 21 +++++++++++++++++ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/hammer_cli_foreman/command_extensions.rb b/lib/hammer_cli_foreman/command_extensions.rb index 9b06afef4..2b5ef36ea 100644 --- a/lib/hammer_cli_foreman/command_extensions.rb +++ b/lib/hammer_cli_foreman/command_extensions.rb @@ -7,3 +7,4 @@ require 'hammer_cli_foreman/command_extensions/user' require 'hammer_cli_foreman/command_extensions/subnet' require 'hammer_cli_foreman/command_extensions/domain' +require 'hammer_cli_foreman/command_extensions/compute_resource_subcommand' diff --git a/lib/hammer_cli_foreman/compute_resource.rb b/lib/hammer_cli_foreman/compute_resource.rb index 27c4a53d3..7a26a0193 100644 --- a/lib/hammer_cli_foreman/compute_resource.rb +++ b/lib/hammer_cli_foreman/compute_resource.rb @@ -141,12 +141,6 @@ class AvailableNetworksCommand < HammerCLIForeman::ListCommand field :vlanid, _('VLAN ID') end - def request_params - params = super - params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') - params - end - build_options without: :cluster_id extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end @@ -228,12 +222,6 @@ class AvailableResourcePoolsCommand < HammerCLIForeman::ListCommand field :datacenter, _('Datacenter') end - def request_params - params = super - params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') - params - end - build_options without: :cluster_id extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end @@ -247,12 +235,6 @@ class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand field :name, _('Name') end - def request_params - params = super - params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') - params - end - build_options without: :cluster_id extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end @@ -267,12 +249,6 @@ class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand field :datacenter, _('Datacenter') end - def request_params - params = super - params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') - params - end - build_options without: :cluster_id extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])) end diff --git a/test/functional/compute_resource_test.rb b/test/functional/compute_resource_test.rb index f53228613..c7b5992a4 100644 --- a/test/functional/compute_resource_test.rb +++ b/test/functional/compute_resource_test.rb @@ -355,10 +355,31 @@ ] ) expected_result = success_result(output) + expected_result.expected_err = "Warning: Option --cluster-id is deprecated. Use --cluster-name instead\n" result = run_cmd(cmd + params) assert_cmd(expected_result, result) end + + it 'lists available resource_pools for a compute resource with updated cluster_name param' do + api_expects(:compute_resources, :available_resource_pools, 'resource-pools').with_params( + 'id' => '1', 'cluster_id' => 'test%2Ftest1' + ).returns(index_response(resource_pools)) + + cluster_param = base_params + ['--cluster-name=test/test1'] + + output = IndexMatcher.new( + [ + %w[ID NAME], + %w[1 resource_pool1], + %w[2 resource_pool2] + ] + ) + expected_result = success_result(output) + + result = run_cmd(cmd + cluster_param) + assert_cmd(expected_result, result) + end end describe 'storage_domains' do