Project

General

Profile

« Previous | Next » 

Revision b729fb04

Added by Paul Kelly almost 14 years ago

  • ID b729fb042c3c82172050a0fe477c6ff9f2c2174d

Fixes #212 - Remove AS from facts

View differences:

app/controllers/application_controller.rb
before_filter :require_ssl, :require_login
before_filter :load_tabs, :manage_tabs
def self.active_scaffold_controller_for(klass)
return FactNamesController if klass == Puppet::Rails::FactName
return FactValuesController if klass == Puppet::Rails::FactValue
return "#{klass}ScaffoldController".constantize rescue super
end
# host list AJAX methods
# its located here, as it might be requested from the dashboard controller or via the hosts controller
def fact_selected
@fact_name_id = params[:search_fact_values_fact_name_id_eq].to_i
@fact_values = FactValue.find(:all, :select => 'DISTINCT value', :conditions => {
@fact_name_id = params[:search_fact_name_id].to_i
@via = params[:via]
@values = FactValue.find(:all, :select => 'DISTINCT value', :conditions => {
:fact_name_id => @fact_name_id }, :order => 'value ASC') if @fact_name_id > 0
render :partial => 'common/fact_selected', :layout => false
end
app/controllers/fact_names_controller.rb
class FactNamesController < ApplicationController
end
app/controllers/fact_values_controller.rb
# avoids storing the facts data in the log files
filter_parameter_logging :facts
active_scaffold :fact_value do |config|
config.list.columns = [:name, :value, :host]
config.actions = [:list]
config.columns = [:name, :value]
config.columns[:name].sort = true
config.columns[:name].sort_by :method => 'name'
config.actions.add :list_filter
config.list_filter.add(:association, :fact_name)
def index
@search = FactValue.search(params[:search])
@fact_values = @search.paginate :page => params[:page], :include => [:fact_name, { :host => :domain }]
@via = ""
end
def create
app/controllers/hosts_controller.rb
def index
@search = Host.search(params[:search])
@hosts = @search.paginate :page => params[:page]
@hosts = @search.paginate :page => params[:page]
@via = "fact_values_"
end
def show
app/models/fact_value.rb
class FactValue < Puppet::Rails::FactValue
belongs_to :host #ensures we uses our Host model and not Puppets
delegate :name, :to => :fact_name
# Todo: find a way to filter which values are logged,
# this generates too much useless data
......
end
hash
end
# proxy accessor for fact name
def name
fact_name.name
def self.per_page
15
end
end
app/models/host.rb
end
def self.importHostAndFacts yaml
facts = YAML::load yaml
raise "invalid Fact" unless facts.is_a?(Puppet::Node::Facts)
h=Host.find_or_create_by_name facts.name
return h.importFacts(facts)
begin
facts = YAML::load yaml
raise "invalid Fact" unless facts.is_a?(Puppet::Node::Facts)
h=Host.find_or_create_by_name facts.name
return h.importFacts(facts)
rescue Exception => e
logger.error e.message
false
end
end
# import host facts, required when running without storeconfigs.
app/views/common/_fact_selected.html.erb
<%= hidden_field_tag :via, @via %>
<span id=fact_search>
<%= label_tag "Fact Name" %>
<%= collection_select :search, :fact_values_fact_name_id_eq,
<%= label_tag :search_fact_name_id, "Fact Name" %>
<%= collection_select :search, "#{@via}fact_name_id_eq".to_sym,
Puppet::Rails::FactName.all(:select => "id, name", :order => "name ASC"),
:id, :name, :selected => @fact_name_id, :include_blank => "Select a fact"
:id, :name, {:selected => @fact_name_id, :include_blank => "Select a fact"},
{:id => :search_fact_name_id}
%>
<% if @fact_values -%>
<%= label :fact_values_value_eq, "Value" %>
<%= collection_select :search, :fact_values_value_eq, @fact_values, :value, :value %>
<% if @values -%>
<%= label "search_#{@via}value_eq", "Value" %>
<%= collection_select :search, "#{@via}value_eq".to_sym, @values, :value, :value %>
<% end -%>
</span>
<%= observe_field(:search_fact_values_fact_name_id_eq,
<%= observe_field(:search_fact_name_id,
:url => { :action => :fact_selected },
:update => :fact_search,
:with => :search_fact_values_fact_name_id_eq) %>
:with => "'search_fact_name_id=' + value + '&via=' + $F(\'via\')") %>
app/views/fact_values/_search_line.html.erb
<% form_for @search do |f|-%>
<span title="A substring match">
<%= f.label :host_name_like, "Host" %>
<%= f.text_field :host_name_like, :size => 10 %>
</span>
<%= render :partial => 'common/fact_selected' %>
<%= f.submit "Go" %> Save as tab: <%= text_field_tag :tab_name, "", :size => 10 %>
<% end %>
app/views/fact_values/index.html.erb
<% title "Fact Values" %>
<table class="list">
<tr>
<th><%= order @search, :by => :host_name, :as => :Host %></th>
<th><%= order @search, :by => :fact_name_name, :as => :Name %></th>
<th><%= order @search, :by => :value %></th>
</tr>
<% for fact_value in @fact_values %>
<% next if fact_value.name == "--- :_timestamp\n" -%>
<tr class="<%= cycle("even", "odd") -%>">
<td><%= link_to(h(fact_value.host.shortname), hosts_path("search[id_eq]"=> fact_value.host)) %></td>
<td>
<%= link_to h(fact_value.fact_name.name),
fact_values_path("search[fact_name_id_eq]" => fact_value.fact_name),
:title => "Show all #{fact_value.name} facts" %>
</td>
<td>
<%= link_to h(truncate fact_value.value, :length => 40),
fact_values_path("search[fact_name_id_eq]" => fact_value.fact_name, :"search[value_eq]" => fact_value.value),
:title => "Show all #{fact_value.name} facts where they are equal to #{fact_value.value}" %>
</td>
</tr>
<% end %>
</table>
<%= page_entries_info @fact_values %>
<%= will_paginate @fact_values %>
app/views/hosts/facts.html.erb
<%= render :active_scaffold => 'fact_values', :constraints => { :host => @host}, :label => "Facts for #{@host.name}"%>
<%= link_to 'Back', :back %>
app/views/hosts/show.html.erb
<%= @host.to_label %>
<span id="host_actions">
<%= link_to "Edit", edit_host_path(@host), :title => "Edit your host" %> |
<%= link_to "Facts", facts_host_path(@host), :title => "Browse host facts" %> |
<%= link_to "Facts", fact_values_path("search[host_id_eq]" => @host.id), :title => "Browse host facts" %> |
<%= link_to "Reports", reports_host_path(@host), :title => "Browse host reports" %> |
<%= link_to "YAML", externalNodes_host_path(@host), :title => "Puppet external nodes YAML dump" %> |
<%= link_to_if @host.can_be_build?, "Build", setBuild_host_path(@host), :title => "prepare this host for build" %> |
config/routes.rb
:requirements => { :name => /[^\.][\w\.-]+/ }
map.connect "/hosts/query", :controller => 'hosts', :action => 'query'
map.resources :hosts,
:member => { :report => :get, :reports => :get, :facts => :get, :clone => :get,
:member => { :report => :get, :reports => :get, :clone => :get,
:environment_selected => :post, :architecture_selected => :post, :os_selected => :post,
:storeconfig_klasses => :get, :externalNodes => :get, :setBuild => :get, :puppetrun => :get},
:collection => { :show_search => :get, :multiple_actions => :get, :multiple_parameters => :get,
......
map.resources :common_parameters
map.resources :environments, :collection => {:import_environments => :get}
map.resources :subnets, :active_scaffold => true
map.resources :fact_values, :active_scaffold => true
map.resources :fact_values
map.resources :ptables
map.resources :auth_source_ldaps
map.resources :users, :collection => {:login => [:get, :post], :logout => :get}
public/stylesheets/style.css
/* Tables */
table.list { border: 1px solid #e4e4e4; border-collapse: collapse; width: 100%; margin-bottom: 4px; }
table.list th { background-color:#EEEEEE; padding: 4px; white-space:nowrap; }
table.list td { vertical-align: top; border: 1px #fff solid; padding: 4px }
table.list th { background-color:#EEEEEE; padding: 4px; white-space:nowrap; text-align:left; }
table.list td { vertical-align: top; border: 1px #eeeeee solid; padding: 4px }
table.list td.id { width: 2%; text-align: center;}
table.list td.checkbox { width: 15px; padding: 0px;}
table.list tbody tr:hover { background-color:#ffffaa; }
test/fixtures/brslc022.facts.yaml
--- !ruby/object:Puppet::Node::Facts
name: brslc022.brs.infineon.com
values:
is_virtual: "true"
processorcount: "2"
serialnumber: VMware-56 4d 15 06 72 86 a9 d3-8a 09 fc 27 5a cf 00 45
kernel: Linux
virtual: vmware
:_timestamp: 2010-02-16 12:52:38.163833 +01:00
network_eth0: 172.29.205.0
operatingsystemrelease: "4"
uniqueid: 1dac16cd
hardwaremodel: i686
rubysitedir: /usr/lib/site_ruby/1.8
platform: Linux_2.6_i386_all
uptime_seconds: "3756"
lsbrelease: ":core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch"
memorysize: 1.45 GB
gi: "4"
netmask_eth0: 255.255.255.128
ipaddress: 172.29.205.22
physicalprocessorcount: "0"
swapfree: 1.95 GB
vmware: virtual
netmask: 255.255.255.128
clientversion: 0.24.8
fqdn: brslc022.brs.infineon.com
timezone: GMT
ps: ps -ef
kernelrelease: 2.6.9-89.0.16.ELsmp
hardwareisa: i686
domain: brs.infineon.com
type: Other
kernelversion: 2.6.9
id: root
lsbdistdescription: Red Hat Enterprise Linux AS release 4 (Nahant Update 8)
uptime_hours: "1"
lsbdistrelease: "4"
macaddress_eth0: 00:0C:29:CF:00:45
manufacturer: VMware, Inc.
memoryfree: 1.39 GB
selinux: "false"
gateway_if: eth0
lsbdistcodename: NahantUpdate8
sshrsakey: AAAAB3NzaC1yc2EAAAABIwAAAIEAyj0XAKzx4WlNE8Vzj0ABBEHxqHr2H4AZZnabnQkYTOfz5kObXL+BvYqPONg2EqeUYCTNaFtQQPpJ4H+TM+GCJDNvFEKJTRd+cFoOuramf9LunWN/+ETreQ5V8KhKvdYTNw5blPBKiQz/XxSxcm7beo5QiBVr/lOM0u8YhGTLawk=
uptime_days: "0"
interfaces: eth0
hostname: brslc022
graphcard: VMware
uptime: 1:02 hours
processor0: Intel(R) Xeon(R) CPU X5460 @ 3.16GHz
puppetversion: 0.24.8
productname: VMware Virtual Platform
architecture: i386
gateway: 172.29.205.1
rubyversion: 1.8.1
environment: brs_test
path: /usr/bin:/sbin:/bin:/usr/sbin:/opt/csw/bin
swapsize: 1.95 GB
ipaddress_eth0: 172.29.205.22
facterversion: 1.5.7
kernelmajversion: "2.6"
operatingsystem: RedHat
macaddress: 00:0C:29:CF:00:45
processor1: Intel(R) Xeon(R) CPU X5460 @ 3.16GHz
lsbmajdistrelease: "4"
sshdsakey: AAAAB3NzaC1kc3MAAACBAIUasO2eEvlRHfcO8wMPfbo98YfgVsJj0qhUDSSoSa6xmYI8QWBDMoxf1h8INiDfrNQ5e4VreLQjt4/2Ex7OXoeB7C9Cg18/TlfZU+RTNMdsL85W5hQrrKoBm+ksMnxidkDC66ROq+pmxBTGDwwxg3ugF8eZnVSzCZ1FE605AsStAAAAFQCrr3s1cLQFRc6oZJAx3EZDxDraCQAAAIBqIqIvY7KtRsI+8y8E5MSZXpRRZxf0zqbraDxASwzImUr6ysEmpJsHbHyi6UePnF55tG/iZNM4bSNg/3qExK8So040byV71qN4HNT48nIh3cCS0z8oKLqvlCRJ+dOY1QMkE8ZLfOyF4A6ZOTuE8TTsGpvUIR0HyXkpoiIR9XcgzgAAAIA4nkedBQi+VA01NvWx27GGz5P3TTQ36yDODZdLmXoepQM1rPfKWvPFFd5MxgJumSU5BKhYUiQTOImcRlQcY5DA3dGbog1dOAKlWyeJn4WRHbYr+VNgR/HwBzHLMW4TXLt38ThmPv9TiLS1RvTdHuDm2oRTadNZOrmQz619kZejmw==
lsbdistid: RedHatEnterpriseAS
test/functional/fact_values_controller_test.rb
require 'test_helper'
class FactValuesControllerTest < ActionController::TestCase
test "should get list" do
get :list, {}, set_session_user
def fact_fixture
Pathname.new("#{RAILS_ROOT}/test/fixtures/brslc022.facts.yaml").read
end
def test_index
get :index, {}, set_session_user
assert_response :success
assert_not_nil :records
assert_template 'index'
assert_not_nil :fact_values
end
test "should get list_filter" do
get :list_filter, {}, set_session_user
assert_response :found
def test_create_invalid
post :create, {:facts => fact_fixture[1..-1]}, set_session_user
assert_response :error
end
def test_create_valid
post :create, {:facts => fact_fixture}, set_session_user
assert_response :success
end
end

Also available in: Unified diff