Module: ForemanSalt::Concerns::HostManagedExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/foreman_salt/concerns/host_managed_extensions.rb
Instance Method Summary collapse
- #configuration_with_salt? ⇒ Boolean
- #params_with_salt_proxy ⇒ Object
- #salt_master ⇒ Object
- #salt_modules_for_enc ⇒ Object
- #salt_modules_in_host_environment ⇒ Object
- #saltrun! ⇒ Object
- #set_hostgroup_defaults_with_salt_proxy ⇒ Object
- #smart_proxy_ids_with_salt_proxy ⇒ Object
Instance Method Details
#configuration_with_salt? ⇒ Boolean
32 33 34 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 32 def configuration_with_salt? configuration_without_salt? || !!salt_proxy end |
#params_with_salt_proxy ⇒ Object
36 37 38 39 40 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 36 def params_with_salt_proxy params = params_without_salt_proxy params['salt_master'] = salt_master unless salt_master.blank? params end |
#salt_master ⇒ Object
48 49 50 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 48 def salt_master salt_proxy.to_s end |
#salt_modules_for_enc ⇒ Object
42 43 44 45 46 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 42 def salt_modules_for_enc return [] unless salt_environment modules = salt_modules + (hostgroup ? hostgroup.all_salt_modules : []) ForemanSalt::SaltModule.in_environment(salt_environment).where(:id => modules).pluck("salt_modules.name").uniq end |
#salt_modules_in_host_environment ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 78 def salt_modules_in_host_environment return unless self.salt_modules.any? if self.salt_environment errors.add(:base, _('Salt states must be in the environment of the host')) unless (self.salt_modules - self.salt_environment.salt_modules).empty? else errors.add(:base, _('Host must have an environment in order to set salt states')) end end |
#saltrun! ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 52 def saltrun! unless salt_proxy.present? errors.add(:base, _("No Salt master defined - can't continue")) logger.warn 'Unable to execute salt run, no salt proxies defined' return false end ProxyAPI::Salt.new(:url => salt_proxy.url).highstate name rescue => e errors.add(:base, _('Failed to execute state.highstate: %s') % e) false end |
#set_hostgroup_defaults_with_salt_proxy ⇒ Object
64 65 66 67 68 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 64 def set_hostgroup_defaults_with_salt_proxy return unless hostgroup assign_hostgroup_attributes(%w(salt_proxy_id salt_environment_id)) set_hostgroup_defaults_without_salt_proxy end |
#smart_proxy_ids_with_salt_proxy ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/models/foreman_salt/concerns/host_managed_extensions.rb', line 70 def smart_proxy_ids_with_salt_proxy ids = smart_proxy_ids_without_salt_proxy [salt_proxy, hostgroup.try(:salt_proxy)].compact.each do |proxy| ids << proxy.id end ids end |