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

bconsole.py « bin - github.com/bareos/python-bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 64afb48dca21bd0dcd52156b4ca28b48edf4d086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python

from __future__ import print_function
import argparse
#import bareos
import bareos.bsock
import logging
import sys

def getArguments():
    parser = argparse.ArgumentParser(description='Console to Bareos Director.' )
    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

if __name__ == '__main__':
    logging.basicConfig(format='%(levelname)s %(module)s.%(funcName)s: %(message)s', level=logging.INFO)
    logger = logging.getLogger()

    args=getArguments()
    if args.debug:
        logger.setLevel(logging.DEBUG)

    try:
        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.DirectorConsole(**parameter)
    except RuntimeError as e:
        print(str(e))
        sys.exit(1)
    logger.debug( "authentication successful" )
    director.interactive()