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,197 @@
1
+ """Shared annotated types used across all models."""
2
+
3
+ import re
4
+ from collections.abc import Callable
5
+ from typing import Annotated
6
+
7
+ from pydantic import BeforeValidator, Field, PlainSerializer, StringConstraints
8
+ from pydantic_xml import attr
9
+
10
+ from libvirtpy.xml._base import LibvirtXmlModel
11
+
12
+ __all__ = [
13
+ "HexNumber",
14
+ "OnOff",
15
+ "OptionalText",
16
+ "PresenceFlag",
17
+ "ScaledInteger",
18
+ "SizeUnit",
19
+ "Uuid",
20
+ "YesNo",
21
+ "size_to_bytes",
22
+ ]
23
+
24
+
25
+ def _bool_parser(true_word: str, false_word: str) -> Callable[[object], bool]:
26
+ """Build a validator that accepts only ``true_word``, ``false_word`` or ``bool``.
27
+
28
+ The check is done here, not with pydantic's ``Strict()``: pydantic-xml
29
+ validates with ``strict=False``, which would let pydantic's lax ``bool``
30
+ accept ``"true"``, ``"1"`` and the other word pair (``"on"`` for yes/no).
31
+
32
+ :param true_word: the text that means ``True``, e.g. ``"yes"``.
33
+ :param false_word: the text that means ``False``, e.g. ``"no"``.
34
+ :returns: the validator function.
35
+ """
36
+ words = {true_word: True, false_word: False}
37
+
38
+ def parse(value: object) -> bool:
39
+ """Convert one value to ``bool``.
40
+
41
+ :param value: a ``bool`` or one of the two accepted words.
42
+ :returns: the ``bool`` value.
43
+ :raises ValueError: if ``value`` is anything else.
44
+ """
45
+ if isinstance(value, bool):
46
+ return value
47
+ if isinstance(value, str) and value in words:
48
+ return words[value]
49
+ raise ValueError(f"expected {true_word!r} or {false_word!r}, got {value!r}")
50
+
51
+ return parse
52
+
53
+
54
+ def _bool_serializer(true_word: str, false_word: str) -> Callable[[bool], str]:
55
+ """Build a serializer that writes ``True`` and ``False`` as words.
56
+
57
+ :param true_word: the text written for ``True``.
58
+ :param false_word: the text written for ``False``.
59
+ :returns: the serializer function.
60
+ """
61
+
62
+ def serialize(value: bool) -> str:
63
+ """Write one ``bool`` as its word.
64
+
65
+ :param value: the value to write.
66
+ :returns: the word for ``value``.
67
+ """
68
+ return true_word if value else false_word
69
+
70
+ return serialize
71
+
72
+
73
+ YesNo = Annotated[
74
+ bool,
75
+ BeforeValidator(_bool_parser("yes", "no")),
76
+ PlainSerializer(_bool_serializer("yes", "no"), return_type=str),
77
+ ]
78
+ """A ``yes``/``no`` attribute value as ``bool``."""
79
+
80
+ OnOff = Annotated[
81
+ bool,
82
+ BeforeValidator(_bool_parser("on", "off")),
83
+ PlainSerializer(_bool_serializer("on", "off"), return_type=str),
84
+ ]
85
+ """An ``on``/``off`` attribute value as ``bool``."""
86
+
87
+
88
+ def _empty_to_none(value: object) -> object:
89
+ """Turn an empty string into ``None``, leave other values alone.
90
+
91
+ :param value: the raw value of an element's text.
92
+ :returns: ``None`` for ``""``, otherwise ``value`` unchanged.
93
+ """
94
+ if value == "":
95
+ return None
96
+ return value
97
+
98
+
99
+ OptionalText = Annotated[str | None, BeforeValidator(_empty_to_none)]
100
+ """Element text that may be missing, for a model that also has attributes.
101
+
102
+ ``<loader readonly='yes'/>`` has no path: it parses to ``None``, not ``""``.
103
+ Use it as ``value: OptionalText = None``.
104
+ """
105
+
106
+
107
+ class PresenceFlag(LibvirtXmlModel):
108
+ """An empty element whose presence is the information, like ``<acpi/>``.
109
+
110
+ Use it as ``PresenceFlag | None``: ``None`` means the element is absent.
111
+ The element tag comes from the field, e.g. ``element(tag="acpi")``.
112
+ A ``bool`` field cannot be used: pydantic-xml reads an empty element as
113
+ missing and cannot write an empty element for ``True``.
114
+ """
115
+
116
+
117
+ HexNumber = Annotated[str, StringConstraints(pattern=r"^(0x)?[0-9a-fA-F]+$")]
118
+ """A number written in hex (``0x1f``) or decimal (``31``), kept as written.
119
+
120
+ Used for device addresses, where libvirt accepts both forms.
121
+ """
122
+
123
+ Uuid = Annotated[
124
+ str,
125
+ StringConstraints(
126
+ pattern=r"^([a-fA-F0-9]{32}|[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12})$"
127
+ ),
128
+ ]
129
+ """A UUID kept exactly as written (with or without dashes, any case)."""
130
+
131
+
132
+ # Same as the "unit" define of libvirt's basictypes.rng.
133
+ _SIZE_UNIT_PATTERN = r"^([bB]([yY][tT][eE][sS]?)?|[kKmMgGtTpPeE]([iI]?[bB])?)$"
134
+
135
+ SizeUnit = Annotated[str, StringConstraints(pattern=_SIZE_UNIT_PATTERN)]
136
+ """A size unit as accepted by libvirt: ``b``, ``byte(s)``, ``KB``, ``KiB``, ``k``...
137
+
138
+ Kept as written (``"GiB"`` stays ``"GiB"``); the libvirt schema accepts these
139
+ case-insensitively, so a ``Literal`` would reject valid documents.
140
+ """
141
+
142
+ _DECIMAL_FACTORS = {
143
+ "k": 1000**1,
144
+ "m": 1000**2,
145
+ "g": 1000**3,
146
+ "t": 1000**4,
147
+ "p": 1000**5,
148
+ "e": 1000**6,
149
+ }
150
+ _BINARY_FACTORS = {
151
+ "k": 1024**1,
152
+ "m": 1024**2,
153
+ "g": 1024**3,
154
+ "t": 1024**4,
155
+ "p": 1024**5,
156
+ "e": 1024**6,
157
+ }
158
+
159
+
160
+ def size_to_bytes(value: int, unit: SizeUnit) -> int:
161
+ """Convert ``value`` in ``unit`` to bytes, following libvirt's rules.
162
+
163
+ ``KB``, ``MB``... are powers of 1000; ``k``, ``KiB``, ``M``, ``MiB``... are
164
+ powers of 1024.
165
+
166
+ :param value: the amount.
167
+ :param unit: the libvirt unit of ``value``, such as ``"GiB"`` or ``"KB"``.
168
+ :returns: the amount in bytes.
169
+ :raises ValueError: if ``unit`` is not a libvirt size unit.
170
+ """
171
+ if re.fullmatch(_SIZE_UNIT_PATTERN, unit) is None:
172
+ raise ValueError(f"unknown size unit: {unit!r}")
173
+
174
+ normalized = unit.lower()
175
+ if normalized in ("b", "byte", "bytes"):
176
+ return value
177
+
178
+ prefix = normalized[0]
179
+ is_decimal = len(normalized) == 2 and normalized.endswith("b") # "kb", "mb"...
180
+ if is_decimal:
181
+ return value * _DECIMAL_FACTORS[prefix]
182
+ return value * _BINARY_FACTORS[prefix]
183
+
184
+
185
+ class ScaledInteger(LibvirtXmlModel):
186
+ """Base of elements that hold an amount with an optional ``unit``.
187
+
188
+ Subclass it with a ``tag``, e.g. ``class Limit(ScaledInteger, tag="limit")``.
189
+ The unit is kept as written; ``to_bytes()`` converts explicitly.
190
+ """
191
+
192
+ value: int = Field(ge=0, description="Element text: the amount, in ``unit``.")
193
+ unit: SizeUnit | None = attr(name="unit", default=None)
194
+
195
+ def to_bytes(self) -> int:
196
+ """Return the amount in bytes (a missing ``unit`` means KiB)."""
197
+ return size_to_bytes(self.value, self.unit or "KiB")
@@ -0,0 +1,134 @@
1
+ """An XML element for pydantic-xml whose "unordered" search keeps sibling order.
2
+
3
+ pydantic-xml's ``search_mode="unordered"`` consumes a child by *swapping* it to
4
+ the front of the unread children. That reorders the others: reading ``<disk>``
5
+ first from ``[controller0, controller1, disk]`` leaves ``[disk, controller1,
6
+ controller0]``, and the controllers are then read in the wrong order (checked
7
+ with pydantic-xml 2.22). Device order matters to libvirt, so this is data
8
+ corruption.
9
+
10
+ ``StableXmlElement`` moves the found child to the front *without* disturbing
11
+ the rest. ``LibvirtXmlModel.from_xml_tree`` uses it for every parse. This
12
+ module depends on pydantic-xml internals; the tests in ``tests/unit/test_base.py``
13
+ fail if an upgrade breaks it, or make it unnecessary.
14
+ """
15
+
16
+ from typing import cast
17
+
18
+ from lxml import etree
19
+ from pydantic_xml.element.element import SearchMode
20
+ from pydantic_xml.element.element import XmlElement as BaseXmlElement
21
+ from pydantic_xml.element.native.lxml import XmlElement as LxmlXmlElement
22
+
23
+ __all__ = ["StableXmlElement"]
24
+
25
+
26
+ class StableXmlElement(LxmlXmlElement):
27
+ """An lxml-backed pydantic-xml element with an order-preserving search."""
28
+
29
+ __slots__ = ()
30
+
31
+ @classmethod
32
+ def from_native(cls, element: etree._Element) -> StableXmlElement:
33
+ """Build the element tree from ``element``, ignoring comments and PIs.
34
+
35
+ :param element: the lxml element to copy, with its descendants.
36
+ :returns: the same tree as ``StableXmlElement`` objects.
37
+ """
38
+ return cls(
39
+ tag=str(element.tag),
40
+ text=element.text,
41
+ tail=element.tail,
42
+ attributes={
43
+ str(name): str(value) for name, value in element.attrib.items()
44
+ },
45
+ elements=[
46
+ cls.from_native(child)
47
+ for child in element
48
+ if isinstance(child.tag, str) # comments and PIs have a function tag
49
+ ],
50
+ sourceline=cast(int, element.sourceline)
51
+ if element.sourceline is not None
52
+ else -1,
53
+ )
54
+
55
+ def find_element(
56
+ self,
57
+ tag: str,
58
+ search_mode: SearchMode,
59
+ look_behind: bool = True,
60
+ step_forward: bool = True,
61
+ ) -> BaseXmlElement[etree._Element] | None:
62
+ """Find the next child with ``tag``; "unordered" mode keeps sibling order.
63
+
64
+ :param tag: the tag of the child to find.
65
+ :param search_mode: how pydantic-xml searches; only ``UNORDERED`` differs
66
+ from the base class.
67
+ :param look_behind: also accept the child that was read last.
68
+ :param step_forward: mark the child as read.
69
+ :returns: the child, or ``None`` if there is none left.
70
+ """
71
+ if search_mode != SearchMode.UNORDERED:
72
+ return super().find_element(tag, search_mode, look_behind, step_forward)
73
+ return self._stable_search(
74
+ tag, look_behind=look_behind, step_forward=step_forward
75
+ )
76
+
77
+ def pop_element(
78
+ self,
79
+ tag: str,
80
+ search_mode: SearchMode,
81
+ remove: bool = False,
82
+ ) -> BaseXmlElement[etree._Element] | None:
83
+ """Find a child like ``find_element`` and optionally detach its content.
84
+
85
+ :param tag: the tag of the child to find.
86
+ :param search_mode: how pydantic-xml searches; only ``UNORDERED`` differs
87
+ from the base class.
88
+ :param remove: take the child's text, attributes and children out of it.
89
+ :returns: the child, or ``None`` if there is none left.
90
+ """
91
+ if search_mode != SearchMode.UNORDERED:
92
+ return super().pop_element(tag, search_mode, remove)
93
+
94
+ element = self._stable_search(tag, look_behind=False, step_forward=True)
95
+ if element is None or not remove:
96
+ return element
97
+
98
+ return type(self)(
99
+ tag=element.tag,
100
+ nsmap=element.nsmap,
101
+ text=element.pop_text(),
102
+ tail=element.pop_tail(),
103
+ attributes=element.pop_attributes(),
104
+ elements=element.pop_elements(),
105
+ sourceline=element.get_sourceline(),
106
+ )
107
+
108
+ def _stable_search(
109
+ self, tag: str, *, look_behind: bool, step_forward: bool
110
+ ) -> BaseXmlElement[etree._Element] | None:
111
+ """Find the next unread child with ``tag`` without reordering the others.
112
+
113
+ :param tag: the tag of the child to find.
114
+ :param look_behind: also accept the child that was read last.
115
+ :param step_forward: mark the child as read.
116
+ :returns: the child, or ``None`` if there is none left.
117
+ """
118
+ state = self._state
119
+ if look_behind and state.next_element_idx != 0:
120
+ previous = state.elements[state.next_element_idx - 1]
121
+ if previous.tag == tag:
122
+ return previous
123
+
124
+ for index in range(state.next_element_idx, len(state.elements)):
125
+ candidate = state.elements[index]
126
+ if candidate.tag != tag:
127
+ continue
128
+ # Unlike pydantic-xml, move the match without reordering the others.
129
+ state.elements.insert(state.next_element_idx, state.elements.pop(index))
130
+ if step_forward:
131
+ state.next_element_idx += 1
132
+ return candidate
133
+
134
+ return None
@@ -0,0 +1,25 @@
1
+ """Models for domain backups and checkpoints. See https://libvirt.org/formatbackup.html"""
2
+
3
+ from libvirtpy.xml.backup.backup import (
4
+ Backup,
5
+ BackupDisk,
6
+ BackupDiskDriver,
7
+ BackupLocation,
8
+ BackupServer,
9
+ )
10
+ from libvirtpy.xml.backup.checkpoint import (
11
+ Checkpoint,
12
+ CheckpointDisk,
13
+ CheckpointParent,
14
+ )
15
+
16
+ __all__ = [
17
+ "Backup",
18
+ "BackupDisk",
19
+ "BackupDiskDriver",
20
+ "BackupLocation",
21
+ "BackupServer",
22
+ "Checkpoint",
23
+ "CheckpointDisk",
24
+ "CheckpointParent",
25
+ ]
@@ -0,0 +1,89 @@
1
+ """``<domainbackup>``: a request to back up a running domain.
2
+
3
+ ``mode='push'`` writes the backup to a ``<target>`` of each disk; ``mode='pull'``
4
+ serves it over NBD from ``<server>`` with a ``<scratch>`` file per disk.
5
+
6
+ See https://libvirt.org/formatbackup.html
7
+ """
8
+
9
+ from typing import Literal
10
+
11
+ from pydantic_xml import attr, element
12
+
13
+ from libvirtpy.xml._base import LibvirtXmlModel
14
+ from libvirtpy.xml._shared.storage import DeviceSeclabel, StorageEncryption
15
+ from libvirtpy.xml._types import YesNo
16
+
17
+ __all__ = [
18
+ "Backup",
19
+ "BackupDisk",
20
+ "BackupDiskDriver",
21
+ "BackupLocation",
22
+ "BackupServer",
23
+ ]
24
+
25
+
26
+ class BackupLocation(LibvirtXmlModel):
27
+ """Base of ``<target>`` and ``<scratch>``: a file or a block device."""
28
+
29
+ file: str | None = attr(name="file", default=None)
30
+ dev: str | None = attr(name="dev", default=None)
31
+ seclabels: list[DeviceSeclabel] = element(tag="seclabel", default_factory=list)
32
+ encryption: StorageEncryption | None = element(tag="encryption", default=None)
33
+
34
+
35
+ class BackupTarget(BackupLocation, tag="target"):
36
+ """``<target>``: where a push backup of the disk is written."""
37
+
38
+
39
+ class BackupScratch(BackupLocation, tag="scratch"):
40
+ """``<scratch>``: the scratch image of a pull backup."""
41
+
42
+
43
+ class BackupDiskDriver(LibvirtXmlModel, tag="driver"):
44
+ type: str = attr(name="type", description="Image format, e.g. ``qcow2``.")
45
+
46
+
47
+ class BackupDisk(LibvirtXmlModel, tag="disk"):
48
+ """``<disk>``: what to do with one disk of the domain."""
49
+
50
+ name: str = attr(name="name", description="Target of the disk, e.g. ``vda``.")
51
+ # The daemon adds ``index`` to a running job; libvirt's schema does not list it.
52
+ index: int | None = attr(name="index", default=None, ge=0)
53
+ backup: YesNo | None = attr(name="backup", default=None)
54
+ backupmode: Literal["full", "incremental"] | None = attr(
55
+ name="backupmode", default=None
56
+ )
57
+ incremental: str | None = attr(name="incremental", default=None)
58
+ exportname: str | None = attr(name="exportname", default=None)
59
+ exportbitmap: str | None = attr(name="exportbitmap", default=None)
60
+ type: Literal["file", "block"] | None = attr(name="type", default=None)
61
+ target: BackupTarget | None = element(tag="target", default=None)
62
+ scratch: BackupScratch | None = element(tag="scratch", default=None)
63
+ driver: BackupDiskDriver | None = element(tag="driver", default=None)
64
+
65
+
66
+ class BackupServer(LibvirtXmlModel, tag="server"):
67
+ """``<server>``: the NBD server of a pull backup."""
68
+
69
+ tls: YesNo | None = attr(name="tls", default=None)
70
+ transport: Literal["tcp", "unix", "fd"] | None = attr(
71
+ name="transport", default=None
72
+ )
73
+ name: str | None = attr(name="name", default=None)
74
+ port: int | None = attr(name="port", default=None, ge=0)
75
+ socket: str | None = attr(name="socket", default=None)
76
+ fdgroup: str | None = attr(name="fdgroup", default=None)
77
+
78
+
79
+ class BackupDisks(LibvirtXmlModel, tag="disks"):
80
+ disks: list[BackupDisk] = element(tag="disk", default_factory=list)
81
+
82
+
83
+ class Backup(LibvirtXmlModel, tag="domainbackup"):
84
+ """``<domainbackup>``: the parameters of one backup job."""
85
+
86
+ mode: Literal["push", "pull"] | None = attr(name="mode", default=None)
87
+ incremental: str | None = element(tag="incremental", default=None)
88
+ server: BackupServer | None = element(tag="server", default=None)
89
+ disks: BackupDisks | None = element(tag="disks", default=None)
@@ -0,0 +1,48 @@
1
+ """``<domaincheckpoint>``: a point in time that incremental backups start from.
2
+
3
+ It embeds the domain definition at that time, so this module uses the
4
+ ``domain`` package.
5
+
6
+ See https://libvirt.org/formatcheckpoint.html
7
+ """
8
+
9
+ from typing import Literal
10
+
11
+ from pydantic_xml import attr, element
12
+
13
+ from libvirtpy.xml._base import LibvirtXmlModel
14
+ from libvirtpy.xml.domain import Domain
15
+
16
+ __all__ = [
17
+ "Checkpoint",
18
+ "CheckpointDisk",
19
+ "CheckpointParent",
20
+ ]
21
+
22
+
23
+ class CheckpointDisk(LibvirtXmlModel, tag="disk"):
24
+ """``<disk>``: the checkpoint bitmap of one disk."""
25
+
26
+ name: str = attr(name="name")
27
+ checkpoint: Literal["no", "bitmap"] | None = attr(name="checkpoint", default=None)
28
+ bitmap: str | None = attr(name="bitmap", default=None)
29
+ size: int | None = attr(name="size", default=None, ge=0)
30
+
31
+
32
+ class CheckpointDisks(LibvirtXmlModel, tag="disks"):
33
+ disks: list[CheckpointDisk] = element(tag="disk", default_factory=list)
34
+
35
+
36
+ class CheckpointParent(LibvirtXmlModel, tag="parent"):
37
+ name: str = element(tag="name")
38
+
39
+
40
+ class Checkpoint(LibvirtXmlModel, tag="domaincheckpoint"):
41
+ """``<domaincheckpoint>``: a checkpoint of a domain."""
42
+
43
+ name: str | None = element(tag="name", default=None)
44
+ description: str | None = element(tag="description", default=None)
45
+ creation_time: int | None = element(tag="creationTime", default=None, ge=0)
46
+ disks: CheckpointDisks | None = element(tag="disks", default=None)
47
+ parent: CheckpointParent | None = element(tag="parent", default=None)
48
+ domain: Domain | None = element(tag="domain", default=None)
@@ -0,0 +1,43 @@
1
+ """Read-only capability documents. See https://libvirt.org/formatcaps.html"""
2
+
3
+ from libvirtpy.xml.capabilities.domain import (
4
+ CapsEnum,
5
+ DomainCapabilities,
6
+ FeatureSupport,
7
+ )
8
+ from libvirtpy.xml.capabilities.host import (
9
+ Capabilities,
10
+ GuestArch,
11
+ GuestCapabilities,
12
+ GuestDomain,
13
+ HostCapabilities,
14
+ HostCpu,
15
+ HostTopology,
16
+ SecModel,
17
+ )
18
+ from libvirtpy.xml.capabilities.storagepool import (
19
+ PoolCapabilities,
20
+ PoolCapsDefaultFormat,
21
+ PoolCapsEnum,
22
+ PoolCapsOptions,
23
+ StoragePoolCapabilities,
24
+ )
25
+
26
+ __all__ = [
27
+ "Capabilities",
28
+ "CapsEnum",
29
+ "DomainCapabilities",
30
+ "FeatureSupport",
31
+ "GuestArch",
32
+ "GuestCapabilities",
33
+ "GuestDomain",
34
+ "HostCapabilities",
35
+ "HostCpu",
36
+ "HostTopology",
37
+ "PoolCapabilities",
38
+ "PoolCapsDefaultFormat",
39
+ "PoolCapsEnum",
40
+ "PoolCapsOptions",
41
+ "SecModel",
42
+ "StoragePoolCapabilities",
43
+ ]