| Path: | lib/puppet/config_stores/rest.rb |
| Last Update: | Tue Jul 08 15:46:19 +0200 2008 |
# File lib/puppet/config_stores/rest.rb, line 15
15: def initialize
16: @host = Puppet[:puppetstorehost]
17: @port = Puppet[:puppetstoreport]
18:
19: # Not sure if this is bad idea to share.
20: @http = Net::HTTP.new(@host, @port)
21: 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.
# File lib/puppet/config_stores/rest.rb, line 44
44: def collect_exported(client, conditions)
45: begin
46: # Gotta be a better way... seems goofy to me.
47: # maybe using a nested rails rest route...
48:
49: # filterhost so we don't get exported resources for the current client
50: url = "/resources?restype=exported&filterhost=#{client}"
51: conditions.each_pair {|k,v| url << "&#{k}=#{v}"}
52: res = @http.get(url)
53: rescue => detail
54: Puppet.err("ERROR: collect_exported failed: ", detail.to_s)
55: end
56:
57: return res.body unless !res.is_a?(Net::HTTPOK)
58: end
Get a client‘s config. (called in collector?)
# File lib/puppet/config_stores/rest.rb, line 7
7: def get(client, config)
8: # Assuming this comes in as Puppet::Parser objects
9: # we may need way to choose which transport data type we use.
10:
11: # hmm.. is this even useful for stored configs? I suppose there could
12: # be scenarios where it'd be cool, like ralsh or something.
13: end
Store config to the web service. (called in getconfig?)
# File lib/puppet/config_stores/rest.rb, line 24
24: def store(client, config)
25: # Probably store as yaml...
26: puppetstore = Thread.new do
27: benchmark(:notice, "Stored configuration for %s" % client) do
28: begin
29: # config should come from elsewhere; probably in getconfig I assume.
30: # should probably allow a config option for the serialization type.
31: yaml = YAML.dump(config)
32: url = "/collector/create"
33: @http.post(url, yaml, { 'Content-Type' => 'text/yaml' })
34: rescue => detail
35: Puppet.err("ERROR: storeconfig failed: ", detail.to_s)
36: end
37: end
38: end
39: puppetstore.run
40: end