Skip to content

Draft: Add Puppet proxy (CA) bulk actions#429

Open
nadjaheitmann wants to merge 1 commit intomasterfrom
new_all_hosts_page_puppet_proxy_actions
Open

Draft: Add Puppet proxy (CA) bulk actions#429
nadjaheitmann wants to merge 1 commit intomasterfrom
new_all_hosts_page_puppet_proxy_actions

Conversation

@nadjaheitmann
Copy link
Collaborator

@nadjaheitmann nadjaheitmann commented Sep 24, 2025

@adamruzicka @jeremylenz I have created a draft for the Puppet Proxy update bulk action. It is not more than a draft and I know there is a bunch of things missing (e.g. clearing proxy, CA proxy, tests, ...). I basically took code from Foreman and Katello and mixed it into this. Do you mind checking whether the general approach is the direction we want to go. UI wise, I think this is straight forward, but I was not sure whether

  • extending the BulkHostManager
  • adding a new API endpoint to the HostsBulkActionsController
  • adding the API endpoint itself to the Foreman rather than the foreman_puppet namespace

is the way to go.

I appreciate your opinions.

Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

Left some notes inline, can't speak much to the frontend

extend ActiveSupport::Concern

included do
before_action :find_editable_hosts, :only => [:change_puppet_proxy]
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this override the before action from the base class in https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/hosts_bulk_actions_controller.rb#L8 ?

In this case I'd prefer katello's approach - have a brand new controller rather than trying to extend the existing one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it does. Is there a way not to overwrite it? If not, it has to be a new controller, indeed.

Copy link
Contributor

Choose a reason for hiding this comment

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

From the top of my head I can't suggest any clean way that would make it behave the way we need. Hacks could be done, sure, with the cleanest one probably being just calling it directly in #change_puppet_proxy without relying on controller callbacks.


api :PUT, "/hosts/bulk/change_puppet_proxy", N_("Change Puppet Proxy")
param_group :bulk_host_ids
param :proxy_id, :number, :required => true, :desc => N_("ID of the Puppet proxy to reassign the hosts to")
Copy link
Contributor

Choose a reason for hiding this comment

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

This being required means it can be used to reassign the host to a different proxy, but this cannot be used to unassign it, correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. I have not yet implemented the unassign method, so the implementation details about that one are still open.

Comment on lines 11 to 15
host.puppet_ca_proxy = proxy
else
host.puppet_proxy = proxy
end
host.save(:validate => false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need callbacks to be run or could we take a shortcut and assign the proxy with a single update query?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure, if we need callbacks to be honest. The original action does run some validations about validating the proxy I think: https://github.com/theforeman/foreman_puppet/blob/master/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb#L143

Can the update command also take the validate => false parameter?

Comment on lines 16 to 22
rescue StandardError => e
message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type)
Foreman::Logging.exception(message, e)
end
rescue RecordNotFoundError => e
Foreman::Logging.exception(_('Cound not find Smart Proxy'))
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rescue StandardError => e
message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type)
Foreman::Logging.exception(message, e)
end
rescue RecordNotFoundError => e
Foreman::Logging.exception(_('Cound not find Smart Proxy'))
end
rescue StandardError => e
message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type)
Foreman::Logging.exception(message, e)
end
rescue ActiveRecord::RecordNotFound => e
Foreman::Logging.exception(_('Cound not find Smart Proxy'))
end

And even then, ActiveRecord::RecordNotFound is a subclass of StandardError so the record not found branch would never match

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that one is messy - this also somehow depends if we want a separate method for unassign.

extend ActiveSupport::Concern

def change_puppet_proxy(proxy_id, ca_proxy)
proxy = SmartProxy.find_by(id: proxy_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

This just returns nil if no proxy was found. Is that expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I would solve that depending on how I implement the unassign method. The PR is still very drafty.

@nadjaheitmann nadjaheitmann force-pushed the new_all_hosts_page_puppet_proxy_actions branch from e2b1c7f to c7dd83c Compare September 24, 2025 12:15
Copy link
Collaborator Author

@nadjaheitmann nadjaheitmann left a comment

Choose a reason for hiding this comment

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

Thanks @adamruzicka !

extend ActiveSupport::Concern

included do
before_action :find_editable_hosts, :only => [:change_puppet_proxy]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it does. Is there a way not to overwrite it? If not, it has to be a new controller, indeed.


api :PUT, "/hosts/bulk/change_puppet_proxy", N_("Change Puppet Proxy")
param_group :bulk_host_ids
param :proxy_id, :number, :required => true, :desc => N_("ID of the Puppet proxy to reassign the hosts to")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. I have not yet implemented the unassign method, so the implementation details about that one are still open.

extend ActiveSupport::Concern

def change_puppet_proxy(proxy_id, ca_proxy)
proxy = SmartProxy.find_by(id: proxy_id)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I would solve that depending on how I implement the unassign method. The PR is still very drafty.

Comment on lines 11 to 15
host.puppet_ca_proxy = proxy
else
host.puppet_proxy = proxy
end
host.save(:validate => false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure, if we need callbacks to be honest. The original action does run some validations about validating the proxy I think: https://github.com/theforeman/foreman_puppet/blob/master/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb#L143

Can the update command also take the validate => false parameter?

Comment on lines 16 to 22
rescue StandardError => e
message = format(_('Failed to set %{proxy_type} proxy for %{host}.'), host: host, proxy_type: proxy_type)
Foreman::Logging.exception(message, e)
end
rescue RecordNotFoundError => e
Foreman::Logging.exception(_('Cound not find Smart Proxy'))
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that one is messy - this also somehow depends if we want a separate method for unassign.

@nadjaheitmann nadjaheitmann force-pushed the new_all_hosts_page_puppet_proxy_actions branch 2 times, most recently from ac62ab7 to e980546 Compare September 24, 2025 12:48
@nadjaheitmann nadjaheitmann force-pushed the new_all_hosts_page_puppet_proxy_actions branch 3 times, most recently from 11c8919 to 4512e86 Compare October 13, 2025 07:52
@nadjaheitmann nadjaheitmann force-pushed the new_all_hosts_page_puppet_proxy_actions branch from 4512e86 to 2eb2f1a Compare January 21, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants