Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/python-bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Steffens <joerg.steffens@bareos.com>2016-08-02 12:58:49 +0300
committerJoerg Steffens <joerg.steffens@bareos.com>2016-08-02 12:58:49 +0300
commita3b755aa94cc3b54069d30d48d874bb89c014c2d (patch)
tree6403ec60df04d2875ed48efcd3bf7a2c3ada32ba
parent462627048c9674f26c1232cb4349c9afb8feb5fb (diff)
jsonrpc cleanup
-rwxr-xr-xbin/bareos-jsonrpc-server.py51
-rwxr-xr-xbin/jsonrpc-test.py24
2 files changed, 57 insertions, 18 deletions
diff --git a/bin/bareos-jsonrpc-server.py b/bin/bareos-jsonrpc-server.py
index 7e84ce3..ffc1249 100755
--- a/bin/bareos-jsonrpc-server.py
+++ b/bin/bareos-jsonrpc-server.py
@@ -20,20 +20,47 @@ class RequestHandler(pyjsonrpc.HttpRequestHandler):
}
class BconsoleMethods:
- def __init__(self, bconsole ):
- self.logger = logging.getLogger()
- self.logger.debug("init")
- self.conn = bconsole
-
- def call( self, command ):
- self.logger.debug( command )
- return self.conn.call_fullresult( command )
-
-def bconsole_methods_to_jsonrpc( bconsole_methods ):
- tuples = inspect.getmembers( bconsole_methods, predicate=inspect.ismethod )
+ def __init__(self, bconsole):
+ self.logger = logging.getLogger()
+ self.logger.debug("init")
+ self.conn = bconsole
+
+ def execute(self, command):
+ """
+ Generic function to call any bareos console command.
+ """
+ self.logger.debug(command)
+ return self.conn.call(command)
+
+ def execute_fullresult(self, command):
+ """
+ Generic function to call any bareos console commands,
+ and return the full result (also the pseudo jsonrpc header, not required here).
+ """
+ self.logger.debug(command)
+ return self.conn.call_fullresult(command)
+
+ def list(self, command):
+ """
+ Interface to the Bareos console list command.
+ """
+ return self.execute("list " + command)
+
+ def call(self, command):
+ """
+ legacy function, as call is a suboptimal name.
+ It is used internally by python-jsonrpc.
+ Use execute() instead.
+ """
+ return self.execute(command)
+
+
+
+def bconsole_methods_to_jsonrpc(bconsole_methods):
+ tuples = inspect.getmembers(bconsole_methods, predicate=inspect.ismethod)
methods = RequestHandler.methods
for i in tuples:
- methods[i[0]] = getattr( bconsole_methods, i[0] )
+ methods[i[0]] = getattr(bconsole_methods, i[0])
print i[0]
print methods
RequestHandler.methods=methods
diff --git a/bin/jsonrpc-test.py b/bin/jsonrpc-test.py
index eced702..9cd660b 100755
--- a/bin/jsonrpc-test.py
+++ b/bin/jsonrpc-test.py
@@ -19,10 +19,22 @@ http_client = pyjsonrpc.HttpClient(
# It is also possible to use the *method* name as *attribute* name.
#print http_client.add(1, 2)
-result = http_client.call( "call", "list jobs last" )
-try:
- pprint(result['result'])
-except:
- pprint( result )
-
+# provoke an error
#print http_client.add(2,"abc")
+
+
+result = http_client.execute_fullresult("list jobs last")
+pprint(result)
+
+result = http_client.execute("list jobs last")
+pprint(result)
+
+result = http_client.list("jobs last")
+pprint(result)
+
+
+#try:
+ #pprint(result['result'])
+#except:
+ #pprint( result )
+