Connections¶
Module for connections to GVM server daemons like gvmd and ospd.
-
class
gvm.connections.
GvmConnection
(timeout=60)¶ Base class for establishing a connection to a remote server daemon.
- Parameters
timeout (
Optional
[int
,None
]) – Timeout in seconds for the connection. None to wait indefinitely
-
connect
()¶ Establish a connection to a remote server
-
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 (
Union
[bytes
,str
]) – Data to be send to the server. Either utf-8 encoded string or bytes.
-
class
gvm.connections.
SSHConnection
(*, timeout=60, hostname='127.0.0.1', port=22, username='gmp', password='')¶ SSH Class to connect, read and write from GVM via SSH
- Parameters
timeout (
Optional
[int
,None
]) – Timeout in seconds for the connection.hostname (
Optional
[str
,None
]) – DNS name or IP address of the remote server. Default is 127.0.0.1.port (
Optional
[int
,None
]) – Port of the remote SSH server. Default is port 22.username (
Optional
[str
,None
]) – Username to use for SSH login. Default is “gmp”.password (
Optional
[str
,None
]) – Passwort to use for SSH login. Default is “”.
-
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 (
Union
[bytes
,str
]) – Data to be send to the server. Either utf-8 encoded string or bytes.
-
class
gvm.connections.
TLSConnection
(*, certfile=None, cafile=None, keyfile=None, hostname='127.0.0.1', port=9390, password=None, timeout=60)¶ TLS class to connect, read and write from a remote GVM daemon via TLS secured socket.
- Parameters
timeout (
Optional
[int
,None
]) – Timeout in seconds for the connection.hostname (
Optional
[str
,None
]) – DNS name or IP address of the remote TLS server.port (
Optional
[int
,None
]) – Port for the TLS connection. Default is 9390.certfile (
Optional
[str
,None
]) – Path to PEM encoded certificate file. See python certificates for details.cafile (
Optional
[str
,None
]) – Path to PEM encoded CA file. See python certificates for details.keyfile (
Optional
[str
,None
]) – Path to PEM encoded private key. See python certificates for details.password (
Optional
[str
,None
]) – 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.
-
connect
()¶ Establish a connection to a remote server
-
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 (
Union
[bytes
,str
]) – Data to be send to the server. Either utf-8 encoded string or bytes.
-
class
gvm.connections.
UnixSocketConnection
(*, path='/var/run/gvm/gvmd.sock', timeout=60)¶ UNIX-Socket class to connect, read, write from a GVM server daemon via direct communicating UNIX-Socket
- Parameters
path (
Optional
[str
,None
]) – Path to the socket. Default is “/var/run/gvm/gvmd.sock”.timeout (
Optional
[int
,None
]) – Timeout in seconds for the connection. Default is 60 seconds.
-
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 (
Union
[bytes
,str
]) – Data to be send to the server. Either utf-8 encoded string or bytes.
-
class
gvm.connections.
DebugConnection
(connection)¶ 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) socketconnection = UnixSocketConnection(path='/var/run/gvm/gvm.sock') connection = DebugConnection(socketconnection) gmp = Gmp(connection=connection)
- Parameters
connection (
GvmConnection
) – GvmConnection to observe