Module: HostCommon::InstanceMethods

Defined in:
app/models/host_common.rb

Instance Method Summary collapse

Instance Method Details

#default_image_fileObject

If the host/hostgroup has a medium then use the path from there Else if the host/hostgroup's operatingsystem has only one media then use the image_path from that as this is automatically displayed when there is only one item Else we cannot provide a default and it is cut and paste time


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/host_common.rb', line 69

def default_image_file
  return "" unless operatingsystem and operatingsystem.supports_image
  if medium
    nfs_path = medium.try :image_path
    if operatingsystem.try(:media) and operatingsystem.media.size == 1
      nfs_path ||= operatingsystem.media.first.image_path
    end
    # We encode the hw_model into the image file name as not all Sparc flashes can contain all possible hw_models. The user can always
    # edit it if required or use symlinks if they prefer.
    hw_model = model.try :hardware_model if defined?(model_id)
    operatingsystem.interpolate_medium_vars(nfs_path, architecture.name, operatingsystem) +\
      "#{operatingsystem.file_prefix}.#{architecture}#{hw_model.empty? ? "" : "." + hw_model.downcase}.#{operatingsystem.image_extension}"
  else
    ""
  end
end

#image_fileObject


93
94
95
# File 'app/models/host_common.rb', line 93

def image_file
  super || default_image_file
end

#image_file=(file) ⇒ Object


86
87
88
89
90
91
# File 'app/models/host_common.rb', line 86

def image_file= file
  # We only save a value into the image_file field if the value is not the default path, (which was placed in the entry when it was displayed,)
  # and it is not a directory, (ends in /)
  value = ( (default_image_file == file) or (file =~ /\/$/) or file == "") ? nil : file
  write_attribute :image_file, value
end

#puppet_ca_serverObject


62
63
64
# File 'app/models/host_common.rb', line 62

def puppet_ca_server
  puppet_ca_proxy.to_s
end

#puppetca?Boolean


50
51
52
53
# File 'app/models/host_common.rb', line 50

def puppetca?
  return false if self.respond_to?(:managed?) and !managed?
  !!(puppet_ca_proxy and puppet_ca_proxy.url.present?)
end

#puppetmasterObject

no need to store anything in the db if the entry is plain “puppet” If the system is using smart proxies and the user has run the smartproxy:migrate task then the puppetmaster functions handle smart proxy objects


58
59
60
# File 'app/models/host_common.rb', line 58

def puppetmaster
  puppet_proxy.to_s
end

#root_pass=(pass) ⇒ Object

make sure we store an encrypted copy of the password in the database this password can be use as is in a unix system


99
100
101
102
# File 'app/models/host_common.rb', line 99

def root_pass=(pass)
  p = pass.empty? ? nil : (pass.starts_with?('$') ? pass : pass.crypt("$1$#{SecureRandom.base64(6)}"))
  write_attribute(:root_pass, p)
end

#url_for_boot(file) ⇒ Object

Returns a url pointing to boot file


46
47
48
# File 'app/models/host_common.rb', line 46

def url_for_boot file
  "#{os.medium_uri(self)}/#{os.url_for_boot(file)}"
end