Project

General

Profile

« Previous | Next » 

Revision 9c3ffb6b

Added by Ohad Levy over 14 years ago

  • ID 9c3ffb6b7826a4b61984a2b1292edfe73afd9bbc

switches global setting var to be a constant var - refs #100

View differences:

app/controllers/application_controller.rb
#Force a user to login if ldap authentication is enabled
def require_login
return true unless $settings[:ldap]
return true unless SETTINGS[:ldap]
unless (session[:user] and (@user = User.find(session[:user])))
session[:original_uri] = request.request_uri
redirect_to :controller => "users", :action => "login"
app/controllers/hosts_controller.rb
config.columns[:puppetclasses].options = { :draggable_lists => {}}
config.columns[:fact_values].association.reverse = :host
config.nested.add_link("Inventory", [:fact_values])
config.columns[:puppetmaster].description = "leave empty if it is #{$settings[:puppet_server] || "puppet"}"
config.columns[:puppetmaster].description = "leave empty if it is #{SETTINGS[:puppet_server] || "puppet"}"
# do not show these fields if unattended mode is disabled
if $settings[:unattended].nil? or $settings[:unattended]
if SETTINGS[:unattended].nil? or SETTINGS[:unattended]
config.columns = %w{ name ip mac hostgroup puppetclasses operatingsystem environment architecture media domain model root_pass serial puppetmaster ptable disk comment host_parameters}
config.columns[:architecture].form_ui = :select
config.columns[:media].form_ui = :select
......
Are you sure you want to reinstall this host?"
end
config.action_links.add 'rrdreport', :label => 'RRDReport', :inline => true,
:type => :record, :position => :after if $settings[:rrd_report_url]
:type => :record, :position => :after if SETTINGS[:rrd_report_url]
config.action_links.add 'externalNodes', :label => 'YAML', :inline => true,
:type => :record, :position => :after
end
......
# generates a link to Puppetmaster RD graphs
def rrdreport
if $settings[:rrd_report_url].nil? or (host=Host.find(params[:id])).last_report.nil?
if SETTINGS[:rrd_report_url].nil? or (host=Host.find(params[:id])).last_report.nil?
render :text => "Sorry, no graphs for this host"
else
render :partial => "rrdreport", :locals => { :host => host}
app/helpers/unattended_helper.rb
def ca_pubkey
#TODO: replace hardcoded dirs into puppet variables
unless $settings[:CAPubKey].nil?
"echo \"#{$settings[:CAPubKey]}\" >> /var/lib/puppet/ssl/certs/ca.pem
unless SETTINGS[:CAPubKey].nil?
"echo \"#{SETTINGS[:CAPubKey]}\" >> /var/lib/puppet/ssl/certs/ca.pem
count=`grep -c -- \"--END\" /var/lib/puppet/ssl/certs/ca.pem`
echo \"Updated the certificate chain. There are now $count certificates\""
end
app/models/environment.rb
if env.size == 0
# fall back to defaults - we probably don't use environments
env[:production] = conf[:main][:modulepath] || conf[:puppetmasterd][:modulepath] || $settings[:modulepath] || Puppet[:modulepath] || "/etc/puppet/modules"
env[:production] = conf[:main][:modulepath] || conf[:puppetmasterd][:modulepath] || SETTINGS[:modulepath] || Puppet[:modulepath] || "/etc/puppet/modules"
end
end
return env
app/models/host.rb
validates_uniqueness_of :name
validates_presence_of :name, :environment_id
if $settings[:unattended].nil? or $settings[:unattended]
if SETTINGS[:unattended].nil? or SETTINGS[:unattended]
validates_uniqueness_of :ip
validates_uniqueness_of :mac
validates_uniqueness_of :sp_mac, :allow_nil => true, :allow_blank => true
......
GW::Puppetca.disable self.name
GW::Tftp.remove self.mac
save
site_post_built = "#{$settings[:modulepath]}sites/#{self.domain.name.downcase}/built.sh"
site_post_built = "#{SETTINGS[:modulepath]}sites/#{self.domain.name.downcase}/built.sh"
if File.executable? site_post_built
%x{#{site_post_built} #{self.name} >> #{$settings[:logfile]} 2>&1 &}
%x{#{site_post_built} #{self.name} >> #{SETTINGS[:logfile]} 2>&1 &}
end
end
# no need to store anything in the db if the entry is plain "puppet"
def puppetmaster
read_attribute(:puppetmaster) || $settings[:puppet_server] || "puppet"
read_attribute(:puppetmaster) || SETTINGS[:puppet_server] || "puppet"
end
def puppetmaster=(pm)
write_attribute(:puppetmaster, pm == ($settings[:puppet_server] || "puppet") ? nil : pm)
write_attribute(:puppetmaster, pm == (SETTINGS[:puppet_server] || "puppet") ? nil : pm)
end
#retuns fqdn of host puppetmaster
......
# no need to store anything in the db if the password is our default
def root_pass
read_attribute(:root_pass) || $settings[:root_pass] || "!*!*!*!*!"
read_attribute(:root_pass) || SETTINGS[:root_pass] || "!*!*!*!*!"
end
# make sure we store an encrypted copy of the password in the database
app/views/home/settings.erb
<li><%= link_to 'Partition Tables', { :controller => 'ptables' } %></li>
<li><%= link_to 'Global Parameters', { :controller => 'common_parameters' } %></li>
<li><%= link_to 'LDAP Authentication',{ :controller => 'auth_sources' } %></li>
<li><%= link_to_if $settings[:ldap], 'Users', { :controller => 'users' } %></li>
<li><%= link_to_if SETTINGS[:ldap], 'Users', { :controller => 'users' } %></li>
</ul>
app/views/hosts/_rrdreport.rhtml
<h3><%= host.name %> Last puppet report on <%= host.last_report.getlocal %>, which is <%= time_ago_in_words(host.last_report) %> ago</h3>
<center>
<% url = "http://#{host.pm_fqdn}/#{$settings[:rrd_report_url]}/#{host.name}" -%>
<% url = "http://#{host.pm_fqdn}/#{SETTINGS[:rrd_report_url]}/#{host.name}" -%>
<h4>Daily</h4>
<img src = <%= "#{url}/time-daily.png"%>>
<img src = <%= "#{url}/changes-daily.png"%>>
config/initializers/foreman.rb
require 'gchart'
# import settings file
$settings = YAML.load_file("#{RAILS_ROOT}/config/settings.yaml")
SETTINGS= YAML.load_file("#{RAILS_ROOT}/config/settings.yaml")
Puppet[:config] = $settings[:puppetconfdir] || "/etc/puppet/puppet.conf"
Puppet[:config] = SETTINGS[:puppetconfdir] || "/etc/puppet/puppet.conf"
Puppet.parse_config
# Add an empty method to nil. Now no need for if x and x.empty?. Just x.empty?
test/unit/host_test.rb
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
:domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first,
:architecture => Architecture.first, :environment => Environment.first
assert true unless $settings[:attended]
assert true unless SETTINGS[:attended]
assert !host.valid?
end
vendor/plugins/proxy/lib/proxy.rb
private
# returns the absolute path
def self.path( p = $settings[:tftppath] )
def self.path( p = SETTINGS[:tftppath] )
# are we running in RAILS or as a standalone CGI?
dir = RAILS_ROOT ? RAILS_ROOT : File.dirname(__FILE__)
return (p =~ /^\//) ? p : "#{dir}/#{p}"

Also available in: Unified diff