summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/config_stores/rest.rb48
-rw-r--r--lib/puppet/util/config_store.rb5
2 files changed, 49 insertions, 4 deletions
diff --git a/lib/puppet/config_stores/rest.rb b/lib/puppet/config_stores/rest.rb
index 4f65f399b..531c7661f 100644
--- a/lib/puppet/config_stores/rest.rb
+++ b/lib/puppet/config_stores/rest.rb
@@ -1,19 +1,59 @@
Puppet::Util::ConfigStore.newstore(:rest) do
desc "Store client configurations via a REST web service."
+ require 'net/http'
+
# Get a client's config. (called in collector?)
def get(client, config)
- # Assuming this come in as Puppet::Parser objects
- # we may need way to choose which transport data type we use.
+ # Assuming this comes in as Puppet::Parser objects
+ # we may need way to choose which transport data type we use.
+
+ # hmm.. is this even useful for stored configs? I suppose there could
+ # be scenarios where it'd be cool, like ralsh or something.
end
def initialize
- # need config vars like puppetstore host, port, etc.
+ @host = Puppet[:puppetstorehost]
+ @port = Puppet[:puppetstoreport]
+
+ # Not sure if this is bad idea to share.
+ @http = Net::HTTP.new(@host, @port)
end
# Store config to the web service. (called in getconfig?)
def store(client, config)
- # Probably store as yaml...
+ # Probably store as yaml...
+ puppetstore = Thread.new do
+ benchmark(:notice, "Stored configuration for %s" % client) do
+ begin
+ # config should come from elsewhere; probably in getconfig I assume.
+ # should probably allow a config option for the serialization type.
+ yaml = YAML.dump(config)
+ url = "/collector/create"
+ @http.post(url, yaml, { 'Content-Type' => 'text/yaml' })
+ rescue => detail
+ Puppet.err("ERROR: storeconfig failed: ", detail.to_s)
+ end
+ end
+ end
+ puppetstore.run
+ end
+
+ # Rough first try... assuming the calling method handles the data type conversion
+ # Can we use a thread here? Probably needs to be the caller's thread.
+ def collect_exported(client, conditions)
+ begin
+ @http = Net::HTTP.new(@host, @port)
+ # Gotta be a better way... seems goofy to me.
+ # maybe using a nested rails rest route...
+ url = "/#{client}/resources?restype=exported"
+ conditions.each_pair {|k,v| url << "&#{k}=#{v}"}
+ res = http.get(url)
+ rescue => detail
+ Puppet.err("ERROR: collect_exported failed: ", detail.to_s)
+ end
+
+ return res.body unless !res.is_a?(Net::HTTPOK)
end
end
diff --git a/lib/puppet/util/config_store.rb b/lib/puppet/util/config_store.rb
index 4483eaed8..668d73f6e 100644
--- a/lib/puppet/util/config_store.rb
+++ b/lib/puppet/util/config_store.rb
@@ -51,6 +51,11 @@ module Puppet::Util
def store(client, config)
raise Puppet::DevError, "%s has not overridden store" % self.class.name
end
+
+ def collect_exported(client, conditions)
+ raise Puppet::DevError, "%s has not overridden collect_exported" % self.class.name
+ end
+
end
end