Module: ForemanChef::ChefProxyForm

Defined in:
app/helpers/foreman_chef/chef_proxy_form.rb

Instance Method Summary collapse

Instance Method Details

#chef_proxy_form(f) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 3

def chef_proxy_form(f)
  # Don't show this if we have no Chef proxies, otherwise always include blank
  # so the user can choose not to use puppet on this host
  proxies = SmartProxy.with_taxonomy_scope_override(@location,@organization).with_features('Chef')
  return if proxies.count == 0
  javascript('foreman_chef/chef_proxy_environment_refresh')

  chef_proxy_form_chef_proxy_select(f, proxies) +
    chef_proxy_form_chef_environment_select(f, f.object.available_chef_environments)
end

#chef_proxy_form_chef_environment_select(f, environments) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 14

def chef_proxy_form_chef_environment_select(f, environments)
  begin
    if f.object.is_a?(Host::Base) && f.object.persisted? && f.object.chef_environment_differs?
      help = (:span, ' ', :class => 'pficon pficon-warning-triangle-o') + ' ' + _('Chef environment is set to %s on Chef server, submitting will override it') % f.object.fresh_chef_environment
      help = help.html_safe
    else
      help = nil
    end
  rescue => e # chef server communication issue
    help = (:span, ' ', :class => 'pficon pficon-warning-triangle-o') + ' ' + _('Unable to communicate with Chef server - %s.') % e.message
    help = help.html_safe
  end

  select_f(f, :chef_environment_id, environments, :id, :name,
           {:include_blank => blank_or_inherit_f(f, :chef_environment_id)},
           {:label => _("Chef environment"), :help_inline => help })
end

#chef_proxy_form_chef_proxy_select(f, proxies) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 32

def chef_proxy_form_chef_proxy_select(f, proxies)
  select_f(f, :chef_proxy_id, proxies, :id, :name,
           { :include_blank => blank_or_inherit_f(f, :chef_proxy) },
           { :label => _("Chef proxy"),
             :help_inline => _("Use this foreman proxy as an entry point to your Chef, node will be managed via this proxy"),
             :data => { :url => environments_for_chef_proxy_foreman_chef_environments_path } })
end

#chef_run_list_differs?(host) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 64

def chef_run_list_differs?(host)
  host.persisted? && host.chef_proxy_id.present? && host.run_list_differs?
end

#chef_tab_content(f) ⇒ Object



60
61
62
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 60

def chef_tab_content(f)
  render 'foreman_chef/hosts/chef_tab', :f => f
end

#chef_tab_menu(host) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 40

def chef_tab_menu(host)
  if SmartProxy.with_features("Chef").count > 0
    warning = ''
    begin
      if chef_run_list_differs?(host)
        warning = chef_warning_icon
      end
    rescue => e
      warning = chef_warning_icon
    end
     :li do
      link_to(warning + _('Chef'), '#chef', :data => { :toggle => 'tab'})
    end
  end
end

#chef_warning_iconObject



56
57
58
# File 'app/helpers/foreman_chef/chef_proxy_form.rb', line 56

def chef_warning_icon
  (:span, ' '.html_safe, :class => "pficon pficon-warning-triangle-o")
end