Project

General

Profile

Download (3.34 KB) Statistics
| Branch: | Tag: | Revision:
36f93e4d Ohad Levy
module HostsAndHostgroupsHelper
8053eafd Amos Benari
def hostgroup_name group, max_length = 1000
4d4b84f6 Ohad Levy
return if group.blank?
8053eafd Amos Benari
options = (group.to_s.size > max_length) ? {:'data-original-title'=> group.to_s, :rel=>'twipsy'} : {}
6e92e9a5 Sam Kottler
nesting = group.to_s.gsub(/[^\/]+\/?$/, "")
aeab6f88 Amos Benari
nesting = truncate(nesting, :length => max_length - group.name.size) if nesting.size > 0
name = truncate(group.name.to_s, :length => max_length - nesting.size)
8053eafd Amos Benari
link_to_if_authorized(
content_tag(:span,
aeab6f88 Amos Benari
content_tag(:span, nesting, :class => "gray") + name, options),
8053eafd Amos Benari
hash_for_edit_hostgroup_path(:id => group))
4d4b84f6 Ohad Levy
end

c8d89c66 Amos Benari
def model_name host
name = host.try(:model)
name = host.compute_resource.name if host.compute_resource
8ec37cce Ohad Levy
trunc(name, 14)
c8d89c66 Amos Benari
end

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

487b7791 Ohad Levy
def parent_classes obj
return obj.hostgroup.classes if obj.is_a?(Host) and obj.hostgroup
return obj.is_root? ? [] : obj.parent.classes if obj.is_a?(Hostgroup)
[]
end

d5707b63 Ohad Levy
def select_hypervisor item
options_for_select Hypervisor.all.map{|h| [h.name, h.id]}, item.try(:hypervisor_id).try(:to_i)
end

05ab4c16 Ohad Levy
def select_memory item = nil
memory = item.try(:memory) if item
memory ||= @guest.memory if @guest
d5707b63 Ohad Levy
options_for_select Hypervisor::MEMORY_SIZE.map {|mem| [number_to_human_size(mem*1024), mem]}, memory.to_i
end

05ab4c16 Ohad Levy
def volume_size item
return item.disk_size if item.try(:disk_size)
return @guest.volume.size if @guest
end

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

05ab4c16 Ohad Levy
def domain_subnets
return [] if @domain.blank?
@domain.subnets
end

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

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

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

ace6fbad Ohad Levy
def puppet_master_fields f
ca = SmartProxy.joins(:features).where(:features => { :name => "Puppet CA" })
proxies = SmartProxy.joins(:features).where(:features => { :name => "Puppet" })
# do not show the ca proxy, if we have only one of those and its the same as the puppet proxy
fields = puppet_ca(f) unless ca.count == 1 and ca.map(&:id) == proxies.map(&:id)
"#{fields} #{puppet_master(f)}".html_safe
end

def puppet_ca f
936ba86f Ohad Levy
# if we are not using provisioning, not much point in presenting the CA option (assuming your CA is already set otherwise)
return unless SETTINGS[:unattended]
ace6fbad Ohad Levy
proxies = SmartProxy.joins(:features).where(:features => { :name => "Puppet CA" })
select_f f, :puppet_ca_proxy_id, proxies, :id, :name,
{ :include_blank => proxies.count > 1 },
{ :label => "Puppet CA",
:help_inline => "Use this puppet server as a CA server" }
end

def puppet_master f
proxies = SmartProxy.joins(:features).where(:features => { :name => "Puppet" })
select_f f, :puppet_proxy_id, proxies, :id, :name,
{ :include_blank => proxies.count > 1 },
{ :label => "Puppet Master",
936ba86f Ohad Levy
:help_inline => "Use this puppet server as an initial Puppet Server or to execute puppet runs" }
ace6fbad Ohad Levy
end

36f93e4d Ohad Levy
end