summaryrefslogtreecommitdiffstats
path: root/lib/blink/client.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-05-21 23:07:57 +0000
committerLuke Kanies <luke@madstop.com>2005-05-21 23:07:57 +0000
commit03741b41b3fba65d10c9adafd8969913876e28d2 (patch)
treeb9683cdb933bd71895e4fff68f13e45197131a4f /lib/blink/client.rb
parent4a4438dbf226335ea3c885a4ced32174d4123542 (diff)
downloadpuppet-03741b41b3fba65d10c9adafd8969913876e28d2.tar.gz
puppet-03741b41b3fba65d10c9adafd8969913876e28d2.tar.xz
puppet-03741b41b3fba65d10c9adafd8969913876e28d2.zip
we now have networking
it is very basic right now: the server gets passed a file name, and the client gets passed the server to which to connect. The client gets its config, evaluates it, and exits git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@266 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/blink/client.rb')
-rw-r--r--lib/blink/client.rb112
1 files changed, 86 insertions, 26 deletions
diff --git a/lib/blink/client.rb b/lib/blink/client.rb
index 0c4c59bcf..627d8e4eb 100644
--- a/lib/blink/client.rb
+++ b/lib/blink/client.rb
@@ -7,42 +7,102 @@
require 'blink'
require 'blink/function'
require 'blink/type'
+require 'blink/fact'
require 'blink/transaction'
require 'blink/transportable'
+require 'http-access2'
+require 'soap/rpc/driver'
+require 'soap/rpc/httpserver'
+#require 'webrick/https'
+require 'logger'
module Blink
class ClientError < RuntimeError; end
#---------------------------------------------------------------
- class Client
- attr_accessor :objects
-
- class Local
- def callfunc(name,args)
- if function = Blink::Function[name]
- #Blink.debug("calling function %s" % function)
- value = function.call(args)
- #Blink.debug("from %s got %s" % [name,value])
- return value
- else
- raise "Function '%s' not found" % name
- end
+ class Client < SOAP::RPC::HTTPServer
+ def initialize(hash)
+ # to whom do we connect?
+ if hash.include?(:Local) and hash[:Local] == true
+ @localonly = true
+ else
+ @localonly = false
end
+ unless @localonly
+ @url = hash[:Server]
+ hash.delete(:Server)
- # this method is how the client receives the tree of Transportable
- # objects
- # for now, just descend into the tree and perform and necessary
- # manipulations
- def objects=(tree)
- container = tree.to_type
-
- # for now we just evaluate the top-level container, but eventually
- # there will be schedules and such associated with each object,
- # and probably with the container itself
- transaction = container.evaluate
- #transaction = Blink::Transaction.new(objects)
- transaction.evaluate
+ Blink.notice "Server is %s" % @url
+
+ hash[:BindAddress] ||= "0.0.0.0"
+ hash[:Port] ||= 17444
+ hash[:Debug] ||= true
+ hash[:AccessLog] ||= []
+
+ super(hash)
+ end
+ end
+
+ def getconfig
+ Blink.debug "server is %s" % @url
+ @driver = SOAP::RPC::Driver.new(@url, 'urn:blink-server')
+ @driver.add_method("getconfig", "name")
+ #client.loadproperty('files/sslclient.properties')
+ Blink.notice("getting config")
+ objects = @driver.getconfig(Blink::Fact["hostname"])
+ self.config(objects)
+ end
+
+ # this method is how the client receives the tree of Transportable
+ # objects
+ # for now, just descend into the tree and perform and necessary
+ # manipulations
+ def config(tree)
+ Blink.notice("Calling config")
+ Blink.verbose tree.inspect
+ container = Marshal::load(tree).to_type
+ #Blink.verbose container.inspect
+
+ # for now we just evaluate the top-level container, but eventually
+ # there will be schedules and such associated with each object,
+ # and probably with the container itself
+ transaction = container.evaluate
+ #transaction = Blink::Transaction.new(objects)
+ transaction.evaluate
+ self.shutdown
+ end
+
+ def callfunc(name,args)
+ Blink.notice("Calling callfunc on %s" % name)
+ if function = Blink::Function[name]
+ #Blink.debug("calling function %s" % function)
+ value = function.call(args)
+ #Blink.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:blink-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|
+ f.read
+ })
+ end
+
+ def key(filename)
+ OpenSSL::PKey::RSA.new(File.open(File.join(@dir, filename)) { |f|
+ f.read
+ })
+ end
+
end
#---------------------------------------------------------------
end