Skip to content

Commit

Permalink
Merge pull request choria-legacy#9 from MaxMartin/master
Browse files Browse the repository at this point in the history
Resourcefile reading + general cleanup
  • Loading branch information
ripienaar committed Aug 31, 2011
2 parents 4fc5cfa + 0df515e commit 61f45ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
29 changes: 15 additions & 14 deletions agent/puppetral/agent/puppetral.ddl
Expand Up @@ -41,34 +41,35 @@ action "find", :description => "Get the value of a resource" do
:optional => false,
:maxlength => 90

input :name,
:prompt => "Resource name",
input :title,
:prompt => "Resource title",
:description => "Name of resource to check",
:type => :string,
:validation => '.',
:optional => true,
:maxlength => 90

output :type,
:description => "Type of the inspected resource",
:display_as => "Type"
:description => "Type of the inspected resource",
:display_as => "Type"

output :title,
:description => "Title of the inspected resource",
:display_as => "Title"

ouput :title,
:description => "Title of the inspected resource",
:display_as => "Title"

output :tags,
:description => "Tags of the inspected resource",
:display_as => "Tags"
:description => "Tags of the inspected resource",
:display_as => "Tags"

output :exported,
:description => "Boolean flag indicating export status",
:display_as => "Exported"
:description => "Boolean flag indicating export status",
:display_as => "Exported"

output :parameters,
:description => "Parameters of the inspected resource",
:display_as => "Parameters"
:description => "Parameters of the inspected resource",
:display_as => "Parameters"
end

action "search", :description => "Get the value of all resources of a certain type" do
display :always

Expand Down
13 changes: 10 additions & 3 deletions agent/puppetral/agent/puppetral.rb
Expand Up @@ -41,19 +41,26 @@ class Puppetral<RPC::Agent

action "find" do
type = request[:type]
name = request[:name]
title = request[:title]
typeobj = Puppet::Type.type(type) or raise "Could not find type #{type}"

if typeobj
result = Puppet::Resource.indirection.find([type, name].join('/')).to_pson_data_hash
result = Puppet::Resource.indirection.find([type, title].join('/')).to_pson_data_hash

result.each { |k,v| reply[k] = v }

begin
managed_resources = File.readlines(Puppet[:resourcefile])
managed_resources = managed_resources.map{|r|r.chomp}
reply[:managed] = managed_resources.include?("#{type}[#{title}]")
rescue
reply[:managed] = "unknown"
end
end
end

action "search" do
type = request[:type]
name = request[:name]
typeobj = Puppet::Type.type(type) or raise "Could not find type #{type}"

if typeobj
Expand Down
2 changes: 1 addition & 1 deletion agent/puppetral/spec/puppetral_spec.rb
Expand Up @@ -12,7 +12,7 @@

describe "#find" do
before :all do
@result = @agent.call(:find, :type => 'User', :name => 'bob')
@result = @agent.call(:find, :type => 'User', :title => 'bob')
end

it "should retrieve information about the type and title passed" do
Expand Down

0 comments on commit 61f45ae

Please sign in to comment.