diff options
| author | Luke Kanies <luke@madstop.com> | 2005-07-24 04:15:45 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-07-24 04:15:45 +0000 |
| commit | 075ffd752de203823673d2a3846b7ff2d3dc16ec (patch) | |
| tree | 0e02a3ac47100aa8093e71f0a4c8eb2adb23ec2c /lib/puppet | |
| parent | b5f6a548ebee48aee3f1bab067ea6451d1052089 (diff) | |
| download | puppet-075ffd752de203823673d2a3846b7ff2d3dc16ec.tar.gz puppet-075ffd752de203823673d2a3846b7ff2d3dc16ec.tar.xz puppet-075ffd752de203823673d2a3846b7ff2d3dc16ec.zip | |
making changes necessary to pass tests on all available platforms
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@458 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/client.rb | 162 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 8 |
2 files changed, 110 insertions, 60 deletions
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index 325a6d71e..1e3b0f4a2 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -12,17 +12,46 @@ require 'facter' require 'puppet/transaction' require 'puppet/transportable' require 'puppet/metric' -require 'http-access2' -require 'soap/rpc/driver' -require 'soap/rpc/httpserver' -#require 'webrick/https' -require 'logger' + +begin + require 'webrick' + require 'cgi' + require 'xmlrpc/client' + require 'xmlrpc/server' +rescue LoadError => detail + $nonetworking = detail +end module Puppet + class NetworkClientError < RuntimeError; end class ClientError < RuntimeError; end #--------------------------------------------------------------- - class Client < SOAP::RPC::HTTPServer + unless $nonetworking + class NetworkClient < XMLRPC::Client + @@methods = [ :getconfig ] + + @@methods.each { |method| + self.send(:define_method,method) { |*args| + begin + call("puppetmaster.%s" % method.to_s,*args) + rescue => detail + raise NetworkClientError.new(detail) + end + } + } + + def initialize(hash) + hash[:Path] ||= "/RPC2" + hash[:Server] ||= "localhost" + hash[:Port] ||= 8080 + super(hash[:Server],hash[:Path],hash[:Port]) + end + end + end + + class Client include Puppet + attr_accessor :local def Client.facts facts = {} Facter.each { |name,fact| @@ -36,47 +65,64 @@ module Puppet # to whom do we connect? @server = nil @nil = nil - @url = hash[:Server] - if hash.include?(:Listen) and hash[:Listen] == false - Puppet.debug "We're a local client" - @localonly = true - @driver = @url + if hash.include?(:Server) + case hash[:Server] + when String: + if $nonetworking + raise NetworkClientError.new("Networking not available: %s" % + $nonetworking) + end + + args = {} + [:Port, :Server].each { |arg| + if hash.include?(:Port) + args[arg] = hash[arg] + end + } + @driver = Puppet::NetworkClient.new(args) + @local = false + when Puppet::Master: + @driver = hash[:Server] + @local = true + else + raise ClientError.new("Server must be a hostname or a " + + "Puppet::Master object") + end else - Puppet.debug "We're a networked client" - @localonly = false - @driver = SOAP::RPC::Driver.new(@url, 'urn:puppet-server') - @driver.add_method("getconfig", "name", "facts") - end - unless @localonly - hash.delete(:Server) - - Puppet.debug "Server is %s" % @url - - hash[:BindAddress] ||= "0.0.0.0" - hash[:Port] ||= 17444 - #hash[:Debug] ||= true - hash[:AccessLog] ||= [] - - super(hash) + raise ClientError.new("Must pass :Server to client") end end def getconfig - Puppet.debug "server is %s" % @url #client.loadproperty('files/sslclient.properties') Puppet.debug("getting config") - objects = nil facts = Client.facts - #Puppet.info "Facts are %s" % facts.inspect - textfacts = Marshal::dump(facts) - if @localonly - objects = @driver.getconfig(self,facts) + unless facts.length > 0 + raise Puppet::ClientError.new( + "Could not retrieve any facts" + ) + end + + objects = nil + if @local + objects = @driver.getconfig(facts) + else + textfacts = CGI.escape(Marshal::dump(facts)) + textobjects = CGI.unescape(@driver.getconfig(textfacts)) + begin + objects = Marshal::load(textobjects) + rescue => detail + raise Puppet::Error.new("Could not understand configuration") + end + end + if objects.is_a?(Puppet::TransBucket) + self.config(objects) else - objects = @driver.getconfig(facts["hostname"],textfacts) + Puppet.warning objects.inspect + raise NetworkClientError.new(objects.class) end - self.config(objects) end # this method is how the client receives the tree of Transportable @@ -95,17 +141,19 @@ module Puppet Puppet.err "Corrupt state file %s" % Puppet[:statefile] begin File.unlink(Puppet[:statefile]) + retry rescue => detail raise Puppet::Error.new("Cannot remove %s: %s" % [Puppet[statefile], detail]) end end - if @localonly - container = tree.to_type - else - container = Marshal::load(tree).to_type - end + container = tree.to_type + #if @local + # container = tree.to_type + #else + # container = Marshal::load(tree).to_type + #end # this is a gross hack... but i don't see a good way around it # set all of the variables to empty @@ -125,28 +173,28 @@ module Puppet Metric.graph end Puppet::Storage.store - self.shutdown + #self.shutdown end - def callfunc(name,args) - Puppet.debug("Calling callfunc on %s" % name) - if function = Puppet::Function[name] - #debug("calling function %s" % function) - value = function.call(args) - #debug("from %s got %s" % [name,value]) - return value - else - raise "Function '%s' not found" % name - end - end + #def callfunc(name,args) + # Puppet.debug("Calling callfunc on %s" % name) + # if function = Puppet::Function[name] + # #debug("calling function %s" % function) + # value = function.call(args) + # #debug("from %s got %s" % [name,value]) + # return value + # else + # raise "Function '%s' not found" % name + # end + #end private - def on_init - @default_namespace = 'urn:puppet-client' - add_method(self, 'config', 'config') - add_method(self, 'callfunc', 'name', 'arguments') - end + #def on_init + # @default_namespace = 'urn:puppet-client' + # add_method(self, 'config', 'config') + # add_method(self, 'callfunc', 'name', 'arguments') + #end def cert(filename) OpenSSL::X509::Certificate.new(File.open(File.join(@dir, filename)) { |f| diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index f47806ebf..52ae06b67 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -339,9 +339,11 @@ module Puppet def sync unless Process.uid == 0 - raise Puppet::Error.new( - "Got told to sync owner as non-root user" - ) + # there's a possibility that we never got retrieve() called + # e.g., if the file didn't exist + # thus, just delete ourselves now and don't do any work + @parent.delete(self.name) + return nil end if @is == -1 |
