Skip to content

Commit 12452ee

Browse files
author
luke
committed
Merging r1468 from the implementations branch with r1438 from when the branch was first created.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1469 980ebf18-57e1-0310-9a29-db15c13687c0
1 parent 4d6120a commit 12452ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4994
-2829
lines changed

examples/root/etc/init.d/sleeper

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ path=`echo $script | sed 's/etc..*/bin/'`
77

88
PATH=$PATH:$path
99

10-
ps=`facter ps | cut -d ' ' -f3-`
10+
ps=`facter ps`
1111

1212
if [ -z "$ps" ]; then
1313
ps="ps -ef"

lib/puppet/autoload.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# I have no idea what's going on here, but...
2+
unless defined? MissingSourceFile
3+
class MissingSourceFile < RuntimeError
4+
end
5+
end
6+
# Autoload paths, either based on names or all at once.
7+
class Puppet::Autoload
8+
include Puppet::Util
9+
10+
@autoloaders = {}
11+
12+
attr_accessor :object, :path, :objwarn, :wrap
13+
14+
15+
class << self
16+
attr_reader :autoloaders
17+
private :autoloaders
18+
end
19+
Puppet::Util.classproxy self, :autoloaders, "[]", "[]=", :clear
20+
21+
attr_reader :loaded
22+
private :loaded
23+
24+
Puppet::Util.proxy self, :loaded, :clear
25+
26+
def initialize(obj, path, options = {})
27+
@path = path.to_s
28+
@object = obj
29+
30+
self.class[obj] = self
31+
32+
options.each do |opt, value|
33+
opt = opt.intern if opt.is_a? String
34+
begin
35+
self.send(opt.to_s + "=", value)
36+
rescue NoMethodError
37+
raise ArgumentError, "%s is not a valid option" % opt
38+
end
39+
end
40+
41+
unless defined? @wrap
42+
@wrap = true
43+
end
44+
45+
@loaded = {}
46+
end
47+
48+
def load(name)
49+
name = symbolize(name)
50+
51+
path = File.join(@path, name.to_s + ".rb")
52+
53+
begin
54+
Kernel.load path, @wrap
55+
@loaded[name] = true
56+
return true
57+
rescue MissingSourceFile
58+
return false
59+
rescue LoadError => detail
60+
# I have no idea what's going on here, but different versions
61+
# of ruby are raising different errors on missing files.
62+
unless detail.to_s =~ /^no such file/i
63+
warn "Could not autoload %s: %s" % [name, detail]
64+
end
65+
return false
66+
end
67+
end
68+
69+
def loaded?(name)
70+
name = symbolize(name)
71+
@loaded[name]
72+
end
73+
74+
def loadall
75+
# Load every instance of everything we can find.
76+
$:.each do |dir|
77+
fdir = File.join(dir, @path)
78+
if FileTest.exists?(fdir) and FileTest.directory?(fdir)
79+
Dir.glob("#{fdir}/*.rb").each do |file|
80+
# Load here, rather than require, so that facts
81+
# can be reloaded. This has some short-comings, I
82+
# believe, but it works as long as real classes
83+
# aren't used.
84+
name = File.basename(file).sub(".rb", '').intern
85+
next if @loaded.include? name
86+
begin
87+
Kernel.load file, @wrap
88+
@loaded[name] = true
89+
rescue => detail
90+
#if Puppet[:debug]
91+
# puts detail.backtrace
92+
#end
93+
warn "Could not autoload %s: %s" % [file.inspect, detail]
94+
end
95+
end
96+
end
97+
end
98+
end
99+
end
100+
101+
# $Id$

lib/puppet/client.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ class << self
2626

2727
def initcerts
2828
unless self.readcert
29-
unless self.requestcert
30-
return nil
31-
end
29+
#if self.is_a? Puppet::Client::CA
30+
unless self.requestcert
31+
return nil
32+
end
33+
#else
34+
# return nil
35+
#end
36+
#unless self.requestcert
37+
#end
3238
end
3339

3440
# unless we have a driver, we're a local client and we can't add
@@ -95,6 +101,15 @@ def initialize(hash)
95101
end
96102
end
97103

104+
# Are we a local client?
105+
def local?
106+
if defined? @local and @local
107+
true
108+
else
109+
false
110+
end
111+
end
112+
98113
# A wrapper method to run and then store the last run time
99114
def runnow
100115
if self.stopping

lib/puppet/client/master.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def getplugins
508508
File.basename(object[:path]).sub(".rb",'')
509509
load object[:path]
510510
rescue => detail
511-
Puppet.warning "Could not load %s: %s" %
511+
Puppet.warning "Could not reload plugin %s: %s" %
512512
[object[:path], detail]
513513
end
514514
end

lib/puppet/daemon.rb

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,45 @@ def requestcert
157157
}
158158
end
159159

160+
160161
unless defined? @driver
161162
Puppet.err "Cannot request a certificate without a defined target"
162163
return false
163164
end
164165

165-
Puppet.info "Creating a new certificate request for %s" % @fqdn
166-
name = OpenSSL::X509::Name.new([["CN", @fqdn]])
166+
unless defined? @csr
167+
Puppet.info "Creating a new certificate request for %s" % @fqdn
168+
name = OpenSSL::X509::Name.new([["CN", @fqdn]])
167169

168-
@csr = OpenSSL::X509::Request.new
169-
@csr.version = 0
170-
@csr.subject = name
171-
@csr.public_key = @key.public_key
172-
@csr.sign(@key, OpenSSL::Digest::MD5.new)
170+
@csr = OpenSSL::X509::Request.new
171+
@csr.version = 0
172+
@csr.subject = name
173+
@csr.public_key = @key.public_key
174+
@csr.sign(@key, OpenSSL::Digest::MD5.new)
175+
end
173176

174177
Puppet.info "Requesting certificate"
175178

179+
# We can only request a client with a CA client, so we need
180+
# to create one if we don't already have one (or if we're not a CA
181+
# server).
182+
caclient = nil
183+
if @driver.is_a? Puppet::Client::CA or @driver.is_a? Puppet::Server::CA
184+
caclient = @driver
185+
else
186+
# Create a CA client with which to request the cert.
187+
if @driver.local?
188+
raise Puppet::DevError,
189+
"Incorrect setup for a local CA request"
190+
end
191+
caclient = Puppet::Client::CA.new(
192+
:Port => @driver.puppet_port,
193+
:Server => @driver.puppet_server
194+
)
195+
end
196+
176197
begin
177-
cert, cacert = @driver.getcert(@csr.to_pem)
198+
cert, cacert = caclient.getcert(@csr.to_pem)
178199
rescue => detail
179200
if Puppet[:debug]
180201
puts detail.backtrace

lib/puppet/element.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Puppet::Element
1111

1212
class << self
1313
attr_accessor :doc, :nodoc
14+
include Puppet::Util
1415
end
1516

1617
# all of our subclasses must respond to each of these methods...
@@ -22,7 +23,7 @@ class << self
2223
@@interface_methods.each { |method|
2324
self.send(:define_method,method) {
2425
raise Puppet::DevError, "%s has not overridden %s" %
25-
[self.class,method]
26+
[self.class.name,method]
2627
}
2728
}
2829

lib/puppet/filetype.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def write(text)
145145
# Handle Linux-style cron tabs.
146146
newfiletype(:crontab) do
147147
def initialize(user)
148+
self.path = user
149+
end
150+
151+
def path=(user)
148152
begin
149153
uid = Puppet::Util.uid(user)
150154
rescue Puppet::Error => detail
@@ -153,7 +157,7 @@ def initialize(user)
153157

154158
# We have to have the user name, not the uid, because some
155159
# systems *cough*linux*cough* require it that way
156-
@path = user
160+
@path = uid
157161
end
158162

159163
# Read a specific @path's cron tab.
@@ -177,7 +181,7 @@ def write(text)
177181
private
178182

179183
# Only add the -u flag when the @path is different. Fedora apparently
180-
# does not think I should be allowed to set the @path to my
184+
# does not think I should be allowed to set the @path to my own user name
181185
def cmdbase
182186
cmd = nil
183187
if @path == Process.uid

lib/puppet/networkclient.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ClientError < RuntimeError; end
3030
Puppet.err "Could not load client network libs: %s" % $noclientnetworking
3131
else
3232
class NetworkClient < XMLRPC::Client
33+
attr_accessor :puppet_server, :puppet_port
3334
@clients = {}
3435

3536
# Create a netclient for each handler
@@ -126,6 +127,9 @@ def initialize(hash)
126127
hash[:Server] ||= "localhost"
127128
hash[:Port] ||= Puppet[:masterport]
128129

130+
@puppet_server = hash[:Server]
131+
@puppet_port = hash[:Port]
132+
129133
@puppetserver = hash[:Server]
130134

131135
super(

0 commit comments

Comments
 (0)