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,494 @@
|
|
|
1
|
+
"""Operations that tune the CPU, memory and scheduling of a domain."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
|
|
5
|
+
from libvirtpy.client.operations._common import (
|
|
6
|
+
as_bytes,
|
|
7
|
+
as_int,
|
|
8
|
+
as_list,
|
|
9
|
+
as_params,
|
|
10
|
+
as_struct,
|
|
11
|
+
as_text,
|
|
12
|
+
get_typed_parameters,
|
|
13
|
+
on_domain,
|
|
14
|
+
)
|
|
15
|
+
from libvirtpy.client.references import DomainRef
|
|
16
|
+
from libvirtpy.client.transport import Operation, Request
|
|
17
|
+
from libvirtpy.client.types import VcpuStatus
|
|
18
|
+
from libvirtpy.rpc.cpumap import from_cpumap, map_length, to_cpumap
|
|
19
|
+
from libvirtpy.rpc.protocol import types
|
|
20
|
+
from libvirtpy.rpc.typed_params import TypedValue, from_wire, to_wire
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"add_domain_iothread",
|
|
24
|
+
"delete_domain_iothread",
|
|
25
|
+
"get_domain_blkio_parameters",
|
|
26
|
+
"get_domain_cpu_stats",
|
|
27
|
+
"get_domain_emulator_pin",
|
|
28
|
+
"get_domain_guest_vcpus",
|
|
29
|
+
"get_domain_memory_parameters",
|
|
30
|
+
"get_domain_memory_stats",
|
|
31
|
+
"get_domain_numa_parameters",
|
|
32
|
+
"get_domain_scheduler_parameters",
|
|
33
|
+
"get_domain_scheduler_type",
|
|
34
|
+
"get_domain_vcpu_count",
|
|
35
|
+
"get_domain_vcpu_pins",
|
|
36
|
+
"get_domain_vcpus",
|
|
37
|
+
"peek_domain_memory",
|
|
38
|
+
"pin_domain_emulator",
|
|
39
|
+
"pin_domain_iothread",
|
|
40
|
+
"pin_domain_vcpu",
|
|
41
|
+
"set_domain_blkio_parameters",
|
|
42
|
+
"set_domain_guest_vcpus",
|
|
43
|
+
"set_domain_iothread_parameters",
|
|
44
|
+
"set_domain_max_memory",
|
|
45
|
+
"set_domain_memory_parameters",
|
|
46
|
+
"set_domain_numa_parameters",
|
|
47
|
+
"set_domain_scheduler_parameters",
|
|
48
|
+
"set_domain_vcpu",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_domain_vcpu_count(domain: DomainRef, *, flags: int = 0) -> Operation[int]:
|
|
53
|
+
"""Return the number of virtual CPUs of a domain.
|
|
54
|
+
|
|
55
|
+
:param domain: the domain.
|
|
56
|
+
:param flags: ``virDomainVcpuFlags``: live, config, maximum, guest.
|
|
57
|
+
:returns: the count.
|
|
58
|
+
"""
|
|
59
|
+
return as_int((yield from on_domain(domain, "domain_get_vcpus_flags", flags=flags)))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get_domain_vcpus(domain: DomainRef) -> Operation[list[VcpuStatus]]:
|
|
63
|
+
"""Return the state of each virtual CPU of a running domain.
|
|
64
|
+
|
|
65
|
+
:param domain: the domain.
|
|
66
|
+
:returns: one entry per vCPU, with the host CPUs it is pinned to.
|
|
67
|
+
"""
|
|
68
|
+
count = as_int((yield from on_domain(domain, "domain_get_vcpus_flags", flags=1)))
|
|
69
|
+
length = yield from _host_map_length()
|
|
70
|
+
reply = yield from on_domain(
|
|
71
|
+
domain, "domain_get_vcpus", maxinfo=count, maplen=length
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
vcpus = as_struct(reply, types.DomainGetVcpusRet)
|
|
75
|
+
maps = [vcpus.cpumaps[i * length : (i + 1) * length] for i in range(count)]
|
|
76
|
+
return [
|
|
77
|
+
VcpuStatus(
|
|
78
|
+
item.number, item.state, item.cpu_time, item.cpu, from_cpumap(bitmap)
|
|
79
|
+
)
|
|
80
|
+
for item, bitmap in zip(vcpus.info, maps, strict=False)
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def pin_domain_vcpu(
|
|
85
|
+
domain: DomainRef, vcpu: int, cpus: Iterable[int], *, flags: int = 0
|
|
86
|
+
) -> Operation[None]:
|
|
87
|
+
"""Restrict a virtual CPU to some host CPUs.
|
|
88
|
+
|
|
89
|
+
:param domain: the domain.
|
|
90
|
+
:param vcpu: the vCPU number.
|
|
91
|
+
:param cpus: the host CPU numbers it may run on.
|
|
92
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
93
|
+
"""
|
|
94
|
+
yield from on_domain(
|
|
95
|
+
domain,
|
|
96
|
+
"domain_pin_vcpu_flags",
|
|
97
|
+
vcpu=vcpu,
|
|
98
|
+
cpumap=to_cpumap(cpus),
|
|
99
|
+
flags=flags,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def get_domain_vcpu_pins(
|
|
104
|
+
domain: DomainRef, *, flags: int = 0
|
|
105
|
+
) -> Operation[list[list[int]]]:
|
|
106
|
+
"""Return the host CPUs each virtual CPU may run on.
|
|
107
|
+
|
|
108
|
+
:param domain: the domain.
|
|
109
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
110
|
+
:returns: for each vCPU, the host CPU numbers.
|
|
111
|
+
"""
|
|
112
|
+
count = as_int((yield from on_domain(domain, "domain_get_vcpus_flags", flags=1)))
|
|
113
|
+
length = yield from _host_map_length()
|
|
114
|
+
reply = yield from on_domain(
|
|
115
|
+
domain, "domain_get_vcpu_pin_info", ncpumaps=count, maplen=length, flags=flags
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
pins = as_struct(reply, types.DomainGetVcpuPinInfoRet)
|
|
119
|
+
return [
|
|
120
|
+
from_cpumap(pins.cpumaps[i * length : (i + 1) * length])
|
|
121
|
+
for i in range(pins.num)
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def pin_domain_emulator(
|
|
126
|
+
domain: DomainRef, cpus: Iterable[int], *, flags: int = 0
|
|
127
|
+
) -> Operation[None]:
|
|
128
|
+
"""Restrict the emulator threads of a domain to some host CPUs.
|
|
129
|
+
|
|
130
|
+
:param domain: the domain.
|
|
131
|
+
:param cpus: the host CPU numbers.
|
|
132
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
133
|
+
"""
|
|
134
|
+
yield from on_domain(
|
|
135
|
+
domain, "domain_pin_emulator", cpumap=to_cpumap(cpus), flags=flags
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def get_domain_emulator_pin(
|
|
140
|
+
domain: DomainRef, *, flags: int = 0
|
|
141
|
+
) -> Operation[list[int]]:
|
|
142
|
+
"""Return the host CPUs the emulator threads of a domain may run on.
|
|
143
|
+
|
|
144
|
+
:param domain: the domain.
|
|
145
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
146
|
+
:returns: the host CPU numbers.
|
|
147
|
+
"""
|
|
148
|
+
length = yield from _host_map_length()
|
|
149
|
+
reply = yield from on_domain(
|
|
150
|
+
domain, "domain_get_emulator_pin_info", maplen=length, flags=flags
|
|
151
|
+
)
|
|
152
|
+
return from_cpumap(as_bytes(reply))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def get_domain_guest_vcpus(
|
|
156
|
+
domain: DomainRef, *, flags: int = 0
|
|
157
|
+
) -> Operation[dict[str, TypedValue]]:
|
|
158
|
+
"""Ask the guest agent which virtual CPUs the guest has online.
|
|
159
|
+
|
|
160
|
+
:param domain: the domain.
|
|
161
|
+
:param flags: reserved, 0.
|
|
162
|
+
:returns: ``vcpus``, ``online``, ``offlinable`` as CPU lists such as ``0-3``.
|
|
163
|
+
"""
|
|
164
|
+
reply = yield from on_domain(domain, "domain_get_guest_vcpus", flags=flags)
|
|
165
|
+
return as_params(reply)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def set_domain_guest_vcpus(
|
|
169
|
+
domain: DomainRef, cpus: str, online: bool, *, flags: int = 0
|
|
170
|
+
) -> Operation[None]:
|
|
171
|
+
"""Bring virtual CPUs of the guest online or offline, through the guest agent.
|
|
172
|
+
|
|
173
|
+
:param domain: the domain.
|
|
174
|
+
:param cpus: the vCPUs as a list such as ``0-3,6``.
|
|
175
|
+
:param online: ``True`` to bring them online, ``False`` offline.
|
|
176
|
+
:param flags: reserved, 0.
|
|
177
|
+
"""
|
|
178
|
+
yield from on_domain(
|
|
179
|
+
domain, "domain_set_guest_vcpus", cpumap=cpus, state=int(online), flags=flags
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def set_domain_vcpu(
|
|
184
|
+
domain: DomainRef, cpus: str, enabled: bool, *, flags: int = 0
|
|
185
|
+
) -> Operation[None]:
|
|
186
|
+
"""Enable or disable individual virtual CPUs (hotplug).
|
|
187
|
+
|
|
188
|
+
:param domain: the domain.
|
|
189
|
+
:param cpus: the vCPUs as a list such as ``0-3,6``.
|
|
190
|
+
:param enabled: ``True`` to enable them, ``False`` to disable.
|
|
191
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
192
|
+
"""
|
|
193
|
+
yield from on_domain(
|
|
194
|
+
domain, "domain_set_vcpu", cpumap=cpus, state=int(enabled), flags=flags
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def set_domain_max_memory(domain: DomainRef, kib: int) -> Operation[None]:
|
|
199
|
+
"""Set the maximum memory of a domain, in its next configuration.
|
|
200
|
+
|
|
201
|
+
:param domain: the domain.
|
|
202
|
+
:param kib: the limit in KiB.
|
|
203
|
+
"""
|
|
204
|
+
yield from on_domain(domain, "domain_set_max_memory", memory=kib)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def get_domain_memory_stats(
|
|
208
|
+
domain: DomainRef, *, max_stats: int = 16, flags: int = 0
|
|
209
|
+
) -> Operation[list[types.DomainMemoryStat]]:
|
|
210
|
+
"""Return the memory statistics the balloon driver reports.
|
|
211
|
+
|
|
212
|
+
:param domain: the domain.
|
|
213
|
+
:param max_stats: how many statistics to ask for.
|
|
214
|
+
:param flags: reserved, 0.
|
|
215
|
+
:returns: ``(tag, val)`` pairs; ``tag`` is ``virDomainMemoryStatTags``
|
|
216
|
+
(0 swap in, 1 swap out, 4 unused, 5 available, 7 rss...), ``val`` in KiB.
|
|
217
|
+
"""
|
|
218
|
+
reply = yield from on_domain(
|
|
219
|
+
domain, "domain_memory_stats", max_stats=max_stats, flags=flags
|
|
220
|
+
)
|
|
221
|
+
return [as_struct(item, types.DomainMemoryStat) for item in as_list(reply)]
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def peek_domain_memory(
|
|
225
|
+
domain: DomainRef, offset: int, size: int, *, flags: int = 1
|
|
226
|
+
) -> Operation[bytes]:
|
|
227
|
+
"""Read memory of a domain.
|
|
228
|
+
|
|
229
|
+
:param domain: the domain.
|
|
230
|
+
:param offset: the address to start at.
|
|
231
|
+
:param size: how many bytes.
|
|
232
|
+
:param flags: ``virDomainMemoryFlag``: 1 virtual, 2 physical addresses.
|
|
233
|
+
:returns: the bytes.
|
|
234
|
+
"""
|
|
235
|
+
reply = yield from on_domain(
|
|
236
|
+
domain, "domain_memory_peek", offset=offset, size=size, flags=flags
|
|
237
|
+
)
|
|
238
|
+
return as_bytes(reply)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def get_domain_memory_parameters(
|
|
242
|
+
domain: DomainRef, *, flags: int = 0
|
|
243
|
+
) -> Operation[dict[str, TypedValue]]:
|
|
244
|
+
"""Return the memory tuning of a domain.
|
|
245
|
+
|
|
246
|
+
:param domain: the domain.
|
|
247
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
248
|
+
:returns: e.g. ``hard_limit``, ``soft_limit``, ``swap_hard_limit`` in KiB.
|
|
249
|
+
"""
|
|
250
|
+
return (
|
|
251
|
+
yield from get_typed_parameters(domain, "domain_get_memory_parameters", flags)
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def set_domain_memory_parameters(
|
|
256
|
+
domain: DomainRef, parameters: dict[str, TypedValue], *, flags: int = 0
|
|
257
|
+
) -> Operation[None]:
|
|
258
|
+
"""Change the memory tuning of a domain.
|
|
259
|
+
|
|
260
|
+
:param domain: the domain.
|
|
261
|
+
:param parameters: e.g. ``{"hard_limit": 4194304}``; KiB.
|
|
262
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
263
|
+
"""
|
|
264
|
+
yield from on_domain(
|
|
265
|
+
domain, "domain_set_memory_parameters", params=to_wire(parameters), flags=flags
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def get_domain_numa_parameters(
|
|
270
|
+
domain: DomainRef, *, flags: int = 0
|
|
271
|
+
) -> Operation[dict[str, TypedValue]]:
|
|
272
|
+
"""Return the NUMA tuning of a domain.
|
|
273
|
+
|
|
274
|
+
:param domain: the domain.
|
|
275
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
276
|
+
:returns: ``numa_mode`` and ``numa_nodeset``.
|
|
277
|
+
"""
|
|
278
|
+
return (
|
|
279
|
+
yield from get_typed_parameters(domain, "domain_get_numa_parameters", flags)
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def set_domain_numa_parameters(
|
|
284
|
+
domain: DomainRef, parameters: dict[str, TypedValue], *, flags: int = 0
|
|
285
|
+
) -> Operation[None]:
|
|
286
|
+
"""Change the NUMA tuning of a domain.
|
|
287
|
+
|
|
288
|
+
:param domain: the domain.
|
|
289
|
+
:param parameters: ``numa_mode`` (``virDomainNumatuneMemMode``) and
|
|
290
|
+
``numa_nodeset`` (e.g. ``"0-1"``).
|
|
291
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
292
|
+
"""
|
|
293
|
+
yield from on_domain(
|
|
294
|
+
domain, "domain_set_numa_parameters", params=to_wire(parameters), flags=flags
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def get_domain_blkio_parameters(
|
|
299
|
+
domain: DomainRef, *, flags: int = 0
|
|
300
|
+
) -> Operation[dict[str, TypedValue]]:
|
|
301
|
+
"""Return the block I/O tuning of a domain.
|
|
302
|
+
|
|
303
|
+
:param domain: the domain.
|
|
304
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
305
|
+
:returns: ``weight``, ``device_weight``, ``device_read_iops_sec``...
|
|
306
|
+
"""
|
|
307
|
+
return (
|
|
308
|
+
yield from get_typed_parameters(domain, "domain_get_blkio_parameters", flags)
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def set_domain_blkio_parameters(
|
|
313
|
+
domain: DomainRef, parameters: dict[str, TypedValue], *, flags: int = 0
|
|
314
|
+
) -> Operation[None]:
|
|
315
|
+
"""Change the block I/O tuning of a domain.
|
|
316
|
+
|
|
317
|
+
:param domain: the domain.
|
|
318
|
+
:param parameters: e.g. ``{"weight": 500}``.
|
|
319
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
320
|
+
"""
|
|
321
|
+
yield from on_domain(
|
|
322
|
+
domain, "domain_set_blkio_parameters", params=to_wire(parameters), flags=flags
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def get_domain_scheduler_type(domain: DomainRef) -> Operation[str]:
|
|
327
|
+
"""Return the name of the CPU scheduler tuning of a domain.
|
|
328
|
+
|
|
329
|
+
:param domain: the domain.
|
|
330
|
+
:returns: e.g. ``posix`` for the Linux scheduler.
|
|
331
|
+
"""
|
|
332
|
+
reply = yield from on_domain(domain, "domain_get_scheduler_type")
|
|
333
|
+
return as_text(as_struct(reply, types.DomainGetSchedulerTypeRet).type)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def get_domain_scheduler_parameters(
|
|
337
|
+
domain: DomainRef, *, flags: int = 0
|
|
338
|
+
) -> Operation[dict[str, TypedValue]]:
|
|
339
|
+
"""Return the CPU scheduler tuning of a domain.
|
|
340
|
+
|
|
341
|
+
:param domain: the domain.
|
|
342
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
343
|
+
:returns: ``cpu_shares``, ``vcpu_period``, ``vcpu_quota``, ...
|
|
344
|
+
"""
|
|
345
|
+
reply = yield from on_domain(domain, "domain_get_scheduler_type")
|
|
346
|
+
count = as_struct(reply, types.DomainGetSchedulerTypeRet).nparams
|
|
347
|
+
parameters = yield from on_domain(
|
|
348
|
+
domain, "domain_get_scheduler_parameters_flags", nparams=count, flags=flags
|
|
349
|
+
)
|
|
350
|
+
return as_params(parameters)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def set_domain_scheduler_parameters(
|
|
354
|
+
domain: DomainRef, parameters: dict[str, TypedValue], *, flags: int = 0
|
|
355
|
+
) -> Operation[None]:
|
|
356
|
+
"""Change the CPU scheduler tuning of a domain.
|
|
357
|
+
|
|
358
|
+
:param domain: the domain.
|
|
359
|
+
:param parameters: e.g. ``{"cpu_shares": 2048, "vcpu_quota": 50000}``.
|
|
360
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
361
|
+
"""
|
|
362
|
+
yield from on_domain(
|
|
363
|
+
domain,
|
|
364
|
+
"domain_set_scheduler_parameters_flags",
|
|
365
|
+
params=to_wire(parameters),
|
|
366
|
+
flags=flags,
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def get_domain_cpu_stats(
|
|
371
|
+
domain: DomainRef, *, start_cpu: int = -1, count: int = 1, flags: int = 0
|
|
372
|
+
) -> Operation[list[dict[str, TypedValue]]]:
|
|
373
|
+
"""Return the CPU time statistics of a domain.
|
|
374
|
+
|
|
375
|
+
:param domain: the domain.
|
|
376
|
+
:param start_cpu: the first host CPU; -1 for the totals of the whole domain.
|
|
377
|
+
:param count: how many CPUs; 1 with ``start_cpu=-1``.
|
|
378
|
+
:param flags: reserved, 0.
|
|
379
|
+
:returns: one dict per CPU: ``cpu_time``, ``user_time``, ``system_time``...
|
|
380
|
+
"""
|
|
381
|
+
first = yield from on_domain(
|
|
382
|
+
domain,
|
|
383
|
+
"domain_get_cpu_stats",
|
|
384
|
+
nparams=0,
|
|
385
|
+
start_cpu=0,
|
|
386
|
+
ncpus=1,
|
|
387
|
+
flags=flags,
|
|
388
|
+
)
|
|
389
|
+
per_cpu = as_struct(first, types.DomainGetCpuStatsRet).nparams
|
|
390
|
+
|
|
391
|
+
reply = yield from on_domain(
|
|
392
|
+
domain,
|
|
393
|
+
"domain_get_cpu_stats",
|
|
394
|
+
nparams=per_cpu,
|
|
395
|
+
start_cpu=start_cpu,
|
|
396
|
+
ncpus=count,
|
|
397
|
+
flags=flags,
|
|
398
|
+
)
|
|
399
|
+
values = from_wire(as_struct(reply, types.DomainGetCpuStatsRet).params)
|
|
400
|
+
return _split_per_cpu(values, per_cpu, count)
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def pin_domain_iothread(
|
|
404
|
+
domain: DomainRef, iothread_id: int, cpus: Iterable[int], *, flags: int = 0
|
|
405
|
+
) -> Operation[None]:
|
|
406
|
+
"""Restrict an IO thread of a domain to some host CPUs.
|
|
407
|
+
|
|
408
|
+
:param domain: the domain.
|
|
409
|
+
:param iothread_id: the IO thread id.
|
|
410
|
+
:param cpus: the host CPU numbers.
|
|
411
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
412
|
+
"""
|
|
413
|
+
yield from on_domain(
|
|
414
|
+
domain,
|
|
415
|
+
"domain_pin_iothread",
|
|
416
|
+
iothreads_id=iothread_id,
|
|
417
|
+
cpumap=to_cpumap(cpus),
|
|
418
|
+
flags=flags,
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def add_domain_iothread(
|
|
423
|
+
domain: DomainRef, iothread_id: int, *, flags: int = 0
|
|
424
|
+
) -> Operation[None]:
|
|
425
|
+
"""Add an IO thread to a domain.
|
|
426
|
+
|
|
427
|
+
:param domain: the domain.
|
|
428
|
+
:param iothread_id: the id of the new IO thread.
|
|
429
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
430
|
+
"""
|
|
431
|
+
yield from on_domain(
|
|
432
|
+
domain, "domain_add_iothread", iothread_id=iothread_id, flags=flags
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def delete_domain_iothread(
|
|
437
|
+
domain: DomainRef, iothread_id: int, *, flags: int = 0
|
|
438
|
+
) -> Operation[None]:
|
|
439
|
+
"""Remove an IO thread from a domain.
|
|
440
|
+
|
|
441
|
+
:param domain: the domain.
|
|
442
|
+
:param iothread_id: the IO thread id.
|
|
443
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
444
|
+
"""
|
|
445
|
+
yield from on_domain(
|
|
446
|
+
domain, "domain_del_iothread", iothread_id=iothread_id, flags=flags
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def set_domain_iothread_parameters(
|
|
451
|
+
domain: DomainRef,
|
|
452
|
+
iothread_id: int,
|
|
453
|
+
parameters: dict[str, TypedValue],
|
|
454
|
+
*,
|
|
455
|
+
flags: int = 0,
|
|
456
|
+
) -> Operation[None]:
|
|
457
|
+
"""Tune an IO thread of a domain.
|
|
458
|
+
|
|
459
|
+
:param domain: the domain.
|
|
460
|
+
:param iothread_id: the IO thread id.
|
|
461
|
+
:param parameters: e.g. ``{"poll_max_ns": 32768}``.
|
|
462
|
+
:param flags: ``virDomainModificationImpact``: live, config.
|
|
463
|
+
"""
|
|
464
|
+
yield from on_domain(
|
|
465
|
+
domain,
|
|
466
|
+
"domain_set_iothread_params",
|
|
467
|
+
iothread_id=iothread_id,
|
|
468
|
+
params=to_wire(parameters),
|
|
469
|
+
flags=flags,
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _host_map_length() -> Operation[int]:
|
|
474
|
+
"""Find how many bytes a CPU bitmap of the host needs.
|
|
475
|
+
|
|
476
|
+
:returns: the length, from the host's CPU count.
|
|
477
|
+
"""
|
|
478
|
+
reply = yield Request("node_get_info")
|
|
479
|
+
node = as_struct(reply, types.NodeGetInfoRet)
|
|
480
|
+
return map_length(node.nodes * node.sockets * node.cores * node.threads)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def _split_per_cpu(
|
|
484
|
+
values: dict[str, TypedValue], per_cpu: int, count: int
|
|
485
|
+
) -> list[dict[str, TypedValue]]:
|
|
486
|
+
"""Split the flat statistics into one dict per CPU.
|
|
487
|
+
|
|
488
|
+
:param values: the statistics of all asked CPUs, in order.
|
|
489
|
+
:param per_cpu: how many parameters each CPU has.
|
|
490
|
+
:param count: how many CPUs were asked.
|
|
491
|
+
:returns: one dict per CPU.
|
|
492
|
+
"""
|
|
493
|
+
items = list(values.items())
|
|
494
|
+
return [dict(items[i * per_cpu : (i + 1) * per_cpu]) for i in range(count)]
|