summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/blink/client.rb112
-rw-r--r--lib/blink/function.rb2
-rw-r--r--lib/blink/statechange.rb4
-rw-r--r--lib/blink/type.rb14
-rw-r--r--test/client/tc_client.rb4
5 files changed, 100 insertions, 36 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
diff --git a/lib/blink/function.rb b/lib/blink/function.rb
index 4f10fb2c6..d5cc11107 100644
--- a/lib/blink/function.rb
+++ b/lib/blink/function.rb
@@ -33,7 +33,7 @@ module Blink
#---------------------------------------------------------------
end
- Function.new("retrieve", proc { |fact|
+ Function.new("fact", proc { |fact|
require 'blink/fact'
value = Fact[fact]
diff --git a/lib/blink/statechange.rb b/lib/blink/statechange.rb
index e0b0a6794..49b6484bb 100644
--- a/lib/blink/statechange.rb
+++ b/lib/blink/statechange.rb
@@ -23,8 +23,10 @@ module Blink
def forward
Blink.notice "moving change forward"
if @state.noop
+ Blink.notice "%s is noop" % @state
Blink.notice "change noop is %s" % @state.noop
else
+ Blink.notice "Calling sync on %s" % @state
@state.sync
end
end
@@ -45,7 +47,7 @@ module Blink
#---------------------------------------------------------------
def to_s
- return "%s: %s => %s" % [@path,@is,@should]
+ return "%s: %s => %s" % [@state,@is,@should]
end
#---------------------------------------------------------------
end
diff --git a/lib/blink/type.rb b/lib/blink/type.rb
index 364e0da24..7ca72c5c1 100644
--- a/lib/blink/type.rb
+++ b/lib/blink/type.rb
@@ -91,15 +91,17 @@ class Blink::Type < Blink::Element
#---------------------------------------------------------------
#---------------------------------------------------------------
- def noop(ary)
- Blink[:noop] = ary.shift
- end
+ # ill thought-out
+ # this needs to return @noop
+ #def noop(ary)
+ # Blink[:noop] = ary.shift
+ #end
#---------------------------------------------------------------
#---------------------------------------------------------------
- def debug(ary)
- Blink[:debug] = ary.shift
- end
+ #def debug(ary)
+ # Blink[:debug] = ary.shift
+ #end
#---------------------------------------------------------------
#---------------------------------------------------------------
diff --git a/test/client/tc_client.rb b/test/client/tc_client.rb
index 54da3dc6a..9a78147fa 100644
--- a/test/client/tc_client.rb
+++ b/test/client/tc_client.rb
@@ -16,14 +16,14 @@ class TestClient < Test::Unit::TestCase
def test_local
client = nil
assert_nothing_raised() {
- client = Blink::Client::Local.new()
+ client = Blink::Client.new(:Local => true)
}
facts = %w{operatingsystem operatingsystemrelease}
facts.each { |fact|
assert_equal(
Blink::Fact[fact],
- client.callfunc("retrieve",fact)
+ client.callfunc("fact",fact)
)
}
end