Module: ForemanChef::Concerns::HostExtensions
- Defined in:
- app/models/foreman_chef/concerns/host_extensions.rb
Constant Summary collapse
- DEFAULT =
['role[default]']
Class Method Summary collapse
Instance Method Summary collapse
- #action_input_key ⇒ Object
- #chef_environment_differs? ⇒ Boolean
- #differs? ⇒ Boolean
- #fresh_chef_environment ⇒ Object
- #fresh_run_list ⇒ Object
- #fresh_run_list_data ⇒ Object
- #inherited_attributes ⇒ Object
-
#refresh_run_list! ⇒ Object
although it does not save anything, it changes existing run list object attributes or builds new one.
- #run_list ⇒ Object
- #run_list=(run_list) ⇒ Object
- #run_list_differs? ⇒ Boolean
Class Method Details
.prepended(base) ⇒ Object
6 7 8 9 10 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 6 def self.prepended(base) # even with autosave, save is called only if there's some change in attributes base.has_one :cached_run_list, :autosave => true, :class_name => 'ForemanChef::CachedRunList', :foreign_key => :host_id base.send :attr_accessor, :override_chef_attributes end |
Instance Method Details
#action_input_key ⇒ Object
66 67 68 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 66 def action_input_key "host" end |
#chef_environment_differs? ⇒ Boolean
46 47 48 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 46 def chef_environment_differs? self.chef_environment.try(:name) != fresh_chef_environment end |
#differs? ⇒ Boolean
58 59 60 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 58 def differs? run_list_differs? || chef_environment_differs? end |
#fresh_chef_environment ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 50 def fresh_chef_environment if (data = load_node_data) data['chef_environment'] else nil end end |
#fresh_run_list ⇒ Object
33 34 35 36 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 33 def fresh_run_list data = fresh_run_list_data @fresh_run_list ||= ForemanChef::CachedRunList.parse(data) unless data.nil? end |
#fresh_run_list_data ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 38 def fresh_run_list_data if (data = load_node_data) data['run_list'] else nil end end |
#inherited_attributes ⇒ Object
62 63 64 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 62 def inherited_attributes super.concat(%w(chef_proxy_id chef_environment_id)) end |
#refresh_run_list! ⇒ Object
although it does not save anything, it changes existing run list object attributes or builds new one
24 25 26 27 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 24 def refresh_run_list! data = fresh_run_list_data ForemanChef::CachedRunList.parse(data, self.cached_run_list || self.build_cached_run_list) unless data.nil? end |
#run_list ⇒ Object
12 13 14 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 12 def run_list self.cached_run_list || ForemanChef::CachedRunList.parse(DEFAULT, self.build_cached_run_list) end |
#run_list=(run_list) ⇒ Object
16 17 18 19 20 21 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 16 def run_list=(run_list) # returns CachedRunList instance, if there was one for host, return that one with modified attributes @run_list = ForemanChef::CachedRunList.parse(run_list, self.cached_run_list) # this ensures that host#save will save the cached run list too self.cached_run_list = @run_list end |
#run_list_differs? ⇒ Boolean
29 30 31 |
# File 'app/models/foreman_chef/concerns/host_extensions.rb', line 29 def run_list_differs? self.run_list.try(:list) != fresh_run_list.try(:list) end |