Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial support to communicate with bareos-fd
- Loading branch information
1 parent
8492cd8
commit a92ba26
Showing
8 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#__all__ = [ "bconsole" ] | ||
from bareos.exceptions import * | ||
from bareos.util.password import Password | ||
from bareos.bsock.bsock import BSock | ||
from bareos.bsock.bsockjson import BSockJson | ||
from bareos.exceptions import * | ||
from bareos.util.password import Password | ||
from bareos.bsock.connectiontype import ConnectionType | ||
from bareos.bsock.bsock import BSock | ||
from bareos.bsock.bsockjson import BSockJson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ConnectionType: | ||
""" | ||
""" | ||
DIRECTOR = 1001 | ||
STORAGE = 1002 | ||
FILEDAEMON = 1003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Communicates with the bareos-fd | ||
""" | ||
|
||
from bareos.bsock.connectiontype import ConnectionType | ||
from bareos.bsock import BSock | ||
|
||
class FileDaemon(BSock): | ||
'''use to send and receive the response to Bareos File Daemon''' | ||
|
||
def __init__(self, | ||
address="localhost", | ||
port=9102, | ||
dirname=None, | ||
name=None, | ||
password=None, | ||
type=ConnectionType.FILEDAEMON): | ||
super(FileDaemon, self).__init__(address, port, dirname, name, password, type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/python | ||
|
||
import argparse | ||
import bareos.bsock | ||
from bareos.bsock.filedaemon import FileDaemon | ||
import logging | ||
import sys | ||
|
||
def getArguments(): | ||
parser = argparse.ArgumentParser(description='Connect to Bareos File Daemon.' ) | ||
parser.add_argument('-d', '--debug', action='store_true', help="enable debugging output") | ||
parser.add_argument('--name', help="Name of the Director resource in the File Daemon", required=True) | ||
parser.add_argument('-p', '--password', help="password to authenticate to a Bareos File Daemon", required=True) | ||
parser.add_argument('--port', default=9102, help="Bareos File Daemon network port") | ||
parser.add_argument('address', nargs='?', default="localhost", help="Bareos File Daemon network address") | ||
parser.add_argument('command', nargs='?', help="Command to send to the Bareos File Daemon") | ||
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', '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 | ||
bsock=FileDaemon(**parameter) | ||
except RuntimeError as e: | ||
print str(e) | ||
sys.exit(1) | ||
logger.debug( "authentication successful" ) | ||
if args.command: | ||
print bsock.call(args.command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters