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
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""The objects of the fake daemon and what every kind of object shares."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Mapping
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
from libvirtpy.client.testing._common import (
|
|
7
|
+
Arguments,
|
|
8
|
+
ModelT,
|
|
9
|
+
_ensure_uuid,
|
|
10
|
+
_Entry,
|
|
11
|
+
_handle_argument,
|
|
12
|
+
_handle_of,
|
|
13
|
+
_int,
|
|
14
|
+
_key_of,
|
|
15
|
+
_redefine,
|
|
16
|
+
)
|
|
17
|
+
from libvirtpy.client.transport import Handle
|
|
18
|
+
from libvirtpy.rpc.errors import (
|
|
19
|
+
ErrorNumber,
|
|
20
|
+
ExistsError,
|
|
21
|
+
LibvirtError,
|
|
22
|
+
NoDomainError,
|
|
23
|
+
NoFilterError,
|
|
24
|
+
NoInterfaceError,
|
|
25
|
+
NoNetworkError,
|
|
26
|
+
NoNodeDeviceError,
|
|
27
|
+
NoSecretError,
|
|
28
|
+
NoSnapshotError,
|
|
29
|
+
NoStoragePoolError,
|
|
30
|
+
NoStorageVolumeError,
|
|
31
|
+
OperationInvalidError,
|
|
32
|
+
)
|
|
33
|
+
from libvirtpy.xml.domain import Domain
|
|
34
|
+
from libvirtpy.xml.interface import HostInterface
|
|
35
|
+
from libvirtpy.xml.network import Network
|
|
36
|
+
from libvirtpy.xml.nodedev import Device
|
|
37
|
+
from libvirtpy.xml.nwfilter import Filter
|
|
38
|
+
from libvirtpy.xml.secret import Secret
|
|
39
|
+
from libvirtpy.xml.snapshot import Snapshot
|
|
40
|
+
from libvirtpy.xml.storage import Pool, Volume
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class FakeState:
|
|
44
|
+
"""The objects of the fake daemon and what every kind of object shares."""
|
|
45
|
+
|
|
46
|
+
def __init__(self) -> None:
|
|
47
|
+
"""Create the state: no domains and no other objects."""
|
|
48
|
+
self._next_domain_id = 1
|
|
49
|
+
self._domains: dict[str, _Entry[Domain]] = {}
|
|
50
|
+
self._networks: dict[str, _Entry[Network]] = {}
|
|
51
|
+
self._pools: dict[str, _Entry[Pool]] = {}
|
|
52
|
+
self._volumes: dict[tuple[str, str], Volume] = {}
|
|
53
|
+
self._secrets: dict[str, _Entry[Secret]] = {}
|
|
54
|
+
self._filters: dict[str, _Entry[Filter]] = {}
|
|
55
|
+
self._interfaces: dict[str, _Entry[HostInterface]] = {}
|
|
56
|
+
self._devices: dict[str, Device] = {}
|
|
57
|
+
self._snapshots: dict[tuple[str, str], Snapshot] = {}
|
|
58
|
+
self._snapshot_count = 0
|
|
59
|
+
|
|
60
|
+
def _define(
|
|
61
|
+
self,
|
|
62
|
+
entries: dict[str, _Entry[ModelT]],
|
|
63
|
+
model_type: type[ModelT],
|
|
64
|
+
xml: str,
|
|
65
|
+
) -> Handle:
|
|
66
|
+
model = model_type.from_xml(xml)
|
|
67
|
+
_ensure_uuid(model)
|
|
68
|
+
key = _key_of(model)
|
|
69
|
+
existing = entries.get(key)
|
|
70
|
+
entries[key] = _Entry(model) if existing is None else _redefine(existing, model)
|
|
71
|
+
return _handle_of(model)
|
|
72
|
+
|
|
73
|
+
def _create_transient(
|
|
74
|
+
self,
|
|
75
|
+
entries: dict[str, _Entry[ModelT]],
|
|
76
|
+
model_type: type[ModelT],
|
|
77
|
+
xml: str,
|
|
78
|
+
) -> Handle:
|
|
79
|
+
model = model_type.from_xml(xml)
|
|
80
|
+
_ensure_uuid(model)
|
|
81
|
+
key = _key_of(model)
|
|
82
|
+
if key in entries:
|
|
83
|
+
raise ExistsError(f"{key} already exists", code=ErrorNumber.DOM_EXIST)
|
|
84
|
+
entries[key] = _Entry(model, active=True, transient=True)
|
|
85
|
+
return _handle_of(model)
|
|
86
|
+
|
|
87
|
+
def _undefine(
|
|
88
|
+
self,
|
|
89
|
+
entries: dict[str, _Entry[ModelT]],
|
|
90
|
+
arguments: Arguments,
|
|
91
|
+
not_found: Callable[[str], LibvirtError],
|
|
92
|
+
*,
|
|
93
|
+
check_active: bool = True,
|
|
94
|
+
) -> None:
|
|
95
|
+
entry = self._get(entries, arguments, not_found)
|
|
96
|
+
if check_active and entry.active:
|
|
97
|
+
raise OperationInvalidError(
|
|
98
|
+
"cannot undefine an active object", code=ErrorNumber.OPERATION_INVALID
|
|
99
|
+
)
|
|
100
|
+
del entries[_key_of(entry.model)]
|
|
101
|
+
|
|
102
|
+
def _start(
|
|
103
|
+
self,
|
|
104
|
+
entries: dict[str, _Entry[ModelT]],
|
|
105
|
+
arguments: Arguments,
|
|
106
|
+
not_found: Callable[[str], LibvirtError],
|
|
107
|
+
) -> None:
|
|
108
|
+
entry = self._get(entries, arguments, not_found)
|
|
109
|
+
if entry.active:
|
|
110
|
+
raise OperationInvalidError(
|
|
111
|
+
"the object is already active", code=ErrorNumber.OPERATION_INVALID
|
|
112
|
+
)
|
|
113
|
+
entry.active = True
|
|
114
|
+
|
|
115
|
+
def _stop(
|
|
116
|
+
self,
|
|
117
|
+
entries: dict[str, _Entry[ModelT]],
|
|
118
|
+
arguments: Arguments,
|
|
119
|
+
not_found: Callable[[str], LibvirtError],
|
|
120
|
+
) -> None:
|
|
121
|
+
entry = self._get(entries, arguments, not_found)
|
|
122
|
+
if not entry.active:
|
|
123
|
+
raise OperationInvalidError(
|
|
124
|
+
"the object is not active", code=ErrorNumber.OPERATION_INVALID
|
|
125
|
+
)
|
|
126
|
+
entry.active = False
|
|
127
|
+
if entry.transient:
|
|
128
|
+
del entries[_key_of(entry.model)]
|
|
129
|
+
|
|
130
|
+
def _set_autostart(
|
|
131
|
+
self,
|
|
132
|
+
entries: dict[str, _Entry[ModelT]],
|
|
133
|
+
arguments: Arguments,
|
|
134
|
+
not_found: Callable[[str], LibvirtError],
|
|
135
|
+
) -> None:
|
|
136
|
+
self._get(entries, arguments, not_found).autostart = bool(
|
|
137
|
+
_int(arguments, "autostart")
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
def _list(
|
|
141
|
+
self,
|
|
142
|
+
entries: Mapping[str, _Entry[ModelT]],
|
|
143
|
+
arguments: Arguments,
|
|
144
|
+
inactive_is_one: bool,
|
|
145
|
+
) -> list[Handle]:
|
|
146
|
+
flags = _int(arguments, "flags")
|
|
147
|
+
active_flag, inactive_flag = (2, 1) if inactive_is_one else (1, 2)
|
|
148
|
+
wanted = [
|
|
149
|
+
entry
|
|
150
|
+
for entry in entries.values()
|
|
151
|
+
if flags == 0
|
|
152
|
+
or (flags & active_flag and entry.active)
|
|
153
|
+
or (flags & inactive_flag and not entry.active)
|
|
154
|
+
]
|
|
155
|
+
return [_handle_of(entry.model) for entry in wanted]
|
|
156
|
+
|
|
157
|
+
def _get(
|
|
158
|
+
self,
|
|
159
|
+
entries: Mapping[str, _Entry[ModelT]],
|
|
160
|
+
arguments: Arguments,
|
|
161
|
+
not_found: Callable[[str], LibvirtError],
|
|
162
|
+
) -> _Entry[ModelT]:
|
|
163
|
+
handle = _handle_argument(arguments)
|
|
164
|
+
key = handle.uuid if handle.uuid in entries else handle.name
|
|
165
|
+
entry = entries.get(key or "")
|
|
166
|
+
if entry is None:
|
|
167
|
+
raise not_found(handle.name)
|
|
168
|
+
return entry
|
|
169
|
+
|
|
170
|
+
def _find_by_name(
|
|
171
|
+
self,
|
|
172
|
+
entries: Mapping[str, _Entry[ModelT]],
|
|
173
|
+
name: str,
|
|
174
|
+
not_found: Callable[[str], LibvirtError],
|
|
175
|
+
) -> Handle:
|
|
176
|
+
for entry in entries.values():
|
|
177
|
+
if getattr(entry.model, "name", None) == name:
|
|
178
|
+
return _handle_of(entry.model)
|
|
179
|
+
raise not_found(name)
|
|
180
|
+
|
|
181
|
+
def _find_by_uuid(
|
|
182
|
+
self,
|
|
183
|
+
entries: Mapping[str, _Entry[ModelT]],
|
|
184
|
+
uuid_text: str,
|
|
185
|
+
not_found: Callable[[str], LibvirtError],
|
|
186
|
+
) -> Handle:
|
|
187
|
+
wanted = UUID(uuid_text)
|
|
188
|
+
for entry in entries.values():
|
|
189
|
+
model_uuid = getattr(entry.model, "uuid", None)
|
|
190
|
+
if model_uuid is not None and UUID(model_uuid) == wanted:
|
|
191
|
+
return _handle_of(entry.model)
|
|
192
|
+
raise not_found(uuid_text)
|
|
193
|
+
|
|
194
|
+
def _no_domain(self, what: str) -> LibvirtError:
|
|
195
|
+
return NoDomainError(
|
|
196
|
+
f"Domain not found: no domain with matching name '{what}'",
|
|
197
|
+
code=ErrorNumber.NO_DOMAIN,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
def _no_network(self, what: str) -> LibvirtError:
|
|
201
|
+
return NoNetworkError(
|
|
202
|
+
f"Network not found: no network with matching name '{what}'",
|
|
203
|
+
code=ErrorNumber.NO_NETWORK,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
def _no_pool(self, what: str) -> LibvirtError:
|
|
207
|
+
return NoStoragePoolError(
|
|
208
|
+
f"Storage pool not found: no pool with matching name '{what}'",
|
|
209
|
+
code=ErrorNumber.NO_STORAGE_POOL,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
def _no_volume(self, what: str) -> LibvirtError:
|
|
213
|
+
return NoStorageVolumeError(
|
|
214
|
+
f"Storage volume not found: no volume with matching name '{what}'",
|
|
215
|
+
code=ErrorNumber.NO_STORAGE_VOL,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
def _no_secret(self, what: str) -> LibvirtError:
|
|
219
|
+
return NoSecretError(
|
|
220
|
+
f"Secret not found: no secret with matching uuid '{what}'",
|
|
221
|
+
code=ErrorNumber.NO_SECRET,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
def _no_filter(self, what: str) -> LibvirtError:
|
|
225
|
+
return NoFilterError(
|
|
226
|
+
f"Network filter not found: no nwfilter with matching name '{what}'",
|
|
227
|
+
code=ErrorNumber.NO_NWFILTER,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
def _no_interface(self, what: str) -> LibvirtError:
|
|
231
|
+
return NoInterfaceError(
|
|
232
|
+
f"Interface not found: no interface with matching name '{what}'",
|
|
233
|
+
code=ErrorNumber.NO_INTERFACE,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
def _no_device(self, what: str) -> LibvirtError:
|
|
237
|
+
return NoNodeDeviceError(
|
|
238
|
+
f"Node device not found: no device with matching name '{what}'",
|
|
239
|
+
code=ErrorNumber.NO_NODE_DEVICE,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
def _no_snapshot(self, what: str) -> LibvirtError:
|
|
243
|
+
return NoSnapshotError(
|
|
244
|
+
f"Domain snapshot not found: no snapshot with matching name '{what}'",
|
|
245
|
+
code=ErrorNumber.NO_DOMAIN_SNAPSHOT,
|
|
246
|
+
)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Storage pools and volumes."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.testing._common import (
|
|
4
|
+
Action,
|
|
5
|
+
Arguments,
|
|
6
|
+
_handle_argument,
|
|
7
|
+
_int,
|
|
8
|
+
_pool_name,
|
|
9
|
+
_text,
|
|
10
|
+
_volume_handle,
|
|
11
|
+
_xml_of,
|
|
12
|
+
)
|
|
13
|
+
from libvirtpy.client.testing._state import FakeState
|
|
14
|
+
from libvirtpy.client.transport import Handle
|
|
15
|
+
from libvirtpy.rpc.errors import (
|
|
16
|
+
ErrorNumber,
|
|
17
|
+
ExistsError,
|
|
18
|
+
OperationInvalidError,
|
|
19
|
+
)
|
|
20
|
+
from libvirtpy.xml._shared.storage import Allocation, Capacity
|
|
21
|
+
from libvirtpy.xml.storage import Pool, PoolTarget, Volume, VolumeTarget
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class StorageActions(FakeState):
|
|
25
|
+
"""Storage pools and volumes."""
|
|
26
|
+
|
|
27
|
+
def _pool_actions(self) -> dict[str, Action]:
|
|
28
|
+
return {
|
|
29
|
+
"connect_list_all_storage_pools": lambda a: self._list(
|
|
30
|
+
self._pools, a, True
|
|
31
|
+
),
|
|
32
|
+
"storage_pool_lookup_by_name": lambda a: self._find_by_name(
|
|
33
|
+
self._pools, _text(a, "name"), self._no_pool
|
|
34
|
+
),
|
|
35
|
+
"storage_pool_lookup_by_uuid": lambda a: self._find_by_uuid(
|
|
36
|
+
self._pools, _text(a, "uuid"), self._no_pool
|
|
37
|
+
),
|
|
38
|
+
"storage_pool_get_xml_desc": lambda a: _xml_of(
|
|
39
|
+
self._get(self._pools, a, self._no_pool).model
|
|
40
|
+
),
|
|
41
|
+
"storage_pool_define_xml": self._define_pool,
|
|
42
|
+
"storage_pool_create_xml": self._create_pool,
|
|
43
|
+
"storage_pool_undefine": lambda a: self._undefine(
|
|
44
|
+
self._pools, a, self._no_pool
|
|
45
|
+
),
|
|
46
|
+
"storage_pool_create": lambda a: self._start(self._pools, a, self._no_pool),
|
|
47
|
+
"storage_pool_destroy": lambda a: self._stop(self._pools, a, self._no_pool),
|
|
48
|
+
"storage_pool_build": lambda _: None,
|
|
49
|
+
"storage_pool_delete": self._delete_pool,
|
|
50
|
+
"storage_pool_refresh": self._refresh_pool,
|
|
51
|
+
"storage_pool_get_autostart": lambda a: int(
|
|
52
|
+
self._get(self._pools, a, self._no_pool).autostart
|
|
53
|
+
),
|
|
54
|
+
"storage_pool_set_autostart": lambda a: self._set_autostart(
|
|
55
|
+
self._pools, a, self._no_pool
|
|
56
|
+
),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
def _volume_actions(self) -> dict[str, Action]:
|
|
60
|
+
return {
|
|
61
|
+
"storage_pool_list_all_volumes": self._list_volumes,
|
|
62
|
+
"storage_vol_lookup_by_name": self._lookup_volume_by_name,
|
|
63
|
+
"storage_vol_lookup_by_key": lambda a: self._lookup_volume_by("key", a),
|
|
64
|
+
"storage_vol_lookup_by_path": lambda a: self._lookup_volume_by("path", a),
|
|
65
|
+
"storage_vol_get_xml_desc": lambda a: _xml_of(self._volume(a)),
|
|
66
|
+
"storage_vol_create_xml": self._create_volume,
|
|
67
|
+
"storage_vol_delete": self._delete_volume,
|
|
68
|
+
"storage_vol_resize": self._resize_volume,
|
|
69
|
+
"storage_vol_wipe": lambda a: self._volume(a) and None,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def _define_pool(self, arguments: Arguments) -> Handle:
|
|
73
|
+
handle = self._define(self._pools, Pool, _text(arguments, "xml"))
|
|
74
|
+
self._complete_pool(self._pools[handle.name].model)
|
|
75
|
+
return handle
|
|
76
|
+
|
|
77
|
+
def _create_pool(self, arguments: Arguments) -> Handle:
|
|
78
|
+
handle = self._create_transient(self._pools, Pool, _text(arguments, "xml"))
|
|
79
|
+
self._complete_pool(self._pools[handle.name].model)
|
|
80
|
+
return handle
|
|
81
|
+
|
|
82
|
+
def _complete_pool(self, pool: Pool) -> None:
|
|
83
|
+
if pool.target is None:
|
|
84
|
+
pool.target = PoolTarget(path=f"/var/lib/libvirt/images/{pool.name}")
|
|
85
|
+
if pool.capacity is None:
|
|
86
|
+
pool.capacity = Capacity(value=100, unit="GiB")
|
|
87
|
+
pool.allocation = Allocation(value=0, unit="B")
|
|
88
|
+
|
|
89
|
+
def _delete_pool(self, arguments: Arguments) -> None:
|
|
90
|
+
entry = self._get(self._pools, arguments, self._no_pool)
|
|
91
|
+
if entry.active:
|
|
92
|
+
raise OperationInvalidError(
|
|
93
|
+
"the pool is active", code=ErrorNumber.OPERATION_INVALID
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def _refresh_pool(self, arguments: Arguments) -> None:
|
|
97
|
+
entry = self._get(self._pools, arguments, self._no_pool)
|
|
98
|
+
if not entry.active:
|
|
99
|
+
raise OperationInvalidError(
|
|
100
|
+
"the pool is not active", code=ErrorNumber.OPERATION_INVALID
|
|
101
|
+
)
|
|
102
|
+
used = sum(
|
|
103
|
+
volume.capacity.to_bytes() if volume.capacity else 0
|
|
104
|
+
for (pool, _), volume in self._volumes.items()
|
|
105
|
+
if pool == entry.model.name
|
|
106
|
+
)
|
|
107
|
+
entry.model.allocation = Allocation(value=used, unit="B")
|
|
108
|
+
|
|
109
|
+
def _list_volumes(self, arguments: Arguments) -> list[Handle]:
|
|
110
|
+
pool = self._get(self._pools, arguments, self._no_pool).model.name
|
|
111
|
+
return [
|
|
112
|
+
_volume_handle(volume, owner)
|
|
113
|
+
for (owner, _), volume in self._volumes.items()
|
|
114
|
+
if owner == pool
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
def _lookup_volume_by_name(self, arguments: Arguments) -> Handle:
|
|
118
|
+
pool = self._get(self._pools, {"pool": arguments["pool"]}, self._no_pool)
|
|
119
|
+
volume = self._volumes.get((_pool_name(pool.model), _text(arguments, "name")))
|
|
120
|
+
if volume is None:
|
|
121
|
+
raise self._no_volume(_text(arguments, "name"))
|
|
122
|
+
return _volume_handle(volume, _pool_name(pool.model))
|
|
123
|
+
|
|
124
|
+
def _lookup_volume_by(self, field_name: str, arguments: Arguments) -> Handle:
|
|
125
|
+
wanted = _text(arguments, field_name)
|
|
126
|
+
for (pool, _), volume in self._volumes.items():
|
|
127
|
+
target = volume.target.path if volume.target else None
|
|
128
|
+
if (field_name == "key" and volume.key == wanted) or (
|
|
129
|
+
field_name == "path" and target == wanted
|
|
130
|
+
):
|
|
131
|
+
return _volume_handle(volume, pool)
|
|
132
|
+
raise self._no_volume(wanted)
|
|
133
|
+
|
|
134
|
+
def _volume(self, arguments: Arguments) -> Volume:
|
|
135
|
+
handle = _handle_argument(arguments)
|
|
136
|
+
volume = self._volumes.get((handle.parent or "", handle.name))
|
|
137
|
+
if volume is None:
|
|
138
|
+
raise self._no_volume(handle.name)
|
|
139
|
+
return volume
|
|
140
|
+
|
|
141
|
+
def _create_volume(self, arguments: Arguments) -> Handle:
|
|
142
|
+
entry = self._get(self._pools, {"pool": arguments["pool"]}, self._no_pool)
|
|
143
|
+
if not entry.active:
|
|
144
|
+
raise OperationInvalidError(
|
|
145
|
+
"the pool is not active", code=ErrorNumber.OPERATION_INVALID
|
|
146
|
+
)
|
|
147
|
+
volume = Volume.from_xml(_text(arguments, "xml"))
|
|
148
|
+
pool_name = _pool_name(entry.model)
|
|
149
|
+
if (pool_name, volume.name) in self._volumes:
|
|
150
|
+
raise ExistsError(
|
|
151
|
+
f"volume {volume.name} exists", code=ErrorNumber.OPERATION_FAILED
|
|
152
|
+
)
|
|
153
|
+
base = (
|
|
154
|
+
entry.model.target.path if entry.model.target else "/var/lib/libvirt/images"
|
|
155
|
+
)
|
|
156
|
+
path = f"{base}/{volume.name}"
|
|
157
|
+
volume.key = path
|
|
158
|
+
volume.target = volume.target or VolumeTarget()
|
|
159
|
+
volume.target.path = path
|
|
160
|
+
volume.allocation = volume.allocation or Allocation(value=0, unit="B")
|
|
161
|
+
self._volumes[(pool_name, volume.name)] = volume
|
|
162
|
+
return _volume_handle(volume, pool_name)
|
|
163
|
+
|
|
164
|
+
def _delete_volume(self, arguments: Arguments) -> None:
|
|
165
|
+
handle = _handle_argument(arguments)
|
|
166
|
+
self._volume(arguments)
|
|
167
|
+
del self._volumes[(handle.parent or "", handle.name)]
|
|
168
|
+
|
|
169
|
+
def _resize_volume(self, arguments: Arguments) -> None:
|
|
170
|
+
volume = self._volume(arguments)
|
|
171
|
+
volume.capacity = Capacity(value=_int(arguments, "capacity"), unit="B")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""The async face of the fake daemon."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.testing.fake import FakeLibvirt
|
|
4
|
+
from libvirtpy.client.transport import Request
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AsyncFakeTransport:
|
|
8
|
+
"""The async ``AsyncTransport`` of an ``AsyncLibvirtClient`` over a fake daemon."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, daemon: FakeLibvirt | None = None) -> None:
|
|
11
|
+
"""Create the transport.
|
|
12
|
+
|
|
13
|
+
:param daemon: the daemon to serve from; a new empty one by default.
|
|
14
|
+
"""
|
|
15
|
+
self.daemon = daemon if daemon is not None else FakeLibvirt()
|
|
16
|
+
|
|
17
|
+
async def call(self, request: Request) -> object:
|
|
18
|
+
"""Serve one request, yielding to the event loop first like real I/O.
|
|
19
|
+
|
|
20
|
+
:param request: the call to make.
|
|
21
|
+
:returns: the reply.
|
|
22
|
+
:raises LibvirtError: for the errors a real daemon would report.
|
|
23
|
+
"""
|
|
24
|
+
import asyncio
|
|
25
|
+
|
|
26
|
+
await asyncio.sleep(0)
|
|
27
|
+
return self.daemon.call(request)
|
|
28
|
+
|
|
29
|
+
async def close(self) -> None:
|
|
30
|
+
"""Close the connection (nothing to do for the fake)."""
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""The fake daemon: dispatch of requests to the actions of each area."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.testing._common import (
|
|
4
|
+
_PCI_DEVICE,
|
|
5
|
+
Action,
|
|
6
|
+
_check_against_protocol,
|
|
7
|
+
_Entry,
|
|
8
|
+
)
|
|
9
|
+
from libvirtpy.client.testing._domains import DomainActions
|
|
10
|
+
from libvirtpy.client.testing._objects import ObjectActions
|
|
11
|
+
from libvirtpy.client.testing._storage import StorageActions
|
|
12
|
+
from libvirtpy.client.transport import Request
|
|
13
|
+
from libvirtpy.rpc.errors import (
|
|
14
|
+
ErrorNumber,
|
|
15
|
+
NotSupportedError,
|
|
16
|
+
)
|
|
17
|
+
from libvirtpy.xml.domain import Domain
|
|
18
|
+
from libvirtpy.xml.interface import HostInterface
|
|
19
|
+
from libvirtpy.xml.network import Network
|
|
20
|
+
from libvirtpy.xml.nodedev import Device
|
|
21
|
+
from libvirtpy.xml.nwfilter import Filter
|
|
22
|
+
from libvirtpy.xml.secret import Secret
|
|
23
|
+
from libvirtpy.xml.snapshot import Snapshot
|
|
24
|
+
from libvirtpy.xml.storage import Pool, Volume
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FakeLibvirt(DomainActions, StorageActions, ObjectActions):
|
|
28
|
+
"""The fake daemon; also the sync ``Transport`` of a ``LibvirtClient``."""
|
|
29
|
+
|
|
30
|
+
def __init__(self) -> None:
|
|
31
|
+
"""Create a daemon with no domains and one host device."""
|
|
32
|
+
self._next_domain_id = 1
|
|
33
|
+
self._domains: dict[str, _Entry[Domain]] = {}
|
|
34
|
+
self._networks: dict[str, _Entry[Network]] = {}
|
|
35
|
+
self._pools: dict[str, _Entry[Pool]] = {}
|
|
36
|
+
self._volumes: dict[tuple[str, str], Volume] = {}
|
|
37
|
+
self._secrets: dict[str, _Entry[Secret]] = {}
|
|
38
|
+
self._filters: dict[str, _Entry[Filter]] = {}
|
|
39
|
+
self._interfaces: dict[str, _Entry[HostInterface]] = {}
|
|
40
|
+
self._devices: dict[str, Device] = {}
|
|
41
|
+
self._snapshots: dict[tuple[str, str], Snapshot] = {}
|
|
42
|
+
self._snapshot_count = 0
|
|
43
|
+
self.requests: list[Request] = []
|
|
44
|
+
"""Every request served, in order: handy to see what a client sent."""
|
|
45
|
+
self._actions = self._build_actions()
|
|
46
|
+
device = Device.from_xml(_PCI_DEVICE)
|
|
47
|
+
self._devices[device.name] = device
|
|
48
|
+
|
|
49
|
+
def call(self, request: Request) -> object:
|
|
50
|
+
"""Serve one request.
|
|
51
|
+
|
|
52
|
+
:param request: the call to make.
|
|
53
|
+
:returns: the reply.
|
|
54
|
+
:raises LibvirtError: for the errors a real daemon would report.
|
|
55
|
+
"""
|
|
56
|
+
self.requests.append(request)
|
|
57
|
+
_check_against_protocol(request)
|
|
58
|
+
action = self._actions.get(request.procedure)
|
|
59
|
+
if action is None:
|
|
60
|
+
raise NotSupportedError(
|
|
61
|
+
f"the fake daemon does not know {request.procedure}",
|
|
62
|
+
code=ErrorNumber.NO_SUPPORT,
|
|
63
|
+
)
|
|
64
|
+
return action(request.arguments)
|
|
65
|
+
|
|
66
|
+
def close(self) -> None:
|
|
67
|
+
"""Close the connection (nothing to do for the fake)."""
|
|
68
|
+
|
|
69
|
+
def _build_actions(self) -> dict[str, Action]:
|
|
70
|
+
return {
|
|
71
|
+
**self._connection_actions(),
|
|
72
|
+
**self._domain_actions(),
|
|
73
|
+
**self._snapshot_actions(),
|
|
74
|
+
**self._network_actions(),
|
|
75
|
+
**self._pool_actions(),
|
|
76
|
+
**self._volume_actions(),
|
|
77
|
+
**self._secret_actions(),
|
|
78
|
+
**self._filter_actions(),
|
|
79
|
+
**self._interface_actions(),
|
|
80
|
+
**self._device_actions(),
|
|
81
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""What the clients send and receive.
|
|
2
|
+
|
|
3
|
+
A ``Request`` is one call to the daemon: the libvirt procedure name and its
|
|
4
|
+
arguments. The prototype uses plain Python values for arguments and replies;
|
|
5
|
+
the protocol layer will replace them with the generated XDR structs without
|
|
6
|
+
changing the operations (they only build ``Request`` objects).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections.abc import Generator, Mapping
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from typing import Literal, Protocol, TypeVar
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"AsyncTransport",
|
|
15
|
+
"Handle",
|
|
16
|
+
"Operation",
|
|
17
|
+
"Request",
|
|
18
|
+
"Transport",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
T = TypeVar("T")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class Request:
|
|
26
|
+
"""One call to the daemon, as it would go on the wire."""
|
|
27
|
+
|
|
28
|
+
procedure: str
|
|
29
|
+
"""The libvirt procedure, e.g. ``"domain_lookup_by_name"``."""
|
|
30
|
+
|
|
31
|
+
arguments: Mapping[str, object] = field(default_factory=dict)
|
|
32
|
+
"""The arguments by name; XML travels as ``str``."""
|
|
33
|
+
|
|
34
|
+
stream: Literal["read", "write", "both"] | None = None
|
|
35
|
+
"""For a call that opens a data stream: which way the data flows, as seen by
|
|
36
|
+
the client. The transport answers with the open stream instead of a value."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class Handle:
|
|
41
|
+
"""A server object, as the daemon names it in follow-up requests."""
|
|
42
|
+
|
|
43
|
+
name: str
|
|
44
|
+
uuid: str | None = None
|
|
45
|
+
id: int | None = None
|
|
46
|
+
parent: str | None = None
|
|
47
|
+
"""The pool of a volume or the domain of a snapshot."""
|
|
48
|
+
native: object = field(default=None, compare=False, repr=False)
|
|
49
|
+
"""The daemon's own description of the object, for the wire transport."""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Operation = Generator[Request, object, T]
|
|
53
|
+
"""A sans-I/O operation: yields ``Request``s, receives their replies, returns ``T``."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Transport(Protocol):
|
|
57
|
+
"""Sends a request and waits for the reply (used by ``LibvirtClient``)."""
|
|
58
|
+
|
|
59
|
+
def call(self, request: Request) -> object:
|
|
60
|
+
"""Send ``request`` and return the daemon's reply.
|
|
61
|
+
|
|
62
|
+
:param request: the call to make.
|
|
63
|
+
:returns: the reply: a ``Handle``, a ``list`` of them, text, a number...
|
|
64
|
+
:raises LibvirtError: if the daemon reports an error.
|
|
65
|
+
"""
|
|
66
|
+
...
|
|
67
|
+
|
|
68
|
+
def close(self) -> None:
|
|
69
|
+
"""Close the connection."""
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class AsyncTransport(Protocol):
|
|
74
|
+
"""Sends a request and awaits the reply (used by ``AsyncLibvirtClient``)."""
|
|
75
|
+
|
|
76
|
+
async def call(self, request: Request) -> object:
|
|
77
|
+
"""Send ``request`` and return the daemon's reply.
|
|
78
|
+
|
|
79
|
+
:param request: the call to make.
|
|
80
|
+
:returns: the reply: a ``Handle``, a ``list`` of them, text, a number...
|
|
81
|
+
:raises LibvirtError: if the daemon reports an error.
|
|
82
|
+
"""
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
async def close(self) -> None:
|
|
86
|
+
"""Close the connection."""
|
|
87
|
+
...
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Plain result types of the client that are not XML models."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from enum import IntEnum
|
|
5
|
+
|
|
6
|
+
from libvirtpy.rpc.typed_params import TypedValue
|
|
7
|
+
|
|
8
|
+
__all__ = ["DomainInfo", "DomainState", "JobStats", "VcpuStatus"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DomainState(IntEnum):
|
|
12
|
+
"""The run state of a domain (``virDomainState``)."""
|
|
13
|
+
|
|
14
|
+
NOSTATE = 0
|
|
15
|
+
RUNNING = 1
|
|
16
|
+
BLOCKED = 2
|
|
17
|
+
PAUSED = 3
|
|
18
|
+
SHUTDOWN = 4
|
|
19
|
+
SHUTOFF = 5
|
|
20
|
+
CRASHED = 6
|
|
21
|
+
PMSUSPENDED = 7
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class DomainInfo:
|
|
26
|
+
"""Run time numbers of a domain (``virDomainInfo``)."""
|
|
27
|
+
|
|
28
|
+
state: DomainState
|
|
29
|
+
max_memory_kib: int
|
|
30
|
+
memory_kib: int
|
|
31
|
+
vcpus: int
|
|
32
|
+
cpu_time_ns: int
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class JobStats:
|
|
37
|
+
"""The progress of a long-running job of a domain (``virDomainGetJobStats``)."""
|
|
38
|
+
|
|
39
|
+
type: int
|
|
40
|
+
"""``virDomainJobType``: 0 none, 1 bounded, 2 unbounded, 3 completed, 4 failed,
|
|
41
|
+
5 cancelled."""
|
|
42
|
+
parameters: dict[str, TypedValue]
|
|
43
|
+
"""The statistics by name, e.g. ``time_elapsed`` or ``data_total``."""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class VcpuStatus:
|
|
48
|
+
"""One virtual CPU of a running domain (``virDomainGetVcpus``)."""
|
|
49
|
+
|
|
50
|
+
number: int
|
|
51
|
+
"""The vCPU number inside the domain."""
|
|
52
|
+
state: int
|
|
53
|
+
"""``virVcpuState``: 0 offline, 1 running, 2 blocked."""
|
|
54
|
+
cpu_time_ns: int
|
|
55
|
+
"""CPU time used, in nanoseconds."""
|
|
56
|
+
running_on: int
|
|
57
|
+
"""The host CPU it runs on; negative if not running."""
|
|
58
|
+
pinned_to: list[int]
|
|
59
|
+
"""The host CPUs it may run on."""
|