From 310ea9295d948c9bb25a00575227f62c57c0346e Mon Sep 17 00:00:00 2001 From: Frank Sweetser Date: Tue, 8 Dec 2009 12:47:03 -0500 Subject: [PATCH] Only output yaml when node is found for puppetmasters host search function --- config/routes.rb | 2 +- extras/puppet/foreman/files/external_node.rb | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 16b144d..8e04a94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ ActionController::Routing::Routes.draw do |map| map.root :controller => "hosts" map.connect "node/:name", :controller => 'hosts', :action => 'externalNodes', - :requirements => { :name => /(.+\.)+\w+/ } + :requirements => { :name => /[^\.][\w\.-]+/ } map.connect "/hosts/query", :controller => 'hosts', :action => 'query' map.resources :hosts, :member => {:report => :get, :reports => :get, :facts => :get}, diff --git a/extras/puppet/foreman/files/external_node.rb b/extras/puppet/foreman/files/external_node.rb index a06155a..bf52af7 100755 --- a/extras/puppet/foreman/files/external_node.rb +++ b/extras/puppet/foreman/files/external_node.rb @@ -3,7 +3,22 @@ # you can basically use anything that knows how to get http data, e.g. wget/curl etc. # Foreman url -url="http://foreman:3000" +foreman_url="http://foreman:3000" require 'net/http' -Net::HTTP.get_print URI.parse("#{url}/node/#{ARGV[0]}?format=yml") + +foreman_url += "/node/#{ARGV[0]}?format=yml" +url = URI.parse(foreman_url) +req = Net::HTTP::Get.new(foreman_url) +res = Net::HTTP.start(url.host, url.port) { |http| + http.request(req) +} + +case res +when Net::HTTPOK + puts res.body +else + $stderr.puts "Error retrieving node %s: %s" % [ARGV[0], res.class] +end + + -- 1.6.5.2