bareos.bsock.directorconsole.DirectorConsole

class bareos.bsock.directorconsole.DirectorConsole(address='localhost', port=9101, timeout=None, dirname=None, name='*UserAgent*', password=None, protocolversion=None, pam_username=None, pam_password=None, tls_psk_enable=True, tls_psk_require=False, tls_version=None)[source]

Bases: LowLevel

Send and receive the response to Bareos Director Daemon Console interface.

Example

>>> import bareos.bsock
>>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user1', password='secret')
>>> print(directorconsole.call('help').decode("utf-8"))
Parameters:
  • address (str) – Address of the Bareos Director (hostname or IP).

  • port (int) – Port number of the Bareos Director.

  • timeout (int, optional) – Timeout for the connection to the director. Default: OS dependent

  • dirname (str, optional) – Name of the Bareos Director. Deprecated, normally not required.

  • name (str, optional) – Name of the Director Console. Leave empty when connecting to the Bareos Default Console.

  • password (str, bareos.util.Password) – Password, in cleartext or as Password object.

  • protocolversion (None, bareos.bsock.ProtocolVersions.last, bareos.bsock.ProtocolVersions.bareos_12_4, bareos.bsock.ProtocolVersions.bareos_18_2) – Specify the Bareos Console protocol version to use.

  • pam_username (str) – Additional username when using PAM.

  • pam_password (str) – Additional user password when using PAM.

  • tls_psk_enable (boolean) – Enable TLS-PSK.

  • tls_psk_require (boolean) – Enforce using TLS-PSK.

  • tls_version (None, ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2) – TLS protocol version to use.

Raises:

bareos.exceptions.ConnectionError – On connections errors.

Methods

argparser_add_default_command_line_arguments

Extend argparser with DirectorConsole specific parameter.

argparser_get_bareos_parameter

Extract arguments.

auth

Login to a Bareos Daemon.

call

Call a Bareos command.

close

Close the connection.

connect

Establish a network connection and authenticate.

get_cipher

If a encrypted connection is used, returns information about the encryption.

get_protocol_version

Get the Bareos Console protocol version that is used.

get_tls_psk_identity

Bareos TLS-PSK excepts the identiy is a specific format.

has_data

Is readable data available?

interactive

Enter the interactive mode.

is_connected

Verifes that last status still indicates connected.

is_end_of_message

Checks if a Bareos signal indicates the end of a message.

is_tls_psk_available

Checks if we have all required modules for TLS-PSK.

receive_and_evaluate_response_message

Retrieve a message and evaluate it.

reconnect

Tries to reconnect.

recv

Receive a single message.

recv_bytes

Receive a number of bytes.

recv_msg

Receive a full message.

recv_submsg

Retrieve a message of the specific length.

send

Send message to the Daemon.

send_command

Alias for call().

static argparser_add_default_command_line_arguments(argparser)[source]

Extend argparser with DirectorConsole specific parameter.

Every command line program must offer a similar set of parameter to connect to a Bareos Director. This method adds the required parameter to an existing ArgParser instance. Parameter required to initialize a DirectorConsole class are stored in variables prefixed with BAREOS_.

Use bareos.bsock.lowlevel.LowLevel.argparser_get_bareos_parameter() to retrieve the relevant parameter (with the BAREOS_ prefix removed).

Example

>>> argparser = argparse.ArgumentParser(description="Console to Bareos Director.")
>>> DirectorConsole.argparser_add_default_command_line_arguments(argparser)
>>> args = argparser.parse_args()
>>> bareos_args = DirectorConsole.argparser_get_bareos_parameter(args)
>>> director = DirectorConsole(**bareos_args)
Parameters:

argparser (ArgParser or ConfigArgParser) – (Config)ArgParser instance.

static argparser_get_bareos_parameter(args)

Extract arguments.

This method is usually used together with the method argparser_add_default_command_line_arguments().

Parameters:

args (ArgParser.Namespace) – Arguments retrieved by ArgumentParser.parse_args().

Returns:

The relevant parameter from args to initialize a connection.

Return type:

dict

auth()

Login to a Bareos Daemon.

Returns:

True, if the authentication succeeds. In earlier versions, authentication failures returned False. However, now an authentication failure raises an exception.

Return type:

bool

Raises:

bareos.exceptions.AuthenticationError – if authentication fails.

call(command)

Call a Bareos command.

Parameters:

command (str or list) – Command to execute. Best provided as a list.

Returns:

Result received from the Daemon.

Return type:

bytes

close()

Close the connection.

connect(address, port, dirname, connection_type, name=None, password=None, timeout=None)

Establish a network connection and authenticate.

Parameters:
  • address (str) – Address of the Bareos Director (hostname or IP).

  • port (int) – Port number of the Bareos Director.

  • dirname (str, optional) – Name of the Bareos Director. Deprecated, normally not required.

  • connection_type (int) – See bareos.bsock.connectiontype.ConnectionType.

  • name (str, optional) – Credential name.

  • password (str, bareos.util.Password) – Credential password, in cleartext or as Password object.

  • timeout (int, optional) – Connection timeout in seconds. Default OS specific.

Returns:

True, if the authentication succeeds. In earlier versions, authentication failures returned False. However, now an authentication failure raises an exception.

Return type:

bool

Raises:
get_cipher()

If a encrypted connection is used, returns information about the encryption. Else it returns None.

Returns:

Returns a three-value tuple containing the name of the cipher being used, the version of the SSL protocol that defines its use, and the number of secret bits being used. If the connection is unencrypted or has been established, returns None.

Return type:

tuple or None

get_protocol_version()

Get the Bareos Console protocol version that is used.

Returns:

Number that represents the Bareos Console protocol version (see bareos.bsock.protocolversions.ProtocolVersions.)

Return type:

int

get_tls_psk_identity()

Bareos TLS-PSK excepts the identiy is a specific format.

has_data()

Is readable data available?

Returns:

True: if readable data is available.

Return type:

bool

interactive()

Enter the interactive mode.

Exit via typing “exit” or “quit”.

Returns:

True, if exited by user command.

Return type:

bool

is_connected()

Verifes that last status still indicates connected.

Returns:

True, if still connected.

Return type:

bool

is_end_of_message(data)

Checks if a Bareos signal indicates the end of a message.

Parameters:

data (int) – Negative integer.

Returns:

True, if regular end of message is reached.

Return type:

bool

static is_tls_psk_available()

Checks if we have all required modules for TLS-PSK.

receive_and_evaluate_response_message()

Retrieve a message and evaluate it.

Only used during in the authentication phase.

Returns:

(code, text).

Return type:

2-tuple

reconnect()

Tries to reconnect.

Returns:

True, if the connection could be reestablished.

Return type:

bool

recv()

Receive a single message.

This is, header (4 bytes): if

  • > 0: length of the following message

  • < 0: Bareos signal

Returns:

Message retrieved via the connection.

Return type:

bytearray

Raises:

bareos.exceptions.SignalReceivedException – If a Bareos signal is received.

recv_bytes(length, timeout=10)

Receive a number of bytes.

Parameters:
  • length (int) – Number of bytes to receive.

  • timeout (float) – Timeout in seconds.

Raises:
recv_msg(regex=b'^\\d\\d\\d\\d OK.*$')

Receive a full message.

It retrieves messages (header + message text), until

  1. the message contains the specified regex or

  2. the header indicates a signal.

Parameters:

regex (bytes) – Descripes the expected end of the message.

Returns:

Message retrieved via the connection.

Return type:

bytearray

Raises:

bareos.exceptions.SignalReceivedException – If a Bareos signal is received.

recv_submsg(length)

Retrieve a message of the specific length.

Parameters:

length (int) – Number of bytes to retrieve.

Returns:

Retrieved message.

Return type:

bytearray

send(msg=None)

Send message to the Daemon.

Parameters:

msg (bytearray) – Message to send.

send_command(command)

Alias for call().

Deprecated:

15.2.0