Connections

Module for connections to GVM server daemons like gvmd and ospd.

class gvm.connections.GvmConnection
__init__(*args, **kwargs)
class gvm.connections.SSHConnection

SSH Class to connect, read and write from GVM via SSH

Parameters:
  • timeout – Timeout in seconds for the connection.

  • hostname – DNS name or IP address of the remote server. Default is 127.0.0.1.

  • port – Port of the remote SSH server. Default is port 22.

  • username – Username to use for SSH login. Default is “gmp”.

  • password – Password to use for SSH login. Default is “”.

__init__(*, timeout=60, hostname='127.0.0.1', port=22, username='gmp', password='', known_hosts_file=None, auto_accept_host=None)
connect()

Connect to the SSH server and authenticate to it

disconnect()

Disconnect and close the connection to the remote server

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns:

data as utf-8 encoded string

Return type:

str

send(data)

Send data to the connected remote server

Parameters:

data (str | bytes) – Data to be send to the server. Either utf-8 encoded string or bytes.

class gvm.connections.TLSConnection

TLS class to connect, read and write from a remote GVM daemon via TLS secured socket.

Parameters:
  • timeout – Timeout in seconds for the connection.

  • hostname – DNS name or IP address of the remote TLS server.

  • port – Port for the TLS connection. Default is 9390.

  • certfile – Path to PEM encoded certificate file. See python certificates for details.

  • cafile – Path to PEM encoded CA file. See python certificates for details.

  • keyfile – Path to PEM encoded private key. See python certificates for details.

  • password – Password for the private key. If the password argument is not specified and a password is required it will be interactively prompt the user for a password.

__init__(*, certfile=None, cafile=None, keyfile=None, hostname='127.0.0.1', port=9390, password=None, timeout=60)
connect()

Establish a connection to a remote server

disconnect()

Close the SSL layer then disconnect from the remote server

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns:

data as utf-8 encoded string

Return type:

str

send(data)

Send data to the connected remote server

Parameters:

data (str | bytes) – Data to be send to the server. Either utf-8 encoded string or bytes.

class gvm.connections.UnixSocketConnection

UNIX-Socket class to connect, read, write from a daemon via direct communicating UNIX-Socket

Parameters:
  • path – Path to the socket. Default is “/run/gvmd/gvmd.sock”.

  • timeout – Timeout in seconds for the connection. Default is 60 seconds.

__init__(*, path='/run/gvmd/gvmd.sock', timeout=60)
connect()

Connect to the UNIX socket

disconnect()

Disconnect and close the connection to the remote server

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns:

data as utf-8 encoded string

Return type:

str

send(data)

Send data to the connected remote server

Parameters:

data (str | bytes) – Data to be send to the server. Either utf-8 encoded string or bytes.

class gvm.connections.DebugConnection

Wrapper around a connection for debugging purposes

Allows to debug the connection flow including send and read data. Internally it uses the python logging framework to create debug messages. Please take a look at the logging tutorial for further details.

Usage example:

import logging

logging.basicConfig(level=logging.DEBUG)

socket_connection = UnixSocketConnection(path='/var/run/gvm.sock')
connection = DebugConnection(socket_connection)
gmp = Gmp(connection=connection)
Parameters:

connection – GvmConnection to observe

__init__(connection)