opsicommon.client package

Submodules

opsicommon.client.jsonrpc module

This file is part of opsi - https://www.opsi.org

class opsicommon.client.jsonrpc.JSONRPCClient(address, **kwargs)

Bases: object

Parameters:
  • address (str)

  • kwargs (Any)

backend_getInterface()
Return type:

Optional[List[Dict[str, Any]]]

connect()
Return type:

None

disconnect()
Return type:

None

execute_rpc(method, params=None)
Parameters:
  • method (str)

  • params (Union[List, Dict[str, Any], None])

Return type:

Any

get(path, headers=None)
Parameters:
  • path (str)

  • headers (Optional[Dict[str, str]])

Return type:

Response

getInterface()
Return type:

Optional[List[Dict[str, Any]]]

property hostname: str
property interface: List[Dict[str, Any]] | None
property new_host_id: str | None
property new_host_key: str | None
no_proxy_addresses = ['localhost', '127.0.0.1', 'ip6-localhost', '::1']
property serialization: str
property serverName: str | None
property serverVersion: List[int] | None
property server_version: List[int] | None
property session: Session
property session_id: str | None
setCompression(compression)
Parameters:

compression (Union[bool, str])

Return type:

None

set_compression(compression)
Parameters:

compression (Union[bool, str])

Return type:

None

class opsicommon.client.jsonrpc.TimeoutHTTPAdapter(*args, **kwargs)

Bases: HTTPAdapter

Parameters:
  • args (Any)

  • kwargs (Any)

send(request, stream=False, timeout=None, verify=True, cert=None, proxies=None)

Sends PreparedRequest object. Returns Response object.

Parameters:
  • request (PreparedRequest) – The PreparedRequest being sent.

  • stream (bool) – (optional) Whether to stream the request content.

  • timeout (float or tuple or urllib3 Timeout object) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.

  • verify (Union[bool, str]) – (optional) Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use

  • cert (Union[None, bytes, str, Tuple[Union[bytes, str], Union[bytes, str]]]) – (optional) Any user-provided SSL certificate to be trusted.

  • proxies (Optional[Mapping[str, str]]) – (optional) The proxies dictionary to apply to the request.

Return type:

requests.Response

opsicommon.client.jsonrpc.no_export(func)
Parameters:

func (Callable)

Return type:

Callable

opsicommon.client.opsiservice module

This file is part of opsi - https://www.opsi.org

class opsicommon.client.opsiservice.BackendManager(username=None, password=None, **kwargs)

Bases: ServiceClient

For backwards compatibility

Parameters:
  • username (str | None)

  • password (str | None)

  • kwargs (Any)

class opsicommon.client.opsiservice.CallbackThread(callback, **kwargs)

Bases: Thread

Parameters:
  • callback (Callable)

  • kwargs (Any)

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

Return type:

None

class opsicommon.client.opsiservice.KeyPasswordHTTPAdapter(key_password)

Bases: HTTPAdapter

Parameters:

key_password (str | None)

init_poolmanager(*args, **kwargs)

Initializes a urllib3 PoolManager.

This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • connections – The number of urllib3 connection pools to cache.

  • maxsize – The maximum number of connections to save in the pool.

  • block – Block when no free connections are available.

  • pool_kwargs – Extra keyword arguments used to initialize the Pool Manager.

  • args (Any)

  • kwargs (Any)

Return type:

None

class opsicommon.client.opsiservice.Messagebus(opsi_service_client)

Bases: Thread

Parameters:

opsi_service_client (ServiceClient)

async async_send_message(message)
Parameters:

message (Message)

Return type:

None

connect(wait=True)
Parameters:

wait (bool)

Return type:

None

property connected: bool
disconnect(wait=True)
Parameters:

wait (bool)

Return type:

None

jsonrpc(method, params=None, return_result_only=True)
Parameters:
  • method (str)

  • params (tuple[Any, ...] | list[Any] | None)

  • return_result_only (bool)

Return type:

Any

register_messagebus_listener(listener)
Parameters:

listener (MessagebusListener)

Return type:

None

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

Return type:

None

send_message(message)
Parameters:

message (Message)

Return type:

None

stop()
Return type:

None

unregister_messagebus_listener(listener)
Parameters:

listener (MessagebusListener)

Return type:

None

wait_for_jsonrpc_response_message(rpc_id, timeout=None)
Parameters:
  • rpc_id (str | int)

  • timeout (float | None)

Return type:

JSONRPCResponseMessage

property websocket_connected: bool
class opsicommon.client.opsiservice.MessagebusListener(messagebus=None, message_types=None)

Bases: ABC

Parameters:
expired_message_received(message)

Called when a expired message is received. Expired messages should not be processed!

Parameters:

message (Message)

Return type:

None

message_received(message)

Called when a valid message is received.

Parameters:

message (Message)

Return type:

None

messagebus_connection_closed(messagebus)

Called when the connection to the messagebus is closed.

Parameters:

messagebus (Messagebus)

Return type:

None

messagebus_connection_established(messagebus)

Called when the connection to the messagebus is established.

Parameters:

messagebus (Messagebus)

Return type:

None

messagebus_connection_failed(messagebus, exception)

Called when a connection to the messagebus failed.

Parameters:
Return type:

None

messagebus_connection_open(messagebus)

Called when the connection to the messagebus is opened.

Parameters:

messagebus (Messagebus)

Return type:

None

register(messagebus)

Context manager for register this listener on and off the message bus.

Parameters:

messagebus (Messagebus)

Return type:

Generator[None, None, None]

class opsicommon.client.opsiservice.OpsiCaState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

AVAILABLE = 'available'
EXPIRED = 'expired'
UNAVAILABLE = 'unavailable'
class opsicommon.client.opsiservice.Response(status_code, reason, headers, content)

Bases: object

Parameters:
  • status_code (int)

  • reason (str)

  • headers (CaseInsensitiveDict)

  • content (bytes)

content: bytes
headers: CaseInsensitiveDict
reason: str
status_code: int
class opsicommon.client.opsiservice.ServiceClient(address=None, *, username=None, password=None, client_cert_file=None, client_key_file=None, client_key_password=None, ca_cert_file=None, verify=ServiceVerificationFlags.STRICT_CHECK, session_cookie=None, session_lifetime=150, proxy_url='system', user_agent=None, connect_timeout=10.0, max_time_diff=0.0, jsonrpc_create_objects=False, jsonrpc_create_methods=False)

Bases: object

Parameters:
  • address (Union[Iterable[str], str, None])

  • username (str | None)

  • password (str | None)

  • client_cert_file (str | Path | None)

  • client_key_file (str | Path | None)

  • client_key_password (str | None)

  • ca_cert_file (str | Path | None)

  • verify (Union[str, Iterable[str]])

  • session_cookie (str | None)

  • session_lifetime (int)

  • proxy_url (str | None)

  • user_agent (str | None)

  • connect_timeout (float)

  • max_time_diff (float)

  • jsonrpc_create_objects (bool)

  • jsonrpc_create_methods (bool)

add_uib_opsi_ca_to_cert_file()
Return type:

None

property addresses: Iterable[str] | str | None
property base_url: str
property ca_cert_file: Path | None
certs_from_pem(pem_data)
Parameters:

pem_data (str)

Return type:

list[Certificate]

property client_cert_file: Path | None
property client_key_file: Path | None
property client_key_password: str | None
connect()
Return type:

None

connect_messagebus()
Return type:

Messagebus

property connected: bool
connection(connect_messagebus=False)
Parameters:

connect_messagebus (bool)

Return type:

Generator[None, None, None]

create_jsonrpc_methods(instance=None)
Parameters:

instance (Any)

Return type:

None

disconnect()
Return type:

None

disconnect_messagebus()
Return type:

None

fetch_opsi_ca(skip_verify=False)
Parameters:

skip_verify (bool)

Return type:

None

get(path, *, headers=None, connect_timeout=None, read_timeout=None, allow_status_codes=None, raw_response=False)
Parameters:
  • path (str)

  • headers (dict[str, str] | None)

  • connect_timeout (float | None)

  • read_timeout (float | None)

  • allow_status_codes (Optional[Iterable[int]])

  • raw_response (bool)

Return type:

Response | Response

get_opsi_ca_certs()
Return type:

list[Certificate]

get_opsi_ca_state()
Return type:

OpsiCaState

jsonrpc(method, params=None, *, connect_timeout=None, read_timeout=None, return_result_only=True, create_objects=None)
Parameters:
  • method (str)

  • params (tuple[Any, ...] | list[Any] | dict[str, Any] | None)

  • connect_timeout (float | None)

  • read_timeout (float | None)

  • return_result_only (bool)

  • create_objects (bool | None)

Return type:

Any

property messagebus: Messagebus
property messagebus_available: bool
property messagebus_connected: bool
no_proxy_addresses = ['localhost', '127.0.0.1', 'ip6-localhost', '::1']
property password: str | None
post(path, data=None, *, headers=None, connect_timeout=None, read_timeout=None, allow_status_codes=None, raw_response=False)
Parameters:
  • path (str)

  • data (bytes | None)

  • headers (dict[str, str] | None)

  • connect_timeout (float | None)

  • read_timeout (float | None)

  • allow_status_codes (Optional[Iterable[int]])

  • raw_response (bool)

Return type:

Response | Response

property proxy_url: str | None
read_ca_cert_file()
Return type:

list[Certificate]

register_connection_listener(listener)
Parameters:

listener (ServiceConnectionListener)

Return type:

None

request(method, path, *, headers=None, connect_timeout=None, read_timeout=None, data=None, allow_status_codes=None, raw_response=False)
Parameters:
  • method (str)

  • path (str)

  • headers (dict[str, str] | None)

  • connect_timeout (float | None)

  • read_timeout (float | None)

  • data (bytes | None)

  • allow_status_codes (Optional[Iterable[int]])

  • raw_response (bool)

Return type:

Response | Response

service_is_opsiclientd()
Return type:

bool

set_addresses(address)
Parameters:

address (Union[Iterable[str], str, None])

Return type:

None

stop()
Return type:

None

unregister_connection_listener(listener)
Parameters:

listener (ServiceConnectionListener)

Return type:

None

property username: str | None
property verify: list[ServiceVerificationFlags]
write_ca_cert_file(certs)
Parameters:

certs (list[Certificate])

Return type:

None

class opsicommon.client.opsiservice.ServiceConnectionListener

Bases: ABC

connection_closed(service_client)

Called when the connection to the service is close.

Parameters:

service_client (ServiceClient)

Return type:

None

connection_established(service_client)

Called when the connection to the service is established.

Parameters:

service_client (ServiceClient)

Return type:

None

connection_failed(service_client, exception)

Called when a connection to the service failed.

Parameters:
Return type:

None

connection_open(service_client)

Called when the connection to the service is opened.

Parameters:

service_client (ServiceClient)

Return type:

None

register(service_client)

Context manager for register this listener on and off the message bus.

Parameters:

service_client (ServiceClient)

Return type:

Generator[None, None, None]

class opsicommon.client.opsiservice.ServiceVerificationFlags(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

ACCEPT_ALL = 'accept_all'
OPSI_CA = 'opsi_ca'
REPLACE_EXPIRED_CA = 'replace_expired_ca'
STRICT_CHECK = 'strict_check'
UIB_OPSI_CA = 'uib_opsi_ca'
opsicommon.client.opsiservice.get_service_client(*, address=None, username=None, password=None, user_agent=None)
Parameters:
  • address (str | None)

  • username (str | None)

  • password (str | None)

  • user_agent (str | None)

Return type:

ServiceClient

Module contents

This file is part of opsi - https://www.opsi.org