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-01 17:26:25 +0300
committerJoerg Steffens <joerg.steffens@bareos.com>2016-08-01 17:26:25 +0300
commit462627048c9674f26c1232cb4349c9afb8feb5fb (patch)
tree0691cbf17a87e66c2e2215a54c5286f2fd50d486
parent65afa32e4497c989a3807641c088c59ad1ed8fb8 (diff)
fixes PoC json-rpc server
-rwxr-xr-xbin/bareos-jsonrpc-server.py42
-rwxr-xr-xbin/jsonrpc-test.py4
2 files changed, 25 insertions, 21 deletions
diff --git a/bin/bareos-jsonrpc-server.py b/bin/bareos-jsonrpc-server.py
index aa5c078..7e84ce3 100755
--- a/bin/bareos-jsonrpc-server.py
+++ b/bin/bareos-jsonrpc-server.py
@@ -1,9 +1,10 @@
#!/usr/bin/python
import argparse
-import bareos
+import bareos.bsock
import inspect
import logging
+# pip install python-jsonrpc
import pyjsonrpc
import sys
from types import MethodType
@@ -26,11 +27,7 @@ class BconsoleMethods:
def call( self, command ):
self.logger.debug( command )
- raw=self.conn.call( command )
- result = {
- 'raw': raw
- }
- return result
+ return self.conn.call_fullresult( command )
def bconsole_methods_to_jsonrpc( bconsole_methods ):
tuples = inspect.getmembers( bconsole_methods, predicate=inspect.ismethod )
@@ -44,10 +41,12 @@ def bconsole_methods_to_jsonrpc( bconsole_methods ):
def getArguments():
parser = argparse.ArgumentParser(description='Run Bareos Director JSON-RPC proxy.' )
- parser.add_argument( '-d', '--debug', action='store_true', help="enable debugging output" )
- parser.add_argument( '-p', '--password', help="password to authenticate at Bareos Director" )
- parser.add_argument( 'host', default="localhost", help="Bareos Director host" )
- parser.add_argument( 'dirname', nargs='?', default=None, help="Bareos Director name" )
+ parser.add_argument('-d', '--debug', action='store_true', help="enable debugging output")
+ parser.add_argument('--name', default="*UserAgent*", help="use this to access a specific Bareos director named console. Otherwise it connects to the default console (\"*UserAgent*\")")
+ parser.add_argument('-p', '--password', help="password to authenticate to a Bareos Director console", required=True)
+ parser.add_argument('--port', default=9101, help="Bareos Director network port")
+ parser.add_argument('--dirname', help="Bareos Director name")
+ parser.add_argument('address', nargs='?', default="localhost", help="Bareos Director network address")
args = parser.parse_args()
return args
@@ -61,23 +60,28 @@ if __name__ == '__main__':
logger.setLevel(logging.DEBUG)
try:
- director = bareos.bconsole( host=args.host, dirname=args.dirname )
+ options = [ 'address', 'port', 'dirname', 'name' ]
+ parameter = {}
+ for i in options:
+ if hasattr(args, i) and getattr(args,i) != None:
+ logger.debug( "%s: %s" %(i, getattr(args,i)))
+ parameter[i] = getattr(args, i)
+ else:
+ logger.debug( '%s: ""' %(i))
+ logger.debug('options: %s' % (parameter))
+ password = bareos.bsock.Password(args.password)
+ parameter['password']=password
+ director = bareos.bsock.DirectorConsoleJson(**parameter)
except RuntimeError as e:
- print str(e)
- sys.exit(1)
- if not director.login( password=args.password ):
- print "failed to authenticate"
+ print(str(e))
sys.exit(1)
logger.debug( "authentication successful" )
- director.init()
- director.show_commands()
-
bconsole_methods = BconsoleMethods( director )
bconsole_methods_to_jsonrpc( bconsole_methods )
- print bconsole_methods.call( "status director" )
+ print bconsole_methods.call("list jobs last")
# Threading HTTP-Server
http_server = pyjsonrpc.ThreadingHttpServer(
diff --git a/bin/jsonrpc-test.py b/bin/jsonrpc-test.py
index 91ed205..eced702 100755
--- a/bin/jsonrpc-test.py
+++ b/bin/jsonrpc-test.py
@@ -19,9 +19,9 @@ 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", "status director" )
+result = http_client.call( "call", "list jobs last" )
try:
- print result['raw']
+ pprint(result['result'])
except:
pprint( result )