Project

General

Profile

« Previous | Next » 

Revision b06da7b9

Added by Daniel Lobato Garcia about 9 years ago

Fixes #10111 - Use a dummy primary interface for unmanaged hosts

Unmanaged hosts require a host interface due to delegation of networking
attributes, and some others like 'name'. Since unmanaged hosts do not
necessarily have an interface associated (unless created through puppet
facts importer), we provide a dummy interface to prevent errors.

Ideally this should go away as soon as unmanaged hosts are a different
class or Host::Base, moving validations and other particularities
to Host::Managed.

(cherry picked from commit a5dc3e23d6c2065149ea93b8687b3f5c32eb54b4)

View differences:

app/controllers/hosts_controller.rb
before_filter :taxonomy_scope, :only => [:new, :edit] + AJAX_REQUESTS
before_filter :set_host_type, :only => [:update]
before_filter :find_multiple, :only => MULTIPLE_ACTIONS
before_filter :cleanup_passwords, :only => :update
helper :hosts, :reports, :interfaces
def index(title = nil)
......
def update
forward_url_options
Taxonomy.no_taxonomy_scope do
# remove from hash :root_pass and bmc :password if blank?
params[:host].except!(:root_pass) if params[:host][:root_pass].blank?
if @host.type == "Host::Managed" && params[:host][:interfaces_attributes]
params[:host][:interfaces_attributes].each do |k, v|
params[:host][:interfaces_attributes]["#{k}"].except!(:password) if params[:host][:interfaces_attributes]["#{k}"][:password].blank?
end
end
if @host.update_attributes(params[:host])
process_success :success_redirect => host_path(@host)
else
......
def offer_to_overwrite_conflicts
@host.overwrite = "true" if @host.errors.any? and @host.errors.are_all_conflicts?
end
# :root_pass and bmc :password should not update the Host and Nic passwords when blank
# This method removes them from the params hash to avoid any processing of these attributes.
def cleanup_passwords
params[:host].except!(:root_pass) if params[:host][:root_pass].blank?
if @host.type == "Host::Managed" && params[:host][:interfaces_attributes]
params[:host][:interfaces_attributes].each do |k, v|
params[:host][:interfaces_attributes]["#{k}"].except!(:password) if params[:host][:interfaces_attributes]["#{k}"][:password].blank?
end
end
end
end

Also available in: Unified diff