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

Conversation

chris1984
Copy link
Member

@chris1984
Copy link
Member Author

@ofedoren can this get a review when you get a chance please?

Copy link
Member

@ofedoren ofedoren left a 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:
ScreenShot-1661786066286
ScreenShot-1661786112506
ScreenShot-1661786140333
ScreenShot-1661786161323

And yes, I was testing this on the latest Foreman's develop so your changes are present.

lib/hammer_cli_foreman/compute_resource.rb Outdated Show resolved Hide resolved
lib/hammer_cli_foreman/compute_resource.rb Outdated Show resolved Hide resolved
lib/hammer_cli_foreman/compute_resource.rb Outdated Show resolved Hide resolved
lib/hammer_cli_foreman/compute_resource/vmware.rb Outdated Show resolved Hide resolved
@chris1984 chris1984 changed the title Refs #35438 - Enhance VMware listing commands to include more info Refs #35438 - Enhance VMware listing commands and switch to cluster_name param Aug 30, 2022
@chris1984
Copy link
Member Author

chris1984 commented Aug 30, 2022

@ofedoren updated.

Changed cluster_id to cluster_name in the help text, but having that be used as the cluster_id since looking into the fog-vsphere code we don't use the raw id for anything. I didn't want to take away the ability to see id's. so to prevent confusion and users using the ID instead of the name, I changed the attribute to name but behind the scenes we use that as the ID to they pass in the name. Also did the gsub things we talked about so a user does not have to do %2F

** 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
----------------|-----------

@chris1984
Copy link
Member Author

If this looks good to you I will update the tests that failed

@ofedoren
Copy link
Member

Although I'm OK with renaming the option, we would need to deprecate it first instead of removal.

@chris1984
Copy link
Member Author

@ofedoren how does this look?

Copy link
Member

@ofedoren ofedoren left a 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?

Comment on lines 140 to 141


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 136 to 137
option '--cluster-name', "Name of cluster", _("Cluster name to search by"),
attribute_name: :option_cluster_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
option '--cluster-id', "ID of cluster", _("Deprecated, use cluster-name")
option '--cluster-id', 'ID', _(Cluster ID'),
deprecated: _('Use --cluster-name instead')

Comment on lines 277 to 280
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")
Copy link
Member

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])
)

@chris1984
Copy link
Member Author

@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)

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 144 to 148
def request_params
params = super
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F')
params
end
Copy link
Member

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.

Comment on lines 231 to 235
def request_params
params = super
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F')
params
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines 250 to 254
def request_params
params = super
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F')
params
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines 270 to 274
def request_params
params = super
params['cluster_id'] = params['cluster_id'].gsub('/', '%2F')
params
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@chris1984
Copy link
Member Author

@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.

Copy link
Member

@ofedoren ofedoren left a 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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants