Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #35438 - Enhance VMware listing commands and switch to cluster_name param #604

Merged
merged 4 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/hammer_cli_foreman/command_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
@@ -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
32 changes: 26 additions & 6 deletions lib/hammer_cli_foreman/compute_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -133,9 +136,13 @@ class AvailableNetworksCommand < HammerCLIForeman::ListCommand
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
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end

class AvailableVnicProfilesCommand < HammerCLIForeman::ListCommand
Expand All @@ -158,6 +165,7 @@ class AvailableImagesCommand < HammerCLIForeman::ListCommand
output do
field :uuid, _('Uuid')
field :name, _('Name')
field :path, _('Path'), Fields::Field, :hide_blank => true
end

build_options
Expand All @@ -182,6 +190,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
Expand All @@ -206,9 +218,12 @@ class AvailableResourcePoolsCommand < HammerCLIForeman::ListCommand
output do
field :id, _('Id')
field :name, _('Name')
field :cluster, _('Cluster')
field :datacenter, _('Datacenter')
end

build_options
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end

class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand
Expand All @@ -220,7 +235,8 @@ class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand
field :name, _('Name')
end

build_options
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end

class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand
Expand All @@ -230,9 +246,11 @@ class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand
output do
field :id, _('Id')
field :name, _('Name')
field :datacenter, _('Datacenter')
end

build_options
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end

class AvailableSecurityGroupsCommand < HammerCLIForeman::ListCommand
Expand All @@ -252,8 +270,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
Expand Down
4 changes: 3 additions & 1 deletion lib/hammer_cli_foreman/compute_resource/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions test/functional/compute_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down