diff options
author | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-12 01:40:47 +0000 |
---|---|---|
committer | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-12 01:40:47 +0000 |
commit | 19af1cb35b3d6c1e8d6a986ba5712ca26ac3e907 (patch) | |
tree | 168dfa11aa127a4ac80bb094b9b5b63d6458442b /lib | |
parent | 12e565614183a34fff0832a78833f3a6626e2727 (diff) | |
download | puppet-19af1cb35b3d6c1e8d6a986ba5712ca26ac3e907.tar.gz puppet-19af1cb35b3d6c1e8d6a986ba5712ca26ac3e907.tar.xz puppet-19af1cb35b3d6c1e8d6a986ba5712ca26ac3e907.zip |
First try at the REST config_store
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2508 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/config_stores/rest.rb | 48 | ||||
-rw-r--r-- | lib/puppet/util/config_store.rb | 5 |
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 |