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
Conversation
@ofedoren can this get a review when you get a chance please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @chris1984! Just a few small nitpicks inline.
Also, I've read initial issue and it seems like in hammer we still have a problem with cluster_id
:
And yes, I was testing this on the latest Foreman's develop
so your changes are present.
@ofedoren updated. Changed ** Hammer commands with normal cluster structure, with new cluster_name attribute: *** Networks [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource networks --id 1 --cluster-name "Satellite-Engineering"
----------------|-------------------------------|----------------|------------------|--------
ID | NAME | DATACENTER | VIRTUAL SWITCH | VLAN ID
----------------|-------------------------------|----------------|------------------|--------
dvportgroup-572 | ABJ-Network | RH_Engineering | Satellite-Switch | 209
dvportgroup-56 | Host-Network | RH_Engineering | Satellite-Switch | 0
----------------|-------------------------------|----------------|------------------|-------- *** Resource pools [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource resource-pools --id 1 --cluster-name "Satellite-Engineering"
-----------|-----------|-----------------------|---------------
ID | NAME | CLUSTER | DATACENTER
-----------|-----------|-----------------------|---------------
resgroup-8 | Resources | Satellite-Engineering | RH_Engineering
-----------|-----------|-----------------------|--------------- *** Storage pods [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource storage-pods --id 1 --cluster-name "Satellite-Engineering"
------------|-------------|---------------
ID | NAME | DATACENTER
------------|-------------|---------------
group-p6123 | NFS-Cluster | RH_Engineering
------------|-------------|--------------- *** Storage Domains [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource storage-domains --id 1 --cluster-name "Satellite-Engineering"
----------------|----------------
ID | NAME
----------------|----------------
datastore-17566 | ISOS
datastore-34 | Local-ESXI23
datastore-3518 | Local-ESXi3
----------------|---------------- Hammer commands with nested cluster structure, with new cluster_name attribute: *** Networks [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource networks --id 2 --cluster-name "Test-Folder/Test-Cluster"
--------------|------------|-------------|----------------|--------
ID | NAME | DATACENTER | VIRTUAL SWITCH | VLAN ID
--------------|------------|-------------|----------------|--------
network-40902 | VM Network | Toledo-Test | |
--------------|------------|-------------|----------------|-------- *** Resource pools [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource resource-pools --id 2 --cluster-name "Test-Folder/Test-Cluster"
---------------|-----------|--------------------------|------------
ID | NAME | CLUSTER | DATACENTER
---------------|-----------|--------------------------|------------
resgroup-40407 | Resources | Test-Folder/Test-Cluster | Toledo-Test
---------------|-----------|--------------------------|------------ *** Storage pods [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource storage-pods --id 2 --cluster-name "Test-Folder/Test-Cluster"
---|------|-----------
ID | NAME | DATACENTER
---|------|-----------
*** Storage Domains [vagrant@centos7-hammer-devel hammer-cli-foreman]$ hammer compute-resource storage-domains --id 2 --cluster-name "Test-Folder/Test-Cluster"
----------------|-----------
ID | NAME
----------------|-----------
datastore-40901 | datastore1
----------------|----------- |
If this looks good to you I will update the tests that failed |
Although I'm OK with renaming the option, we would need to deprecate it first instead of removal. |
@ofedoren how does this look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @chris1984! It works now. Some code-related suggestions which also should fix almost all of the tests.
And can we have at least one more test to cover this specific case?
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option '--cluster-name', "Name of cluster", _("Cluster name to search by"), | ||
attribute_name: :option_cluster_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option '--cluster-name', "Name of cluster", _("Cluster name to search by"), | |
attribute_name: :option_cluster_id | |
option '--cluster-name', 'NAME', _('Cluster name to search by'), | |
attribute_name: :option_cluster_id |
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name") | |
option '--cluster-id', 'ID', _(Cluster ID'), | |
deprecated: _('Use --cluster-name instead') |
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those changes are quite repetitive. Let's extract them into a command extension:
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
And then we can update the related commands like:
build_options without: :cluster_id
extend_with(
HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params])
)
@ofedoren I updated with your suggestions. When trying to run the test suite locally I get: /home/vagrant/hammer-cli-foreman/lib/hammer_cli_foreman/compute_resource.rb:153:in `<class:AvailableNetworksCommand>': uninitialized constant HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand (NameError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @chris1984, you need to also register the extension in https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/command_extensions.rb
def request_params | ||
params = super | ||
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') | ||
params | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed since it's present in the extension.
def request_params | ||
params = super | ||
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') | ||
params | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
def request_params | ||
params = super | ||
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') | ||
params | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
def request_params | ||
params = super | ||
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F') | ||
params | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@ofedoren how does this look? I kept it in a separate commit so you can review it easier. If it all looks good I can squash it or I think you can squash them all too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @chris1984, here is 🍪 for you :)
Requires theforeman/foreman#9383