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,93 @@
1
+ """Operations on the connection and the host: version, capabilities, sysinfo."""
2
+
3
+ from libvirtpy.client.operations._common import (
4
+ as_int,
5
+ as_text,
6
+ )
7
+ from libvirtpy.client.transport import Operation, Request
8
+ from libvirtpy.xml.capabilities import (
9
+ Capabilities,
10
+ DomainCapabilities,
11
+ StoragePoolCapabilities,
12
+ )
13
+ from libvirtpy.xml.sysinfo import Sysinfo
14
+
15
+ __all__ = [
16
+ "get_capabilities",
17
+ "get_domain_capabilities",
18
+ "get_hostname",
19
+ "get_storage_pool_capabilities",
20
+ "get_sysinfo",
21
+ "get_version",
22
+ ]
23
+
24
+
25
+ def get_version() -> Operation[int]:
26
+ """Return the hypervisor version.
27
+
28
+ :returns: the version as ``major * 1_000_000 + minor * 1_000 + release``.
29
+ """
30
+ return as_int((yield Request("connect_get_version")))
31
+
32
+
33
+ def get_hostname() -> Operation[str]:
34
+ """Return the host name of the machine the daemon runs on.
35
+
36
+ :returns: the host name.
37
+ """
38
+ return as_text((yield Request("connect_get_hostname")))
39
+
40
+
41
+ def get_capabilities() -> Operation[Capabilities]:
42
+ """Return what the host and its hypervisors can do.
43
+
44
+ :returns: the host capabilities.
45
+ """
46
+ xml = as_text((yield Request("connect_get_capabilities")))
47
+ return Capabilities.from_xml(xml)
48
+
49
+
50
+ def get_domain_capabilities(
51
+ *,
52
+ emulator_binary: str | None = None,
53
+ arch: str | None = None,
54
+ machine: str | None = None,
55
+ virt_type: str | None = None,
56
+ ) -> Operation[DomainCapabilities]:
57
+ """Return what a hypervisor supports for a domain.
58
+
59
+ :param emulator_binary: the emulator, or ``None`` for the default.
60
+ :param arch: the guest architecture, or ``None`` for the default.
61
+ :param machine: the machine type, or ``None`` for the default.
62
+ :param virt_type: the domain type (``kvm``, ``qemu``), or ``None``.
63
+ :returns: the domain capabilities.
64
+ """
65
+ arguments = {
66
+ "emulatorbin": emulator_binary,
67
+ "arch": arch,
68
+ "machine": machine,
69
+ "virttype": virt_type,
70
+ "flags": 0,
71
+ }
72
+ xml = as_text((yield Request("connect_get_domain_capabilities", arguments)))
73
+ return DomainCapabilities.from_xml(xml)
74
+
75
+
76
+ def get_storage_pool_capabilities() -> Operation[StoragePoolCapabilities]:
77
+ """Return what each storage pool type supports.
78
+
79
+ :returns: the storage pool capabilities.
80
+ """
81
+ xml = as_text(
82
+ (yield Request("connect_get_storage_pool_capabilities", {"flags": 0}))
83
+ )
84
+ return StoragePoolCapabilities.from_xml(xml)
85
+
86
+
87
+ def get_sysinfo() -> Operation[Sysinfo]:
88
+ """Return the host's SMBIOS data.
89
+
90
+ :returns: the host system information.
91
+ """
92
+ xml = as_text((yield Request("connect_get_sysinfo", {"flags": 0})))
93
+ return Sysinfo.from_xml(xml)
@@ -0,0 +1,256 @@
1
+ """Operations on the connection: driver information, CPU comparison, conversions."""
2
+
3
+ from libvirtpy.client.operations._common import (
4
+ as_bool,
5
+ as_int,
6
+ as_list,
7
+ as_struct,
8
+ as_text,
9
+ as_xml,
10
+ )
11
+ from libvirtpy.client.transport import Operation, Request
12
+ from libvirtpy.rpc.protocol import types
13
+ from libvirtpy.rpc.typed_params import TypedValue, from_wire, to_wire
14
+ from libvirtpy.xml.domain import Domain
15
+
16
+ __all__ = [
17
+ "baseline_cpu",
18
+ "baseline_hypervisor_cpu",
19
+ "compare_cpu",
20
+ "compare_hypervisor_cpu",
21
+ "convert_domain_from_native",
22
+ "convert_domain_to_native",
23
+ "get_all_domain_stats",
24
+ "get_cpu_model_names",
25
+ "get_driver_type",
26
+ "get_library_version",
27
+ "get_max_vcpus",
28
+ "get_uri",
29
+ "is_connection_secure",
30
+ "set_connection_identity",
31
+ "supports_feature",
32
+ ]
33
+
34
+
35
+ def get_driver_type() -> Operation[str]:
36
+ """Return the name of the hypervisor driver.
37
+
38
+ :returns: e.g. ``QEMU``.
39
+ """
40
+ return as_text((yield Request("connect_get_type")))
41
+
42
+
43
+ def get_uri() -> Operation[str]:
44
+ """Return the URI the daemon reports for the connection.
45
+
46
+ :returns: e.g. ``qemu:///system``.
47
+ """
48
+ return as_text((yield Request("connect_get_uri")))
49
+
50
+
51
+ def get_library_version() -> Operation[int]:
52
+ """Return the version of the libvirt daemon.
53
+
54
+ :returns: ``major * 1_000_000 + minor * 1_000 + release``.
55
+ """
56
+ return as_int((yield Request("connect_get_lib_version")))
57
+
58
+
59
+ def get_max_vcpus(virt_type: str | None = None) -> Operation[int]:
60
+ """Return how many virtual CPUs the hypervisor supports for one domain.
61
+
62
+ :param virt_type: the domain type (``kvm``, ``qemu``); ``None`` for the default.
63
+ :returns: the limit.
64
+ """
65
+ return as_int((yield Request("connect_get_max_vcpus", {"type": virt_type})))
66
+
67
+
68
+ def supports_feature(feature: int) -> Operation[bool]:
69
+ """Tell whether the driver supports a feature.
70
+
71
+ :param feature: ``virDrvFeature``, e.g. 3 migration v1, 7 migration v2.
72
+ :returns: ``True`` if supported.
73
+ """
74
+ return as_bool((yield Request("connect_supports_feature", {"feature": feature})))
75
+
76
+
77
+ def is_connection_secure() -> Operation[bool]:
78
+ """Tell whether the connection is encrypted or local.
79
+
80
+ :returns: ``True`` if it is secure.
81
+ """
82
+ return as_bool((yield Request("connect_is_secure")))
83
+
84
+
85
+ def compare_cpu(cpu: str, *, flags: int = 0) -> Operation[int]:
86
+ """Compare a CPU description with the CPU of the host.
87
+
88
+ :param cpu: the ``<cpu>`` XML to compare.
89
+ :param flags: ``virConnectCompareCPUFlags``: fail if incomparable, ...
90
+ :returns: ``virCPUCompareResult``: 0 incompatible, 1 identical, 2 superset.
91
+ """
92
+ reply = yield Request("connect_compare_cpu", {"xml": cpu, "flags": flags})
93
+ return as_int(reply)
94
+
95
+
96
+ def baseline_cpu(cpus: list[str], *, flags: int = 0) -> Operation[str]:
97
+ """Compute a CPU that all the given CPUs can run.
98
+
99
+ :param cpus: the ``<cpu>`` XML of each CPU.
100
+ :param flags: ``virConnectBaselineCPUFlags``: expand features, migratable.
101
+ :returns: the common ``<cpu>`` XML.
102
+ """
103
+ reply = yield Request("connect_baseline_cpu", {"xml_cpus": cpus, "flags": flags})
104
+ return as_text(reply)
105
+
106
+
107
+ def get_cpu_model_names(arch: str) -> Operation[list[str]]:
108
+ """List the CPU models known for an architecture.
109
+
110
+ :param arch: e.g. ``x86_64``.
111
+ :returns: the model names.
112
+ """
113
+ reply = yield Request(
114
+ "connect_get_cpu_model_names", {"arch": arch, "need_results": 1, "flags": 0}
115
+ )
116
+ return [as_text(name) for name in as_list(reply)]
117
+
118
+
119
+ def compare_hypervisor_cpu(
120
+ cpu: str,
121
+ *,
122
+ emulator: str | None = None,
123
+ arch: str | None = None,
124
+ machine: str | None = None,
125
+ virt_type: str | None = None,
126
+ flags: int = 0,
127
+ ) -> Operation[int]:
128
+ """Compare a CPU description with what the hypervisor can provide.
129
+
130
+ :param cpu: the ``<cpu>`` XML to compare.
131
+ :param emulator: the emulator binary, or ``None`` for the default.
132
+ :param arch: the architecture, or ``None`` for the default.
133
+ :param machine: the machine type, or ``None`` for the default.
134
+ :param virt_type: the domain type, or ``None`` for the default.
135
+ :param flags: ``virConnectCompareCPUFlags``.
136
+ :returns: ``virCPUCompareResult``: 0 incompatible, 1 identical, 2 superset.
137
+ """
138
+ reply = yield Request(
139
+ "connect_compare_hypervisor_cpu",
140
+ {
141
+ "emulator": emulator,
142
+ "arch": arch,
143
+ "machine": machine,
144
+ "virttype": virt_type,
145
+ "xml_cpu": cpu,
146
+ "flags": flags,
147
+ },
148
+ )
149
+ return as_int(reply)
150
+
151
+
152
+ def baseline_hypervisor_cpu(
153
+ cpus: list[str],
154
+ *,
155
+ emulator: str | None = None,
156
+ arch: str | None = None,
157
+ machine: str | None = None,
158
+ virt_type: str | None = None,
159
+ flags: int = 0,
160
+ ) -> Operation[str]:
161
+ """Compute a CPU that the hypervisor can provide and all the given CPUs have.
162
+
163
+ :param cpus: the ``<cpu>`` XML of each CPU.
164
+ :param emulator: the emulator binary, or ``None`` for the default.
165
+ :param arch: the architecture, or ``None`` for the default.
166
+ :param machine: the machine type, or ``None`` for the default.
167
+ :param virt_type: the domain type, or ``None`` for the default.
168
+ :param flags: ``virConnectBaselineCPUFlags``.
169
+ :returns: the common ``<cpu>`` XML.
170
+ """
171
+ reply = yield Request(
172
+ "connect_baseline_hypervisor_cpu",
173
+ {
174
+ "emulator": emulator,
175
+ "arch": arch,
176
+ "machine": machine,
177
+ "virttype": virt_type,
178
+ "xml_cpus": cpus,
179
+ "flags": flags,
180
+ },
181
+ )
182
+ return as_text(reply)
183
+
184
+
185
+ def convert_domain_from_native(
186
+ native_format: str, native_config: str, *, flags: int = 0
187
+ ) -> Operation[Domain]:
188
+ """Convert a hypervisor's own configuration to a domain description.
189
+
190
+ :param native_format: e.g. ``qemu-argv``.
191
+ :param native_config: the configuration in that format.
192
+ :param flags: reserved, 0.
193
+ :returns: the domain.
194
+ """
195
+ reply = yield Request(
196
+ "connect_domain_xml_from_native",
197
+ {
198
+ "native_format": native_format,
199
+ "native_config": native_config,
200
+ "flags": flags,
201
+ },
202
+ )
203
+ return Domain.from_xml(as_text(reply))
204
+
205
+
206
+ def convert_domain_to_native(
207
+ native_format: str, domain: Domain | str, *, flags: int = 0
208
+ ) -> Operation[str]:
209
+ """Convert a domain description to a hypervisor's own configuration.
210
+
211
+ :param native_format: e.g. ``qemu-argv``.
212
+ :param domain: the domain, as a model or XML.
213
+ :param flags: reserved, 0.
214
+ :returns: the configuration in that format (for QEMU, the command line).
215
+ """
216
+ reply = yield Request(
217
+ "connect_domain_xml_to_native",
218
+ {
219
+ "native_format": native_format,
220
+ "domain_xml": as_xml(domain),
221
+ "flags": flags,
222
+ },
223
+ )
224
+ return as_text(reply)
225
+
226
+
227
+ def get_all_domain_stats(
228
+ stats: int = 0, *, flags: int = 0
229
+ ) -> Operation[dict[str, dict[str, TypedValue]]]:
230
+ """Return the statistics of all domains in one call.
231
+
232
+ :param stats: ``virDomainStatsTypes`` bits (state, cpu, balloon, vcpu,
233
+ interface,
234
+ block, perf...); 0 for all.
235
+ :param flags: ``virConnectGetAllDomainStatsFlags``: which domains to include.
236
+ :returns: for each domain name its statistics by name (``state.state``,
237
+ ``balloon.current``...).
238
+ """
239
+ reply = yield Request(
240
+ "connect_get_all_domain_stats", {"doms": [], "stats": stats, "flags": flags}
241
+ )
242
+ records = [as_struct(item, types.DomainStatsRecord) for item in as_list(reply)]
243
+ return {record.dom.name: from_wire(record.params) for record in records}
244
+
245
+
246
+ def set_connection_identity(
247
+ parameters: dict[str, TypedValue], *, flags: int = 0
248
+ ) -> Operation[None]:
249
+ """Tell the daemon who the client acts for (when it connects for someone else).
250
+
251
+ :param parameters: e.g. ``user-name``, ``unix-user-id``, ``selinux-context``.
252
+ :param flags: reserved, 0.
253
+ """
254
+ yield Request(
255
+ "connect_set_identity", {"params": to_wire(parameters), "flags": flags}
256
+ )
@@ -0,0 +1,306 @@
1
+ """Operations on domains (virtual machines): lifecycle, state, devices."""
2
+
3
+ from libvirtpy.client.operations._common import (
4
+ DOMAINS_ACTIVE,
5
+ DOMAINS_INACTIVE,
6
+ as_int,
7
+ as_xml,
8
+ fetch_model,
9
+ fetch_models,
10
+ many_handles,
11
+ one_handle,
12
+ )
13
+ from libvirtpy.client.references import (
14
+ DomainRef,
15
+ domain_lookup,
16
+ )
17
+ from libvirtpy.client.transport import Operation, Request
18
+ from libvirtpy.client.types import DomainInfo, DomainState
19
+ from libvirtpy.xml._base import LibvirtXmlModel
20
+ from libvirtpy.xml.domain import Domain
21
+
22
+ __all__ = [
23
+ "attach_domain_device",
24
+ "create_domain",
25
+ "define_domain",
26
+ "destroy_domain",
27
+ "detach_domain_device",
28
+ "get_domain_autostart",
29
+ "get_domain_info",
30
+ "get_domain_state",
31
+ "list_domains",
32
+ "lookup_domain",
33
+ "reboot_domain",
34
+ "reset_domain",
35
+ "resume_domain",
36
+ "set_domain_autostart",
37
+ "set_domain_memory",
38
+ "set_domain_vcpus",
39
+ "shutdown_domain",
40
+ "start_domain",
41
+ "suspend_domain",
42
+ "undefine_domain",
43
+ "update_domain_device",
44
+ ]
45
+
46
+
47
+ def lookup_domain(domain: DomainRef) -> Operation[Domain]:
48
+ """Return the configuration of a domain.
49
+
50
+ :param domain: a runtime id, name, UUID or ``Domain`` model.
51
+ :returns: the domain, with the live state (``id``) if it is running.
52
+ :raises NoDomainError: if there is no such domain.
53
+ """
54
+ handle = yield from one_handle(domain_lookup(domain))
55
+ return (yield from fetch_model("domain_get_xml_desc", handle, Domain))
56
+
57
+
58
+ def list_domains(*, active: bool | None = None) -> Operation[list[Domain]]:
59
+ """Return the domains, one request per domain for its XML.
60
+
61
+ :param active: ``True`` for running domains only, ``False`` for the others,
62
+ ``None`` for all.
63
+ :returns: the domains.
64
+ """
65
+ flags = {True: DOMAINS_ACTIVE, False: DOMAINS_INACTIVE, None: 0}[active]
66
+ handles = yield from many_handles(
67
+ Request("connect_list_all_domains", {"need_results": 1, "flags": flags})
68
+ )
69
+ return (yield from fetch_models("domain_get_xml_desc", handles, Domain))
70
+
71
+
72
+ def define_domain(domain: Domain | str, *, flags: int = 0) -> Operation[Domain]:
73
+ """Define (or redefine) a persistent domain without starting it.
74
+
75
+ :param domain: the configuration, as a model or XML text.
76
+ :param flags: ``virDomainDefineFlags``.
77
+ :returns: the stored configuration, with what libvirt filled in (UUID, ...).
78
+ """
79
+ xml = as_xml(domain)
80
+ handle = yield from one_handle(
81
+ Request("domain_define_xml_flags", {"xml": xml, "flags": flags})
82
+ )
83
+ return (yield from fetch_model("domain_get_xml_desc", handle, Domain))
84
+
85
+
86
+ def create_domain(domain: Domain | str, *, flags: int = 0) -> Operation[Domain]:
87
+ """Start a transient domain: it disappears when it stops.
88
+
89
+ :param domain: the configuration, as a model or XML text.
90
+ :param flags: ``virDomainCreateFlags``.
91
+ :returns: the running domain.
92
+ """
93
+ xml = as_xml(domain)
94
+ handle = yield from one_handle(
95
+ Request("domain_create_xml", {"xml_desc": xml, "flags": flags})
96
+ )
97
+ return (yield from fetch_model("domain_get_xml_desc", handle, Domain))
98
+
99
+
100
+ def undefine_domain(domain: DomainRef, *, flags: int = 0) -> Operation[None]:
101
+ """Remove a persistent domain's definition.
102
+
103
+ :param domain: the domain.
104
+ :param flags: ``virDomainUndefineFlagsValues``.
105
+ :raises OperationInvalidError: if the domain is running.
106
+ """
107
+ handle = yield from one_handle(domain_lookup(domain))
108
+ yield Request("domain_undefine_flags", {"dom": handle, "flags": flags})
109
+
110
+
111
+ def start_domain(domain: DomainRef, *, flags: int = 0) -> Operation[Domain]:
112
+ """Start a defined domain.
113
+
114
+ :param domain: the domain.
115
+ :param flags: ``virDomainCreateFlags``, e.g. start paused.
116
+ :returns: the domain, now running (it has an ``id``).
117
+ :raises OperationInvalidError: if the domain is already running.
118
+ """
119
+ handle = yield from one_handle(domain_lookup(domain))
120
+ yield Request("domain_create_with_flags", {"dom": handle, "flags": flags})
121
+ return (yield from fetch_model("domain_get_xml_desc", handle, Domain))
122
+
123
+
124
+ def shutdown_domain(domain: DomainRef, *, flags: int = 0) -> Operation[None]:
125
+ """Ask the guest to shut down cleanly.
126
+
127
+ :param domain: the domain.
128
+ :param flags: ``virDomainShutdownFlagValues``: how to ask (ACPI, guest
129
+ agent...).
130
+ :raises OperationInvalidError: if the domain is not running.
131
+ """
132
+ handle = yield from one_handle(domain_lookup(domain))
133
+ yield Request("domain_shutdown_flags", {"dom": handle, "flags": flags})
134
+
135
+
136
+ def destroy_domain(domain: DomainRef, *, flags: int = 0) -> Operation[None]:
137
+ """Stop a domain at once, like pulling the power.
138
+
139
+ :param domain: the domain.
140
+ :param flags: ``virDomainDestroyFlagsValues``.
141
+ :raises OperationInvalidError: if the domain is not running.
142
+ """
143
+ handle = yield from one_handle(domain_lookup(domain))
144
+ yield Request("domain_destroy_flags", {"dom": handle, "flags": flags})
145
+
146
+
147
+ def reboot_domain(domain: DomainRef, *, flags: int = 0) -> Operation[None]:
148
+ """Ask the guest to reboot.
149
+
150
+ :param domain: the domain.
151
+ :param flags: ``virDomainShutdownFlagValues``.
152
+ :raises OperationInvalidError: if the domain is not running.
153
+ """
154
+ handle = yield from one_handle(domain_lookup(domain))
155
+ yield Request("domain_reboot", {"dom": handle, "flags": flags})
156
+
157
+
158
+ def suspend_domain(domain: DomainRef) -> Operation[None]:
159
+ """Pause a running domain.
160
+
161
+ :param domain: the domain.
162
+ :raises OperationInvalidError: if the domain is not running.
163
+ """
164
+ handle = yield from one_handle(domain_lookup(domain))
165
+ yield Request("domain_suspend", {"dom": handle})
166
+
167
+
168
+ def resume_domain(domain: DomainRef) -> Operation[None]:
169
+ """Resume a paused domain.
170
+
171
+ :param domain: the domain.
172
+ :raises OperationInvalidError: if the domain is not paused.
173
+ """
174
+ handle = yield from one_handle(domain_lookup(domain))
175
+ yield Request("domain_resume", {"dom": handle})
176
+
177
+
178
+ def reset_domain(domain: DomainRef) -> Operation[None]:
179
+ """Reset a running domain, like pressing the reset button.
180
+
181
+ :param domain: the domain.
182
+ :raises OperationInvalidError: if the domain is not running.
183
+ """
184
+ handle = yield from one_handle(domain_lookup(domain))
185
+ yield Request("domain_reset", {"dom": handle, "flags": 0})
186
+
187
+
188
+ def get_domain_state(domain: DomainRef) -> Operation[DomainState]:
189
+ """Return the run state of a domain.
190
+
191
+ :param domain: the domain.
192
+ :returns: the state.
193
+ """
194
+ handle = yield from one_handle(domain_lookup(domain))
195
+ return DomainState(
196
+ as_int((yield Request("domain_get_state", {"dom": handle, "flags": 0})))
197
+ )
198
+
199
+
200
+ def get_domain_info(domain: DomainRef) -> Operation[DomainInfo]:
201
+ """Return the run time numbers of a domain.
202
+
203
+ :param domain: the domain.
204
+ :returns: state, memory, vCPU count and CPU time.
205
+ """
206
+ handle = yield from one_handle(domain_lookup(domain))
207
+ reply = yield Request("domain_get_info", {"dom": handle})
208
+ if not isinstance(reply, DomainInfo):
209
+ raise TypeError(f"expected DomainInfo, got {reply!r}")
210
+ return reply
211
+
212
+
213
+ def set_domain_vcpus(
214
+ domain: DomainRef, count: int, *, flags: int = 0
215
+ ) -> Operation[Domain]:
216
+ """Change the number of virtual CPUs.
217
+
218
+ :param domain: the domain.
219
+ :param count: the new number of vCPUs.
220
+ :param flags: ``virDomainVcpuFlags``: live, config, maximum.
221
+ :returns: the domain with the new setting.
222
+ """
223
+ handle = yield from one_handle(domain_lookup(domain))
224
+ yield Request(
225
+ "domain_set_vcpus_flags", {"dom": handle, "nvcpus": count, "flags": flags}
226
+ )
227
+ return (yield from fetch_model("domain_get_xml_desc", handle, Domain))
228
+
229
+
230
+ def set_domain_memory(
231
+ domain: DomainRef, kib: int, *, flags: int = 0
232
+ ) -> Operation[Domain]:
233
+ """Change the memory of a domain.
234
+
235
+ :param domain: the domain.
236
+ :param kib: the new amount, in KiB.
237
+ :param flags: ``virDomainMemoryModFlags``: live, config, maximum.
238
+ :returns: the domain with the new setting.
239
+ """
240
+ handle = yield from one_handle(domain_lookup(domain))
241
+ yield Request(
242
+ "domain_set_memory_flags", {"dom": handle, "memory": kib, "flags": flags}
243
+ )
244
+ return (yield from fetch_model("domain_get_xml_desc", handle, Domain))
245
+
246
+
247
+ def get_domain_autostart(domain: DomainRef) -> Operation[bool]:
248
+ """Tell whether a domain starts with the host.
249
+
250
+ :param domain: the domain.
251
+ :returns: ``True`` if it starts at boot.
252
+ """
253
+ handle = yield from one_handle(domain_lookup(domain))
254
+ return bool(as_int((yield Request("domain_get_autostart", {"dom": handle}))))
255
+
256
+
257
+ def set_domain_autostart(domain: DomainRef, enabled: bool) -> Operation[None]:
258
+ """Make a domain start (or not) with the host.
259
+
260
+ :param domain: the domain.
261
+ :param enabled: ``True`` to start it at boot.
262
+ """
263
+ handle = yield from one_handle(domain_lookup(domain))
264
+ yield Request("domain_set_autostart", {"dom": handle, "autostart": int(enabled)})
265
+
266
+
267
+ def attach_domain_device(
268
+ domain: DomainRef, device: LibvirtXmlModel | str, *, flags: int = 0
269
+ ) -> Operation[None]:
270
+ """Plug a device into a domain.
271
+
272
+ :param domain: the domain.
273
+ :param device: the device, as a model (``Disk``, ``Interface``, ...) or XML.
274
+ :param flags: ``virDomainDeviceModifyFlags``: live, config.
275
+ """
276
+ handle = yield from one_handle(domain_lookup(domain))
277
+ arguments = {"dom": handle, "xml": as_xml(device), "flags": flags}
278
+ yield Request("domain_attach_device_flags", arguments)
279
+
280
+
281
+ def detach_domain_device(
282
+ domain: DomainRef, device: LibvirtXmlModel | str, *, flags: int = 0
283
+ ) -> Operation[None]:
284
+ """Unplug a device from a domain.
285
+
286
+ :param domain: the domain.
287
+ :param device: the device, as a model or XML.
288
+ :param flags: ``virDomainDeviceModifyFlags``: live, config.
289
+ """
290
+ handle = yield from one_handle(domain_lookup(domain))
291
+ arguments = {"dom": handle, "xml": as_xml(device), "flags": flags}
292
+ yield Request("domain_detach_device_flags", arguments)
293
+
294
+
295
+ def update_domain_device(
296
+ domain: DomainRef, device: LibvirtXmlModel | str, *, flags: int = 0
297
+ ) -> Operation[None]:
298
+ """Change a device of a domain.
299
+
300
+ :param domain: the domain.
301
+ :param device: the new device configuration, as a model or XML.
302
+ :param flags: ``virDomainDeviceModifyFlags``: live, config.
303
+ """
304
+ handle = yield from one_handle(domain_lookup(domain))
305
+ arguments = {"dom": handle, "xml": as_xml(device), "flags": flags}
306
+ yield Request("domain_update_device_flags", arguments)