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.
Files changed (154) hide show
  1. libvirtpy/__init__.py +5 -0
  2. libvirtpy/client/__init__.py +54 -0
  3. libvirtpy/client/_bases.py +326 -0
  4. libvirtpy/client/_runner.py +57 -0
  5. libvirtpy/client/aio.py +5922 -0
  6. libvirtpy/client/client.py +5695 -0
  7. libvirtpy/client/operations/__init__.py +631 -0
  8. libvirtpy/client/operations/_common.py +495 -0
  9. libvirtpy/client/operations/checkpoint.py +196 -0
  10. libvirtpy/client/operations/connection.py +93 -0
  11. libvirtpy/client/operations/connection_extra.py +256 -0
  12. libvirtpy/client/operations/domain.py +306 -0
  13. libvirtpy/client/operations/domain_agent.py +115 -0
  14. libvirtpy/client/operations/domain_block.py +368 -0
  15. libvirtpy/client/operations/domain_info.py +400 -0
  16. libvirtpy/client/operations/domain_lifecycle.py +338 -0
  17. libvirtpy/client/operations/domain_migration.py +164 -0
  18. libvirtpy/client/operations/domain_network.py +113 -0
  19. libvirtpy/client/operations/domain_tuning.py +494 -0
  20. libvirtpy/client/operations/host.py +246 -0
  21. libvirtpy/client/operations/host_interface.py +100 -0
  22. libvirtpy/client/operations/interface_extra.py +45 -0
  23. libvirtpy/client/operations/network.py +135 -0
  24. libvirtpy/client/operations/network_info.py +155 -0
  25. libvirtpy/client/operations/network_port.py +142 -0
  26. libvirtpy/client/operations/node_device.py +76 -0
  27. libvirtpy/client/operations/node_device_info.py +189 -0
  28. libvirtpy/client/operations/nwfilter.py +67 -0
  29. libvirtpy/client/operations/nwfilter_binding.py +74 -0
  30. libvirtpy/client/operations/secret.py +93 -0
  31. libvirtpy/client/operations/secret_extra.py +24 -0
  32. libvirtpy/client/operations/snapshot.py +100 -0
  33. libvirtpy/client/operations/snapshot_tree.py +114 -0
  34. libvirtpy/client/operations/storage.py +267 -0
  35. libvirtpy/client/operations/storage_info.py +188 -0
  36. libvirtpy/client/operations/streams.py +201 -0
  37. libvirtpy/client/references.py +249 -0
  38. libvirtpy/client/subscribing.py +88 -0
  39. libvirtpy/client/testing/__init__.py +24 -0
  40. libvirtpy/client/testing/_common.py +167 -0
  41. libvirtpy/client/testing/_domains.py +294 -0
  42. libvirtpy/client/testing/_objects.py +205 -0
  43. libvirtpy/client/testing/_state.py +246 -0
  44. libvirtpy/client/testing/_storage.py +171 -0
  45. libvirtpy/client/testing/async_transport.py +30 -0
  46. libvirtpy/client/testing/fake.py +81 -0
  47. libvirtpy/client/transport.py +87 -0
  48. libvirtpy/client/types.py +59 -0
  49. libvirtpy/client/wire.py +436 -0
  50. libvirtpy/client/wire_aio.py +348 -0
  51. libvirtpy/errors.py +7 -0
  52. libvirtpy/py.typed +0 -0
  53. libvirtpy/rpc/__init__.py +1 -0
  54. libvirtpy/rpc/aio.py +387 -0
  55. libvirtpy/rpc/cpumap.py +48 -0
  56. libvirtpy/rpc/errors.py +186 -0
  57. libvirtpy/rpc/events.py +259 -0
  58. libvirtpy/rpc/options.py +66 -0
  59. libvirtpy/rpc/procedure.py +27 -0
  60. libvirtpy/rpc/protocol/__init__.py +0 -0
  61. libvirtpy/rpc/protocol/procedures.py +5163 -0
  62. libvirtpy/rpc/protocol/typed_hints.py +210 -0
  63. libvirtpy/rpc/protocol/types.py +9299 -0
  64. libvirtpy/rpc/remote.py +295 -0
  65. libvirtpy/rpc/remote_aio.py +106 -0
  66. libvirtpy/rpc/sasl.py +467 -0
  67. libvirtpy/rpc/session.py +424 -0
  68. libvirtpy/rpc/sockets.py +251 -0
  69. libvirtpy/rpc/stream.py +323 -0
  70. libvirtpy/rpc/subscription.py +451 -0
  71. libvirtpy/rpc/sync.py +460 -0
  72. libvirtpy/rpc/typed_params.py +97 -0
  73. libvirtpy/rpc/uri.py +85 -0
  74. libvirtpy/rpc/xdr.py +552 -0
  75. libvirtpy/xml/__init__.py +49 -0
  76. libvirtpy/xml/_base.py +145 -0
  77. libvirtpy/xml/_shared/__init__.py +1 -0
  78. libvirtpy/xml/_shared/metadata.py +67 -0
  79. libvirtpy/xml/_shared/network.py +108 -0
  80. libvirtpy/xml/_shared/storage.py +131 -0
  81. libvirtpy/xml/_shared/sysinfo.py +83 -0
  82. libvirtpy/xml/_types.py +197 -0
  83. libvirtpy/xml/_xml_element.py +134 -0
  84. libvirtpy/xml/backup/__init__.py +25 -0
  85. libvirtpy/xml/backup/backup.py +89 -0
  86. libvirtpy/xml/backup/checkpoint.py +48 -0
  87. libvirtpy/xml/capabilities/__init__.py +43 -0
  88. libvirtpy/xml/capabilities/domain.py +436 -0
  89. libvirtpy/xml/capabilities/host.py +413 -0
  90. libvirtpy/xml/capabilities/storagepool.py +59 -0
  91. libvirtpy/xml/domain/__init__.py +493 -0
  92. libvirtpy/xml/domain/blkiotune.py +81 -0
  93. libvirtpy/xml/domain/clock.py +79 -0
  94. libvirtpy/xml/domain/cpu.py +265 -0
  95. libvirtpy/xml/domain/devices/__init__.py +495 -0
  96. libvirtpy/xml/domain/devices/address.py +152 -0
  97. libvirtpy/xml/domain/devices/audio.py +204 -0
  98. libvirtpy/xml/domain/devices/chardev.py +197 -0
  99. libvirtpy/xml/domain/devices/common.py +75 -0
  100. libvirtpy/xml/domain/devices/controller.py +262 -0
  101. libvirtpy/xml/domain/devices/devices.py +79 -0
  102. libvirtpy/xml/domain/devices/disk.py +471 -0
  103. libvirtpy/xml/domain/devices/filesystem.py +206 -0
  104. libvirtpy/xml/domain/devices/graphics.py +245 -0
  105. libvirtpy/xml/domain/devices/hostdev.py +221 -0
  106. libvirtpy/xml/domain/devices/input.py +89 -0
  107. libvirtpy/xml/domain/devices/interface.py +459 -0
  108. libvirtpy/xml/domain/devices/iommu.py +54 -0
  109. libvirtpy/xml/domain/devices/memballoon.py +42 -0
  110. libvirtpy/xml/domain/devices/memory_device.py +101 -0
  111. libvirtpy/xml/domain/devices/misc.py +169 -0
  112. libvirtpy/xml/domain/devices/nvram.py +20 -0
  113. libvirtpy/xml/domain/devices/shmem.py +46 -0
  114. libvirtpy/xml/domain/devices/sound.py +42 -0
  115. libvirtpy/xml/domain/devices/tpm.py +103 -0
  116. libvirtpy/xml/domain/devices/usb.py +86 -0
  117. libvirtpy/xml/domain/devices/video.py +101 -0
  118. libvirtpy/xml/domain/domain.py +157 -0
  119. libvirtpy/xml/domain/features.py +312 -0
  120. libvirtpy/xml/domain/iothread.py +41 -0
  121. libvirtpy/xml/domain/launch_security.py +82 -0
  122. libvirtpy/xml/domain/memory.py +149 -0
  123. libvirtpy/xml/domain/misc.py +113 -0
  124. libvirtpy/xml/domain/namespaces.py +96 -0
  125. libvirtpy/xml/domain/numa.py +140 -0
  126. libvirtpy/xml/domain/os.py +267 -0
  127. libvirtpy/xml/domain/qemu.py +102 -0
  128. libvirtpy/xml/domain/seclabel.py +29 -0
  129. libvirtpy/xml/domain/storage_source.py +466 -0
  130. libvirtpy/xml/domain/sysinfo.py +34 -0
  131. libvirtpy/xml/interface/__init__.py +17 -0
  132. libvirtpy/xml/interface/interface.py +153 -0
  133. libvirtpy/xml/network/__init__.py +101 -0
  134. libvirtpy/xml/network/network.py +311 -0
  135. libvirtpy/xml/network/port.py +84 -0
  136. libvirtpy/xml/nodedev/__init__.py +13 -0
  137. libvirtpy/xml/nodedev/nodedev.py +490 -0
  138. libvirtpy/xml/nwfilter/__init__.py +81 -0
  139. libvirtpy/xml/nwfilter/binding.py +51 -0
  140. libvirtpy/xml/nwfilter/filter.py +92 -0
  141. libvirtpy/xml/nwfilter/rules.py +534 -0
  142. libvirtpy/xml/secret/__init__.py +11 -0
  143. libvirtpy/xml/secret/secret.py +36 -0
  144. libvirtpy/xml/snapshot/__init__.py +29 -0
  145. libvirtpy/xml/snapshot/snapshot.py +136 -0
  146. libvirtpy/xml/storage/__init__.py +75 -0
  147. libvirtpy/xml/storage/pool.py +219 -0
  148. libvirtpy/xml/storage/volume.py +102 -0
  149. libvirtpy/xml/sysinfo.py +40 -0
  150. libvirtpy-0.1.0.dist-info/METADATA +109 -0
  151. libvirtpy-0.1.0.dist-info/RECORD +154 -0
  152. libvirtpy-0.1.0.dist-info/WHEEL +4 -0
  153. libvirtpy-0.1.0.dist-info/licenses/LICENSE +501 -0
  154. libvirtpy-0.1.0.dist-info/licenses/NOTICE +23 -0
@@ -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))
@@ -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