Project

General

Profile

« Previous | Next » 

Revision c9fff7c1

Added by Paul Kelly over 13 years ago

  • ID c9fff7c189b179aee2b3f0ab1c15c1e6206735e3

Fixes #168 - optional unattended settings

View differences:

app/controllers/hosts_controller.rb
end
def new
@host = Host.new
@host = Host.new :managed => true
@host.host_parameters.build
end
......
end
def edit
@host.managed = (@host.operatingsystem_id and @host.architecture_id and (@host.ptable_id or not @host.disk.empty?)) ? true : false
load_vars_for_ajax
end
def update
@host.managed = (@host.operatingsystem_id and @host.architecture_id and (@host.ptable_id or not @host.disk.empty?)) ? true : false
if @host.update_attributes(params[:host])
flash[:foreman_notice] = "Successfully updated host."
redirect_to @host
app/models/host.rb
alias_attribute :arch, :architecture
alias_attribute :hostname, :name
attr_accessor :managed
validates_uniqueness_of :name
validates_presence_of :name, :environment_id
if SETTINGS[:unattended].nil? or SETTINGS[:unattended]
......
validates_uniqueness_of :sp_mac, :allow_nil => true, :allow_blank => true
validates_uniqueness_of :sp_name, :sp_ip, :allow_blank => true, :allow_nil => true
validates_format_of :sp_name, :with => /.*-sp/, :allow_nil => true, :allow_blank => true
validates_presence_of :architecture_id, :domain_id, :mac, :operatingsystem_id
validates_presence_of :architecture_id, :operatingsystem_id, :if => Proc.new {|host| host.managed}
validates_presence_of :domain_id, :mac
validates_length_of :root_pass, :minimum => 8,:too_short => 'should be 8 characters or more'
validates_format_of :mac, :with => (/([a-f0-9]{1,2}:){5}[a-f0-9]{1,2}/)
validates_format_of :ip, :with => (/(\d{1,3}\.){3}\d{1,3}/)
validates_presence_of :ptable, :message => "cant be blank unless a custom partition has been defined",
:if => Proc.new { |host| host.disk.empty? and not defined?(Rake) }
:if => Proc.new { |host| host.managed and host.disk.empty? and not defined?(Rake) }
validates_format_of :sp_mac, :with => /([a-f0-9]{1,2}:){5}[a-f0-9]{1,2}/, :allow_nil => true, :allow_blank => true
validates_format_of :sp_ip, :with => /(\d{1,3}\.){3}\d{1,3}/, :allow_nil => true, :allow_blank => true
validates_format_of :serial, :with => /[01],\d{3,}n\d/, :message => "should follow this format: 0,9600n8", :allow_blank => true, :allow_nil => true
app/views/hosts/_form.html.erb
:with => :environment_id)
%>
<% if SETTINGS[:unattended].nil? or SETTINGS[:unattended] -%>
<% if (SETTINGS[:unattended].nil? or SETTINGS[:unattended]) and @host.managed -%>
<%= render 'unattended', :f => f %>
<% end -%>
test/unit/host_test.rb
test "should import facts from yaml of a new host" do
assert Host.importHostAndFacts(File.read(File.expand_path(File.dirname(__FILE__) + "/facts.yml")))
end
test "should not save if both ptable and disk are not defined" do
if SETTINGS[:unattended].nil? or SETTINGS[:unattended] == "true"
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 host.new_record?
else
true
end
if SETTINGS[:unattended].nil? or SETTINGS[:unattended]
test "should not save if neither ptable or disk are defined when the host is managed" do
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, :managed => true
assert !host.valid?
end
test "should save if neither ptable or disk are defined when the host is not managed" do
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, :managed => false
assert host.valid?
end
end
test "should save if ptable is defined" do

Also available in: Unified diff