Module: HostsAndHostgroupsHelper

Included in:
HostgroupsHelper, HostsHelper
Defined in:
app/helpers/hosts_and_hostgroups_helper.rb

Instance Method Summary collapse

Instance Method Details

#accessible_domainsObject


31
32
33
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 31

def accessible_domains
  (User.current.domains.any? and !User.current.admin?) ? User.current.domains : Domain.all
end

#accessible_hostgroupsObject


20
21
22
23
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 20

def accessible_hostgroups
  hg = (User.current.hostgroups.any? and !User.current.admin?) ? User.current.hostgroups : Hostgroup.all
  hg.sort{ |l, r| l.to_label <=> r.to_label }
end

#arch_ossObject


40
41
42
43
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 40

def arch_oss
  return [] if @architecture.blank?
  @architecture.operatingsystems
end

#domain_subnetsObject


35
36
37
38
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 35

def domain_subnets
  return [] if @domain.blank?
  @domain.subnets
end

#hostgroup_name(hostgroup, max_length = 1000) ⇒ Object


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

def hostgroup_name(hostgroup, max_length = 1000)
  return if hostgroup.blank?
  options = (hostgroup.label.to_s.size > max_length) ? {:'data-original-title'=> hostgroup.label, :rel=>'twipsy'} : {}
  nesting = hostgroup.label.to_s.gsub(/[^\/]+\/?$/, "")
  nesting = truncate(nesting, :length => max_length - hostgroup.name.to_s.size) if nesting.to_s.size > 0
  name =  truncate(hostgroup.name, :length => max_length - nesting.to_s.size)
  link_to_if_authorized(
      (:span,
          (:span, nesting, :class => "gray") + name, options),
      hash_for_edit_hostgroup_path(:id => hostgroup))
end

#ifs_bmc_opts(obj) ⇒ Object


90
91
92
93
94
95
96
97
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 90

def ifs_bmc_opts obj
  case obj.read_attribute(:type)
    when "Nic::BMC"
      {}
    else
      { :disabled => true, :value => nil }
  end
end

#interesting_klasses(obj) ⇒ Object


81
82
83
84
85
86
87
88
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 81

def interesting_klasses obj
  classes    = obj.all_puppetclasses
  smart_vars = LookupKey.reorder('').where(:puppetclass_id => classes.map(&:id)).group(:puppetclass_id).count
  class_vars = LookupKey.reorder('').joins(:environment_classes).where(:environment_classes => { :puppetclass_id => classes.map(&:id) }).group('environment_classes.puppetclass_id').count
  klasses    = smart_vars.keys + class_vars.keys

  classes.select { |pc| klasses.include?(pc.id) }
end

#model_name(host) ⇒ Object


14
15
16
17
18
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 14

def model_name host
  name = host.try(:model)
  name = host.compute_resource.name if host.compute_resource
  trunc(name, 14)
end

#os_mediaObject


45
46
47
48
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 45

def os_media
  return [] if @operatingsystem.blank?
  @operatingsystem.media
end

#os_ptableObject


50
51
52
53
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 50

def os_ptable
  return [] if @operatingsystem.blank?
  @operatingsystem.ptables
end

#parent_classes(obj) ⇒ Object


25
26
27
28
29
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 25

def parent_classes obj
  return obj.hostgroup.classes if obj.kind_of?(Host::Base) and obj.hostgroup
  return obj.is_root? ? [] : obj.parent.classes if obj.is_a?(Hostgroup)
  []
end

#puppet_ca(f) ⇒ Object


59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 59

def puppet_ca f
  # Don't show this if we have no CA proxies, otherwise always include blank
  # so the user can choose not to sign the puppet cert on this host
  proxies = SmartProxy.puppetca_proxies
  return if proxies.count == 0
  select_f f, :puppet_ca_proxy_id, proxies, :id, :name,
           { :include_blank => true },
           { :label       => _("Puppet CA"),
             :help_inline => _("Use this puppet server as a CA server") }
end

#puppet_master(f) ⇒ Object


70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 70

def puppet_master f
  # Don't show this if we have no Puppet proxies, otherwise always include blank
  # so the user can choose not to use puppet on this host
  proxies = SmartProxy.puppet_proxies
  return if proxies.count == 0
  select_f f, :puppet_proxy_id, proxies, :id, :name,
           { :include_blank => true },
           { :label       => _("Puppet Master"),
             :help_inline => _("Use this puppet server as an initial Puppet Server or to execute puppet runs") }
end

#puppet_master_fields(f) ⇒ Object


55
56
57
# File 'app/helpers/hosts_and_hostgroups_helper.rb', line 55

def puppet_master_fields f
  "#{puppet_ca(f)} #{puppet_master(f)}".html_safe
end