libvirtpy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libvirtpy/__init__.py +5 -0
- libvirtpy/client/__init__.py +54 -0
- libvirtpy/client/_bases.py +326 -0
- libvirtpy/client/_runner.py +57 -0
- libvirtpy/client/aio.py +5922 -0
- libvirtpy/client/client.py +5695 -0
- libvirtpy/client/operations/__init__.py +631 -0
- libvirtpy/client/operations/_common.py +495 -0
- libvirtpy/client/operations/checkpoint.py +196 -0
- libvirtpy/client/operations/connection.py +93 -0
- libvirtpy/client/operations/connection_extra.py +256 -0
- libvirtpy/client/operations/domain.py +306 -0
- libvirtpy/client/operations/domain_agent.py +115 -0
- libvirtpy/client/operations/domain_block.py +368 -0
- libvirtpy/client/operations/domain_info.py +400 -0
- libvirtpy/client/operations/domain_lifecycle.py +338 -0
- libvirtpy/client/operations/domain_migration.py +164 -0
- libvirtpy/client/operations/domain_network.py +113 -0
- libvirtpy/client/operations/domain_tuning.py +494 -0
- libvirtpy/client/operations/host.py +246 -0
- libvirtpy/client/operations/host_interface.py +100 -0
- libvirtpy/client/operations/interface_extra.py +45 -0
- libvirtpy/client/operations/network.py +135 -0
- libvirtpy/client/operations/network_info.py +155 -0
- libvirtpy/client/operations/network_port.py +142 -0
- libvirtpy/client/operations/node_device.py +76 -0
- libvirtpy/client/operations/node_device_info.py +189 -0
- libvirtpy/client/operations/nwfilter.py +67 -0
- libvirtpy/client/operations/nwfilter_binding.py +74 -0
- libvirtpy/client/operations/secret.py +93 -0
- libvirtpy/client/operations/secret_extra.py +24 -0
- libvirtpy/client/operations/snapshot.py +100 -0
- libvirtpy/client/operations/snapshot_tree.py +114 -0
- libvirtpy/client/operations/storage.py +267 -0
- libvirtpy/client/operations/storage_info.py +188 -0
- libvirtpy/client/operations/streams.py +201 -0
- libvirtpy/client/references.py +249 -0
- libvirtpy/client/subscribing.py +88 -0
- libvirtpy/client/testing/__init__.py +24 -0
- libvirtpy/client/testing/_common.py +167 -0
- libvirtpy/client/testing/_domains.py +294 -0
- libvirtpy/client/testing/_objects.py +205 -0
- libvirtpy/client/testing/_state.py +246 -0
- libvirtpy/client/testing/_storage.py +171 -0
- libvirtpy/client/testing/async_transport.py +30 -0
- libvirtpy/client/testing/fake.py +81 -0
- libvirtpy/client/transport.py +87 -0
- libvirtpy/client/types.py +59 -0
- libvirtpy/client/wire.py +436 -0
- libvirtpy/client/wire_aio.py +348 -0
- libvirtpy/errors.py +7 -0
- libvirtpy/py.typed +0 -0
- libvirtpy/rpc/__init__.py +1 -0
- libvirtpy/rpc/aio.py +387 -0
- libvirtpy/rpc/cpumap.py +48 -0
- libvirtpy/rpc/errors.py +186 -0
- libvirtpy/rpc/events.py +259 -0
- libvirtpy/rpc/options.py +66 -0
- libvirtpy/rpc/procedure.py +27 -0
- libvirtpy/rpc/protocol/__init__.py +0 -0
- libvirtpy/rpc/protocol/procedures.py +5163 -0
- libvirtpy/rpc/protocol/typed_hints.py +210 -0
- libvirtpy/rpc/protocol/types.py +9299 -0
- libvirtpy/rpc/remote.py +295 -0
- libvirtpy/rpc/remote_aio.py +106 -0
- libvirtpy/rpc/sasl.py +467 -0
- libvirtpy/rpc/session.py +424 -0
- libvirtpy/rpc/sockets.py +251 -0
- libvirtpy/rpc/stream.py +323 -0
- libvirtpy/rpc/subscription.py +451 -0
- libvirtpy/rpc/sync.py +460 -0
- libvirtpy/rpc/typed_params.py +97 -0
- libvirtpy/rpc/uri.py +85 -0
- libvirtpy/rpc/xdr.py +552 -0
- libvirtpy/xml/__init__.py +49 -0
- libvirtpy/xml/_base.py +145 -0
- libvirtpy/xml/_shared/__init__.py +1 -0
- libvirtpy/xml/_shared/metadata.py +67 -0
- libvirtpy/xml/_shared/network.py +108 -0
- libvirtpy/xml/_shared/storage.py +131 -0
- libvirtpy/xml/_shared/sysinfo.py +83 -0
- libvirtpy/xml/_types.py +197 -0
- libvirtpy/xml/_xml_element.py +134 -0
- libvirtpy/xml/backup/__init__.py +25 -0
- libvirtpy/xml/backup/backup.py +89 -0
- libvirtpy/xml/backup/checkpoint.py +48 -0
- libvirtpy/xml/capabilities/__init__.py +43 -0
- libvirtpy/xml/capabilities/domain.py +436 -0
- libvirtpy/xml/capabilities/host.py +413 -0
- libvirtpy/xml/capabilities/storagepool.py +59 -0
- libvirtpy/xml/domain/__init__.py +493 -0
- libvirtpy/xml/domain/blkiotune.py +81 -0
- libvirtpy/xml/domain/clock.py +79 -0
- libvirtpy/xml/domain/cpu.py +265 -0
- libvirtpy/xml/domain/devices/__init__.py +495 -0
- libvirtpy/xml/domain/devices/address.py +152 -0
- libvirtpy/xml/domain/devices/audio.py +204 -0
- libvirtpy/xml/domain/devices/chardev.py +197 -0
- libvirtpy/xml/domain/devices/common.py +75 -0
- libvirtpy/xml/domain/devices/controller.py +262 -0
- libvirtpy/xml/domain/devices/devices.py +79 -0
- libvirtpy/xml/domain/devices/disk.py +471 -0
- libvirtpy/xml/domain/devices/filesystem.py +206 -0
- libvirtpy/xml/domain/devices/graphics.py +245 -0
- libvirtpy/xml/domain/devices/hostdev.py +221 -0
- libvirtpy/xml/domain/devices/input.py +89 -0
- libvirtpy/xml/domain/devices/interface.py +459 -0
- libvirtpy/xml/domain/devices/iommu.py +54 -0
- libvirtpy/xml/domain/devices/memballoon.py +42 -0
- libvirtpy/xml/domain/devices/memory_device.py +101 -0
- libvirtpy/xml/domain/devices/misc.py +169 -0
- libvirtpy/xml/domain/devices/nvram.py +20 -0
- libvirtpy/xml/domain/devices/shmem.py +46 -0
- libvirtpy/xml/domain/devices/sound.py +42 -0
- libvirtpy/xml/domain/devices/tpm.py +103 -0
- libvirtpy/xml/domain/devices/usb.py +86 -0
- libvirtpy/xml/domain/devices/video.py +101 -0
- libvirtpy/xml/domain/domain.py +157 -0
- libvirtpy/xml/domain/features.py +312 -0
- libvirtpy/xml/domain/iothread.py +41 -0
- libvirtpy/xml/domain/launch_security.py +82 -0
- libvirtpy/xml/domain/memory.py +149 -0
- libvirtpy/xml/domain/misc.py +113 -0
- libvirtpy/xml/domain/namespaces.py +96 -0
- libvirtpy/xml/domain/numa.py +140 -0
- libvirtpy/xml/domain/os.py +267 -0
- libvirtpy/xml/domain/qemu.py +102 -0
- libvirtpy/xml/domain/seclabel.py +29 -0
- libvirtpy/xml/domain/storage_source.py +466 -0
- libvirtpy/xml/domain/sysinfo.py +34 -0
- libvirtpy/xml/interface/__init__.py +17 -0
- libvirtpy/xml/interface/interface.py +153 -0
- libvirtpy/xml/network/__init__.py +101 -0
- libvirtpy/xml/network/network.py +311 -0
- libvirtpy/xml/network/port.py +84 -0
- libvirtpy/xml/nodedev/__init__.py +13 -0
- libvirtpy/xml/nodedev/nodedev.py +490 -0
- libvirtpy/xml/nwfilter/__init__.py +81 -0
- libvirtpy/xml/nwfilter/binding.py +51 -0
- libvirtpy/xml/nwfilter/filter.py +92 -0
- libvirtpy/xml/nwfilter/rules.py +534 -0
- libvirtpy/xml/secret/__init__.py +11 -0
- libvirtpy/xml/secret/secret.py +36 -0
- libvirtpy/xml/snapshot/__init__.py +29 -0
- libvirtpy/xml/snapshot/snapshot.py +136 -0
- libvirtpy/xml/storage/__init__.py +75 -0
- libvirtpy/xml/storage/pool.py +219 -0
- libvirtpy/xml/storage/volume.py +102 -0
- libvirtpy/xml/sysinfo.py +40 -0
- libvirtpy-0.1.0.dist-info/METADATA +109 -0
- libvirtpy-0.1.0.dist-info/RECORD +154 -0
- libvirtpy-0.1.0.dist-info/WHEEL +4 -0
- libvirtpy-0.1.0.dist-info/licenses/LICENSE +501 -0
- libvirtpy-0.1.0.dist-info/licenses/NOTICE +23 -0
libvirtpy/rpc/events.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"""Events: what the daemon tells you without being asked.
|
|
2
|
+
|
|
3
|
+
An event says that something happened to a domain, a network, a storage pool, a
|
|
4
|
+
host device or a secret: a domain started, a disk reported an error, a block job
|
|
5
|
+
finished. ``Event.data`` holds the generated message struct with every detail;
|
|
6
|
+
the common parts (what it is about, which kind) are plain attributes.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import dataclasses
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from enum import IntEnum
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from libvirtpy.rpc.session import ServerEvent
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"SOURCES",
|
|
18
|
+
"DomainEventKind",
|
|
19
|
+
"DomainLifecycle",
|
|
20
|
+
"Event",
|
|
21
|
+
"EventSource",
|
|
22
|
+
"NetworkEventKind",
|
|
23
|
+
"NodeDeviceEventKind",
|
|
24
|
+
"PoolEventKind",
|
|
25
|
+
"SecretEventKind",
|
|
26
|
+
"make_event",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class DomainEventKind(IntEnum):
|
|
31
|
+
"""The kinds of domain event (``virDomainEventID``)."""
|
|
32
|
+
|
|
33
|
+
LIFECYCLE = 0
|
|
34
|
+
REBOOT = 1
|
|
35
|
+
RTC_CHANGE = 2
|
|
36
|
+
WATCHDOG = 3
|
|
37
|
+
IO_ERROR = 4
|
|
38
|
+
GRAPHICS = 5
|
|
39
|
+
IO_ERROR_REASON = 6
|
|
40
|
+
CONTROL_ERROR = 7
|
|
41
|
+
BLOCK_JOB = 8
|
|
42
|
+
DISK_CHANGE = 9
|
|
43
|
+
TRAY_CHANGE = 10
|
|
44
|
+
PMWAKEUP = 11
|
|
45
|
+
PMSUSPEND = 12
|
|
46
|
+
BALLOON_CHANGE = 13
|
|
47
|
+
PMSUSPEND_DISK = 14
|
|
48
|
+
DEVICE_REMOVED = 15
|
|
49
|
+
BLOCK_JOB_2 = 16
|
|
50
|
+
TUNABLE = 17
|
|
51
|
+
AGENT_LIFECYCLE = 18
|
|
52
|
+
DEVICE_ADDED = 19
|
|
53
|
+
MIGRATION_ITERATION = 20
|
|
54
|
+
JOB_COMPLETED = 21
|
|
55
|
+
DEVICE_REMOVAL_FAILED = 22
|
|
56
|
+
METADATA_CHANGE = 23
|
|
57
|
+
BLOCK_THRESHOLD = 24
|
|
58
|
+
MEMORY_FAILURE = 25
|
|
59
|
+
MEMORY_DEVICE_SIZE_CHANGE = 26
|
|
60
|
+
NIC_MAC_CHANGE = 27
|
|
61
|
+
VCPU_REMOVED = 28
|
|
62
|
+
CHANNEL_LIFECYCLE = 29
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class NetworkEventKind(IntEnum):
|
|
66
|
+
"""The kinds of network event (``virNetworkEventID``)."""
|
|
67
|
+
|
|
68
|
+
LIFECYCLE = 0
|
|
69
|
+
METADATA_CHANGE = 1
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class PoolEventKind(IntEnum):
|
|
73
|
+
"""The kinds of storage pool event (``virStoragePoolEventID``)."""
|
|
74
|
+
|
|
75
|
+
LIFECYCLE = 0
|
|
76
|
+
REFRESH = 1
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class NodeDeviceEventKind(IntEnum):
|
|
80
|
+
"""The kinds of host device event (``virNodeDeviceEventID``)."""
|
|
81
|
+
|
|
82
|
+
LIFECYCLE = 0
|
|
83
|
+
UPDATE = 1
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class SecretEventKind(IntEnum):
|
|
87
|
+
"""The kinds of secret event (``virSecretEventID``)."""
|
|
88
|
+
|
|
89
|
+
LIFECYCLE = 0
|
|
90
|
+
VALUE_CHANGED = 1
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class DomainLifecycle(IntEnum):
|
|
94
|
+
"""What happened to a domain in a ``lifecycle`` event (``virDomainEventType``)."""
|
|
95
|
+
|
|
96
|
+
DEFINED = 0
|
|
97
|
+
UNDEFINED = 1
|
|
98
|
+
STARTED = 2
|
|
99
|
+
SUSPENDED = 3
|
|
100
|
+
RESUMED = 4
|
|
101
|
+
STOPPED = 5
|
|
102
|
+
SHUTDOWN = 6
|
|
103
|
+
PMSUSPENDED = 7
|
|
104
|
+
CRASHED = 8
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@dataclass(frozen=True)
|
|
108
|
+
class EventSource:
|
|
109
|
+
"""How to subscribe to one family of events."""
|
|
110
|
+
|
|
111
|
+
register: str
|
|
112
|
+
"""The procedure that starts the subscription."""
|
|
113
|
+
deregister: str
|
|
114
|
+
"""The procedure that ends it."""
|
|
115
|
+
kinds: type[IntEnum]
|
|
116
|
+
"""The event ids of the family."""
|
|
117
|
+
object_argument: str
|
|
118
|
+
"""The argument of ``register`` that limits it to one object."""
|
|
119
|
+
prefixes: tuple[str, ...]
|
|
120
|
+
"""What the procedure names of its events begin with (longest first)."""
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
SOURCES = {
|
|
124
|
+
"domain": EventSource(
|
|
125
|
+
"connect_domain_event_callback_register_any",
|
|
126
|
+
"connect_domain_event_callback_deregister_any",
|
|
127
|
+
DomainEventKind,
|
|
128
|
+
"dom",
|
|
129
|
+
("domain_event_callback_", "domain_event_"),
|
|
130
|
+
),
|
|
131
|
+
"network": EventSource(
|
|
132
|
+
"connect_network_event_register_any",
|
|
133
|
+
"connect_network_event_deregister_any",
|
|
134
|
+
NetworkEventKind,
|
|
135
|
+
"net",
|
|
136
|
+
("network_event_callback_", "network_event_"),
|
|
137
|
+
),
|
|
138
|
+
"pool": EventSource(
|
|
139
|
+
"connect_storage_pool_event_register_any",
|
|
140
|
+
"connect_storage_pool_event_deregister_any",
|
|
141
|
+
PoolEventKind,
|
|
142
|
+
"pool",
|
|
143
|
+
("storage_pool_event_",),
|
|
144
|
+
),
|
|
145
|
+
"node_device": EventSource(
|
|
146
|
+
"connect_node_device_event_register_any",
|
|
147
|
+
"connect_node_device_event_deregister_any",
|
|
148
|
+
NodeDeviceEventKind,
|
|
149
|
+
"dev",
|
|
150
|
+
("node_device_event_",),
|
|
151
|
+
),
|
|
152
|
+
"secret": EventSource(
|
|
153
|
+
"connect_secret_event_register_any",
|
|
154
|
+
"connect_secret_event_deregister_any",
|
|
155
|
+
SecretEventKind,
|
|
156
|
+
"secret",
|
|
157
|
+
("secret_event_",),
|
|
158
|
+
),
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@dataclass(frozen=True)
|
|
163
|
+
class Event:
|
|
164
|
+
"""Something that happened, as the daemon reported it."""
|
|
165
|
+
|
|
166
|
+
source: str
|
|
167
|
+
"""``domain``, ``network``, ``pool``, ``node_device`` or ``secret``."""
|
|
168
|
+
kind: str
|
|
169
|
+
"""The event kind in lower case: ``lifecycle``, ``block_job_2``, ``refresh``..."""
|
|
170
|
+
name: str | None
|
|
171
|
+
"""The name of the object it is about (a secret has none; see ``uuid``)."""
|
|
172
|
+
uuid: str | None
|
|
173
|
+
"""The UUID of the object, if it has one."""
|
|
174
|
+
callback_id: int | None
|
|
175
|
+
"""The subscription it answers."""
|
|
176
|
+
data: Any
|
|
177
|
+
"""The generated message struct, with all the details of the event."""
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def lifecycle(self) -> tuple[DomainLifecycle, int] | None:
|
|
181
|
+
"""The ``(what happened, detail)`` of a domain ``lifecycle`` event.
|
|
182
|
+
|
|
183
|
+
:returns: e.g. ``(DomainLifecycle.STOPPED, 4)``, or ``None`` for any other
|
|
184
|
+
event. ``detail`` is the libvirt reason code (for example 4 = destroyed).
|
|
185
|
+
"""
|
|
186
|
+
message = getattr(self.data, "msg", None)
|
|
187
|
+
if self.source != "domain" or self.kind != "lifecycle" or message is None:
|
|
188
|
+
return None
|
|
189
|
+
return DomainLifecycle(message.event), int(message.detail)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def make_event(server_event: ServerEvent) -> Event | None:
|
|
193
|
+
"""Turn a pushed message into an ``Event``.
|
|
194
|
+
|
|
195
|
+
:param server_event: the decoded message of the session.
|
|
196
|
+
:returns: the event, or ``None`` if the message is not one this module knows.
|
|
197
|
+
"""
|
|
198
|
+
name = server_event.procedure.name
|
|
199
|
+
for source, description in SOURCES.items():
|
|
200
|
+
for prefix in description.prefixes:
|
|
201
|
+
if name.startswith(prefix):
|
|
202
|
+
return _build(source, name.removeprefix(prefix), server_event.message)
|
|
203
|
+
return None
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def callback_id_of(message: Any) -> int | None:
|
|
207
|
+
"""Read the subscription id out of an event message.
|
|
208
|
+
|
|
209
|
+
:param message: a decoded event message.
|
|
210
|
+
:returns: the id, or ``None`` for the old events that have none.
|
|
211
|
+
"""
|
|
212
|
+
value = getattr(message, "callback_id", None)
|
|
213
|
+
return value if isinstance(value, int) else None
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _build(source: str, kind: str, message: Any) -> Event:
|
|
217
|
+
"""Assemble an event from its parts.
|
|
218
|
+
|
|
219
|
+
:param source: the event family.
|
|
220
|
+
:param kind: the event kind.
|
|
221
|
+
:param message: the decoded message.
|
|
222
|
+
:returns: the event.
|
|
223
|
+
"""
|
|
224
|
+
about = _find_object(message)
|
|
225
|
+
uuid_bytes = getattr(about, "uuid", None)
|
|
226
|
+
return Event(
|
|
227
|
+
source=source,
|
|
228
|
+
kind=kind,
|
|
229
|
+
name=getattr(about, "name", None),
|
|
230
|
+
uuid=_format_uuid(uuid_bytes) if isinstance(uuid_bytes, bytes) else None,
|
|
231
|
+
callback_id=callback_id_of(message),
|
|
232
|
+
data=message,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _find_object(message: Any) -> Any:
|
|
237
|
+
"""Find the object an event is about inside its message.
|
|
238
|
+
|
|
239
|
+
:param message: a decoded event message.
|
|
240
|
+
:returns: the ``Nonnull*`` struct of the domain, network, ...; or ``None``.
|
|
241
|
+
"""
|
|
242
|
+
for field in dataclasses.fields(message):
|
|
243
|
+
value = getattr(message, field.name)
|
|
244
|
+
if type(value).__name__.startswith("Nonnull"):
|
|
245
|
+
return value
|
|
246
|
+
if field.name == "msg":
|
|
247
|
+
return _find_object(value)
|
|
248
|
+
return None
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _format_uuid(raw: bytes) -> str:
|
|
252
|
+
"""Write a UUID in its usual form.
|
|
253
|
+
|
|
254
|
+
:param raw: the 16 bytes.
|
|
255
|
+
:returns: e.g. ``01234567-89ab-cdef-0123-456789abcdef``.
|
|
256
|
+
"""
|
|
257
|
+
import uuid
|
|
258
|
+
|
|
259
|
+
return str(uuid.UUID(bytes=raw))
|
libvirtpy/rpc/options.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Settings of a connection: call timeout and keepalive."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
__all__ = ["MAX_RECONNECT_DELAY", "ConnectionOptions"]
|
|
6
|
+
|
|
7
|
+
MAX_RECONNECT_DELAY = 30.0
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class ConnectionOptions:
|
|
12
|
+
"""How a connection watches the daemon.
|
|
13
|
+
|
|
14
|
+
The keepalive works like libvirt's: after ``keepalive_interval`` seconds without
|
|
15
|
+
anything received the client sends a ping, and it gives the connection up after
|
|
16
|
+
``keepalive_count`` unanswered pings. A daemon that hangs or a network that
|
|
17
|
+
drops silently is therefore noticed in about
|
|
18
|
+
``keepalive_interval * (keepalive_count + 1)`` seconds, and every waiting call
|
|
19
|
+
fails with ``ConnectionLostError``.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
call_timeout: float | None = None
|
|
23
|
+
"""Seconds a call may wait for its reply; ``None`` waits as long as it takes
|
|
24
|
+
(a volume wipe or a big upload can be slow). A call that times out raises
|
|
25
|
+
``CallTimeoutError`` and the connection stays usable."""
|
|
26
|
+
keepalive_interval: float | None = 5.0
|
|
27
|
+
"""Seconds of silence before a ping; ``None`` turns the keepalive off."""
|
|
28
|
+
keepalive_count: int = 5
|
|
29
|
+
"""Unanswered pings after which the daemon is considered dead."""
|
|
30
|
+
reconnect_attempts: int = 0
|
|
31
|
+
"""How many times a lost connection is opened again before giving up; ``0``
|
|
32
|
+
never reconnects (the next call fails with ``ConnectionLostError``)."""
|
|
33
|
+
reconnect_delay: float = 1.0
|
|
34
|
+
"""Seconds before the second attempt; each further wait doubles, up to
|
|
35
|
+
``MAX_RECONNECT_DELAY``. The first attempt is made at once."""
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def reconnects(self) -> bool:
|
|
39
|
+
"""Tell whether a lost connection is opened again.
|
|
40
|
+
|
|
41
|
+
:returns: ``True`` if ``reconnect_attempts`` is positive.
|
|
42
|
+
"""
|
|
43
|
+
return self.reconnect_attempts > 0
|
|
44
|
+
|
|
45
|
+
def reconnect_waits(self) -> list[float]:
|
|
46
|
+
"""List the waits before each reconnect attempt.
|
|
47
|
+
|
|
48
|
+
:returns: one value per attempt: 0 for the first, then ``reconnect_delay``
|
|
49
|
+
doubling, never more than ``MAX_RECONNECT_DELAY``.
|
|
50
|
+
"""
|
|
51
|
+
waits = [0.0]
|
|
52
|
+
delay = self.reconnect_delay
|
|
53
|
+
for _ in range(self.reconnect_attempts - 1):
|
|
54
|
+
waits.append(min(delay, MAX_RECONNECT_DELAY))
|
|
55
|
+
delay *= 2
|
|
56
|
+
return waits[: self.reconnect_attempts]
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def dead_after(self) -> float | None:
|
|
60
|
+
"""Seconds of silence after which the connection is given up.
|
|
61
|
+
|
|
62
|
+
:returns: the limit, or ``None`` if the keepalive is off.
|
|
63
|
+
"""
|
|
64
|
+
if self.keepalive_interval is None:
|
|
65
|
+
return None
|
|
66
|
+
return self.keepalive_interval * (self.keepalive_count + 1)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""The description of one remote procedure: its number, types and daemon."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, Literal, TypeVar
|
|
5
|
+
|
|
6
|
+
__all__ = ["Driver", "Procedure"]
|
|
7
|
+
|
|
8
|
+
Driver = Literal[
|
|
9
|
+
"hypervisor", "interface", "network", "node_device", "nwfilter", "secret", "storage"
|
|
10
|
+
]
|
|
11
|
+
"""The daemon that serves a procedure when libvirt runs as modular daemons."""
|
|
12
|
+
|
|
13
|
+
ArgsT = TypeVar("ArgsT")
|
|
14
|
+
ReturnT = TypeVar("ReturnT")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class Procedure[ArgsT, ReturnT]:
|
|
19
|
+
"""A call of the remote protocol. ``args`` and ``ret`` are ``None`` if void."""
|
|
20
|
+
|
|
21
|
+
number: int
|
|
22
|
+
name: str
|
|
23
|
+
args: type[ArgsT] | None
|
|
24
|
+
ret: type[ReturnT] | None
|
|
25
|
+
driver: Driver
|
|
26
|
+
message: type[Any] | None = None
|
|
27
|
+
"""For an event: the struct the daemon pushes (it is not a reply)."""
|
|
File without changes
|