blob: 03ff7c6ac7cbfd3cd1a8cae4b725eb693045d42c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
require 'openssl'
require 'puppet'
require 'puppet/parser/interpreter'
require 'puppet/sslcertificates'
require 'xmlrpc/server'
module Puppet
class Server
class MasterError < Puppet::Error; end
class Master < Handler
attr_accessor :ast, :local
attr_reader :ca
@interface = XMLRPC::Service::Interface.new("puppetmaster") { |iface|
iface.add_method("string getconfig(string)")
}
def initialize(hash = {})
# FIXME this should all be s/:File/:Manifest/g or something
# build our AST
@file = hash[:File] || Puppet[:manifest]
hash.delete(:File)
if hash[:Local]
@local = hash[:Local]
else
@local = false
end
if hash.include?(:CA) and hash[:CA]
@ca = Puppet::SSLCertificates::CA.new()
else
@ca = nil
end
Puppet.debug("Creating interpreter")
args = {:Manifest => @file}
if hash.include?(:UseNodes)
args[:UseNodes] = hash[:UseNodes]
elsif @local
args[:UseNodes] = false
end
begin
@interpreter = Puppet::Parser::Interpreter.new(args)
rescue => detail
Puppet.err detail
raise
end
end
def getconfig(facts, client = nil, clientip = nil)
if @local
# we don't need to do anything, since we should already
# have raw objects
Puppet.debug "Our client is local"
else
Puppet.debug "Our client is remote"
# XXX this should definitely be done in the protocol, somehow
begin
facts = Marshal::load(CGI.unescape(facts))
rescue => detail
puts "AAAAA"
puts detail
exit
end
end
unless client
client = facts["hostname"]
clientip = facts["ipaddress"]
end
Puppet.debug("Running interpreter")
begin
retobjects = @interpreter.run(client, facts)
rescue => detail
Puppet.err detail.to_s
return ""
end
if @local
return retobjects
else
return CGI.escape(Marshal::dump(retobjects))
end
end
end
end
end
|