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,100 @@
|
|
|
1
|
+
"""Operations on the snapshots of a domain."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.operations._common import (
|
|
4
|
+
as_xml,
|
|
5
|
+
fetch_model,
|
|
6
|
+
fetch_models,
|
|
7
|
+
many_handles,
|
|
8
|
+
one_handle,
|
|
9
|
+
)
|
|
10
|
+
from libvirtpy.client.references import (
|
|
11
|
+
DomainRef,
|
|
12
|
+
SnapshotRef,
|
|
13
|
+
domain_lookup,
|
|
14
|
+
snapshot_lookup,
|
|
15
|
+
)
|
|
16
|
+
from libvirtpy.client.transport import Operation, Request
|
|
17
|
+
from libvirtpy.xml.snapshot import Snapshot
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"create_domain_snapshot",
|
|
21
|
+
"delete_domain_snapshot",
|
|
22
|
+
"list_domain_snapshots",
|
|
23
|
+
"lookup_domain_snapshot",
|
|
24
|
+
"revert_domain_snapshot",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def list_domain_snapshots(domain: DomainRef) -> Operation[list[Snapshot]]:
|
|
29
|
+
"""Return the snapshots of a domain.
|
|
30
|
+
|
|
31
|
+
:param domain: the domain.
|
|
32
|
+
:returns: the snapshots, oldest first.
|
|
33
|
+
"""
|
|
34
|
+
handle = yield from one_handle(domain_lookup(domain))
|
|
35
|
+
names = yield from many_handles(
|
|
36
|
+
Request(
|
|
37
|
+
"domain_list_all_snapshots", {"dom": handle, "need_results": 1, "flags": 0}
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
return (yield from fetch_models("domain_snapshot_get_xml_desc", names, Snapshot))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def lookup_domain_snapshot(
|
|
44
|
+
domain: DomainRef, snapshot: SnapshotRef
|
|
45
|
+
) -> Operation[Snapshot]:
|
|
46
|
+
"""Return one snapshot of a domain.
|
|
47
|
+
|
|
48
|
+
:param domain: the domain.
|
|
49
|
+
:param snapshot: the snapshot name, or a ``Snapshot`` model.
|
|
50
|
+
:returns: the snapshot.
|
|
51
|
+
:raises NoSnapshotError: if there is no such snapshot.
|
|
52
|
+
"""
|
|
53
|
+
handle = yield from one_handle(domain_lookup(domain))
|
|
54
|
+
found = yield from one_handle(snapshot_lookup(handle, snapshot))
|
|
55
|
+
return (yield from fetch_model("domain_snapshot_get_xml_desc", found, Snapshot))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def create_domain_snapshot(
|
|
59
|
+
domain: DomainRef, snapshot: Snapshot | str, *, flags: int = 0
|
|
60
|
+
) -> Operation[Snapshot]:
|
|
61
|
+
"""Take a snapshot of a domain.
|
|
62
|
+
|
|
63
|
+
:param domain: the domain.
|
|
64
|
+
:param snapshot: the snapshot description, as a model or XML (a name may be
|
|
65
|
+
left out).
|
|
66
|
+
:param flags: ``virDomainSnapshotCreateFlags``.
|
|
67
|
+
:returns: the snapshot as the daemon stored it.
|
|
68
|
+
"""
|
|
69
|
+
handle = yield from one_handle(domain_lookup(domain))
|
|
70
|
+
arguments = {"dom": handle, "xml_desc": as_xml(snapshot), "flags": flags}
|
|
71
|
+
created = yield from one_handle(Request("domain_snapshot_create_xml", arguments))
|
|
72
|
+
return (yield from fetch_model("domain_snapshot_get_xml_desc", created, Snapshot))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def revert_domain_snapshot(
|
|
76
|
+
domain: DomainRef, snapshot: SnapshotRef, *, flags: int = 0
|
|
77
|
+
) -> Operation[None]:
|
|
78
|
+
"""Return a domain to a snapshot.
|
|
79
|
+
|
|
80
|
+
:param domain: the domain.
|
|
81
|
+
:param snapshot: the snapshot name, or a ``Snapshot`` model.
|
|
82
|
+
:param flags: ``virDomainSnapshotRevertFlags``.
|
|
83
|
+
"""
|
|
84
|
+
handle = yield from one_handle(domain_lookup(domain))
|
|
85
|
+
found = yield from one_handle(snapshot_lookup(handle, snapshot))
|
|
86
|
+
yield Request("domain_revert_to_snapshot", {"snap": found, "flags": flags})
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def delete_domain_snapshot(
|
|
90
|
+
domain: DomainRef, snapshot: SnapshotRef, *, flags: int = 0
|
|
91
|
+
) -> Operation[None]:
|
|
92
|
+
"""Delete a snapshot of a domain.
|
|
93
|
+
|
|
94
|
+
:param domain: the domain.
|
|
95
|
+
:param snapshot: the snapshot name, or a ``Snapshot`` model.
|
|
96
|
+
:param flags: ``virDomainSnapshotDeleteFlags``.
|
|
97
|
+
"""
|
|
98
|
+
handle = yield from one_handle(domain_lookup(domain))
|
|
99
|
+
found = yield from one_handle(snapshot_lookup(handle, snapshot))
|
|
100
|
+
yield Request("domain_snapshot_delete", {"snap": found, "flags": flags})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Operations on the snapshot tree of a domain: current, parent, children."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.operations._common import (
|
|
4
|
+
as_bool,
|
|
5
|
+
as_handle,
|
|
6
|
+
fetch_model,
|
|
7
|
+
fetch_models,
|
|
8
|
+
many_handles,
|
|
9
|
+
on_domain,
|
|
10
|
+
on_snapshot,
|
|
11
|
+
one_handle,
|
|
12
|
+
)
|
|
13
|
+
from libvirtpy.client.references import (
|
|
14
|
+
DomainRef,
|
|
15
|
+
SnapshotRef,
|
|
16
|
+
domain_lookup,
|
|
17
|
+
snapshot_lookup,
|
|
18
|
+
)
|
|
19
|
+
from libvirtpy.client.transport import Operation, Request
|
|
20
|
+
from libvirtpy.xml.snapshot import Snapshot
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"get_current_domain_snapshot",
|
|
24
|
+
"get_domain_snapshot_parent",
|
|
25
|
+
"has_domain_snapshot_metadata",
|
|
26
|
+
"is_domain_snapshot_current",
|
|
27
|
+
"list_domain_snapshot_children",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_current_domain_snapshot(
|
|
32
|
+
domain: DomainRef, *, flags: int = 0
|
|
33
|
+
) -> Operation[Snapshot]:
|
|
34
|
+
"""Return the current snapshot of a domain.
|
|
35
|
+
|
|
36
|
+
:param domain: the domain.
|
|
37
|
+
:param flags: reserved, 0.
|
|
38
|
+
:returns: the snapshot.
|
|
39
|
+
:raises NoSnapshotError: if the domain has no current snapshot.
|
|
40
|
+
"""
|
|
41
|
+
handle = yield from as_handle(
|
|
42
|
+
on_domain(domain, "domain_snapshot_current", flags=flags)
|
|
43
|
+
)
|
|
44
|
+
return (yield from fetch_model("domain_snapshot_get_xml_desc", handle, Snapshot))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_domain_snapshot_parent(
|
|
48
|
+
domain: DomainRef, snapshot: SnapshotRef, *, flags: int = 0
|
|
49
|
+
) -> Operation[Snapshot]:
|
|
50
|
+
"""Return the parent of a snapshot.
|
|
51
|
+
|
|
52
|
+
:param domain: the domain.
|
|
53
|
+
:param snapshot: the snapshot.
|
|
54
|
+
:param flags: reserved, 0.
|
|
55
|
+
:returns: the parent snapshot.
|
|
56
|
+
:raises NoSnapshotError: if the snapshot has no parent.
|
|
57
|
+
"""
|
|
58
|
+
parent = yield from as_handle(
|
|
59
|
+
on_snapshot(domain, snapshot, "domain_snapshot_get_parent", flags=flags)
|
|
60
|
+
)
|
|
61
|
+
return (yield from fetch_model("domain_snapshot_get_xml_desc", parent, Snapshot))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def list_domain_snapshot_children(
|
|
65
|
+
domain: DomainRef, snapshot: SnapshotRef, *, flags: int = 0
|
|
66
|
+
) -> Operation[list[Snapshot]]:
|
|
67
|
+
"""Return the snapshots that descend from a snapshot.
|
|
68
|
+
|
|
69
|
+
:param domain: the domain.
|
|
70
|
+
:param snapshot: the snapshot.
|
|
71
|
+
:param flags: ``virDomainSnapshotListFlags``: 1 all descendants, ...
|
|
72
|
+
:returns: the children.
|
|
73
|
+
"""
|
|
74
|
+
domain_handle = yield from one_handle(domain_lookup(domain))
|
|
75
|
+
parent = yield from one_handle(snapshot_lookup(domain_handle, snapshot))
|
|
76
|
+
children = yield from many_handles(
|
|
77
|
+
Request(
|
|
78
|
+
"domain_snapshot_list_all_children",
|
|
79
|
+
{"snapshot": parent, "need_results": 1, "flags": flags},
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
return (yield from fetch_models("domain_snapshot_get_xml_desc", children, Snapshot))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def is_domain_snapshot_current(
|
|
86
|
+
domain: DomainRef, snapshot: SnapshotRef, *, flags: int = 0
|
|
87
|
+
) -> Operation[bool]:
|
|
88
|
+
"""Tell whether a snapshot is the current one.
|
|
89
|
+
|
|
90
|
+
:param domain: the domain.
|
|
91
|
+
:param snapshot: the snapshot.
|
|
92
|
+
:param flags: reserved, 0.
|
|
93
|
+
:returns: ``True`` if it is current.
|
|
94
|
+
"""
|
|
95
|
+
reply = yield from on_snapshot(
|
|
96
|
+
domain, snapshot, "domain_snapshot_is_current", flags=flags
|
|
97
|
+
)
|
|
98
|
+
return as_bool(reply)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def has_domain_snapshot_metadata(
|
|
102
|
+
domain: DomainRef, snapshot: SnapshotRef, *, flags: int = 0
|
|
103
|
+
) -> Operation[bool]:
|
|
104
|
+
"""Tell whether libvirt keeps the metadata of a snapshot.
|
|
105
|
+
|
|
106
|
+
:param domain: the domain.
|
|
107
|
+
:param snapshot: the snapshot.
|
|
108
|
+
:param flags: reserved, 0.
|
|
109
|
+
:returns: ``True`` if it does.
|
|
110
|
+
"""
|
|
111
|
+
reply = yield from on_snapshot(
|
|
112
|
+
domain, snapshot, "domain_snapshot_has_metadata", flags=flags
|
|
113
|
+
)
|
|
114
|
+
return as_bool(reply)
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Operations on storage pools and their volumes."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.operations._common import (
|
|
4
|
+
ACTIVE,
|
|
5
|
+
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
|
+
PoolRef,
|
|
15
|
+
VolumeRef,
|
|
16
|
+
pool_lookup,
|
|
17
|
+
volume_lookup,
|
|
18
|
+
)
|
|
19
|
+
from libvirtpy.client.transport import Operation, Request
|
|
20
|
+
from libvirtpy.xml.storage import Pool, Volume
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"build_pool",
|
|
24
|
+
"create_pool",
|
|
25
|
+
"create_pool_volume",
|
|
26
|
+
"define_pool",
|
|
27
|
+
"delete_pool",
|
|
28
|
+
"delete_pool_volume",
|
|
29
|
+
"destroy_pool",
|
|
30
|
+
"get_pool_autostart",
|
|
31
|
+
"list_pool_volumes",
|
|
32
|
+
"list_pools",
|
|
33
|
+
"lookup_pool",
|
|
34
|
+
"lookup_pool_volume",
|
|
35
|
+
"refresh_pool",
|
|
36
|
+
"resize_pool_volume",
|
|
37
|
+
"set_pool_autostart",
|
|
38
|
+
"start_pool",
|
|
39
|
+
"undefine_pool",
|
|
40
|
+
"wipe_pool_volume",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def lookup_pool(pool: PoolRef) -> Operation[Pool]:
|
|
45
|
+
"""Return the configuration of a storage pool.
|
|
46
|
+
|
|
47
|
+
:param pool: a name, UUID or ``Pool`` model.
|
|
48
|
+
:returns: the pool.
|
|
49
|
+
:raises NoStoragePoolError: if there is no such pool.
|
|
50
|
+
"""
|
|
51
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
52
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", handle, Pool))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def list_pools(*, active: bool | None = None) -> Operation[list[Pool]]:
|
|
56
|
+
"""Return the storage pools.
|
|
57
|
+
|
|
58
|
+
:param active: ``True`` for active pools only, ``False`` for the others,
|
|
59
|
+
``None`` for all.
|
|
60
|
+
:returns: the pools.
|
|
61
|
+
"""
|
|
62
|
+
flags = {True: ACTIVE, False: INACTIVE, None: 0}[active]
|
|
63
|
+
handles = yield from many_handles(
|
|
64
|
+
Request("connect_list_all_storage_pools", {"need_results": 1, "flags": flags})
|
|
65
|
+
)
|
|
66
|
+
return (yield from fetch_models("storage_pool_get_xml_desc", handles, Pool))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def define_pool(pool: Pool | str, *, flags: int = 0) -> Operation[Pool]:
|
|
70
|
+
"""Define (or redefine) a persistent storage pool without starting it.
|
|
71
|
+
|
|
72
|
+
:param pool: the configuration, as a model or XML text.
|
|
73
|
+
:param flags: ``virStoragePoolDefineFlags``.
|
|
74
|
+
:returns: the stored configuration, with what libvirt filled in.
|
|
75
|
+
"""
|
|
76
|
+
xml = as_xml(pool)
|
|
77
|
+
handle = yield from one_handle(
|
|
78
|
+
Request("storage_pool_define_xml", {"xml": xml, "flags": flags})
|
|
79
|
+
)
|
|
80
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", handle, Pool))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def create_pool(pool: Pool | str, *, flags: int = 0) -> Operation[Pool]:
|
|
84
|
+
"""Start a transient storage pool: it disappears when it stops.
|
|
85
|
+
|
|
86
|
+
:param pool: the configuration, as a model or XML text.
|
|
87
|
+
:param flags: ``virStoragePoolCreateFlags``.
|
|
88
|
+
:returns: the running pool.
|
|
89
|
+
"""
|
|
90
|
+
xml = as_xml(pool)
|
|
91
|
+
handle = yield from one_handle(
|
|
92
|
+
Request("storage_pool_create_xml", {"xml": xml, "flags": flags})
|
|
93
|
+
)
|
|
94
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", handle, Pool))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def undefine_pool(pool: PoolRef) -> Operation[None]:
|
|
98
|
+
"""Remove a persistent pool's definition.
|
|
99
|
+
|
|
100
|
+
:param pool: the pool.
|
|
101
|
+
:raises OperationInvalidError: if the pool is active.
|
|
102
|
+
"""
|
|
103
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
104
|
+
yield Request("storage_pool_undefine", {"pool": handle})
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def build_pool(pool: PoolRef, *, flags: int = 0) -> Operation[None]:
|
|
108
|
+
"""Create the storage a pool is made of (a directory, a file system, ...).
|
|
109
|
+
|
|
110
|
+
:param pool: the pool.
|
|
111
|
+
:param flags: ``virStoragePoolBuildFlags``.
|
|
112
|
+
"""
|
|
113
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
114
|
+
yield Request("storage_pool_build", {"pool": handle, "flags": flags})
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def start_pool(pool: PoolRef, *, flags: int = 0) -> Operation[Pool]:
|
|
118
|
+
"""Start a defined storage pool.
|
|
119
|
+
|
|
120
|
+
:param pool: the pool.
|
|
121
|
+
:param flags: ``virStoragePoolCreateFlags``.
|
|
122
|
+
:returns: the pool, now active.
|
|
123
|
+
:raises OperationInvalidError: if the pool is already active.
|
|
124
|
+
"""
|
|
125
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
126
|
+
yield Request("storage_pool_create", {"pool": handle, "flags": flags})
|
|
127
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", handle, Pool))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def destroy_pool(pool: PoolRef) -> Operation[None]:
|
|
131
|
+
"""Stop a storage pool; its volumes stay.
|
|
132
|
+
|
|
133
|
+
:param pool: the pool.
|
|
134
|
+
:raises OperationInvalidError: if the pool is not active.
|
|
135
|
+
"""
|
|
136
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
137
|
+
yield Request("storage_pool_destroy", {"pool": handle})
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def delete_pool(pool: PoolRef, *, flags: int = 0) -> Operation[None]:
|
|
141
|
+
"""Delete the storage a pool is made of.
|
|
142
|
+
|
|
143
|
+
:param pool: the pool.
|
|
144
|
+
:param flags: ``virStoragePoolDeleteFlags``.
|
|
145
|
+
"""
|
|
146
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
147
|
+
yield Request("storage_pool_delete", {"pool": handle, "flags": flags})
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def refresh_pool(pool: PoolRef) -> Operation[Pool]:
|
|
151
|
+
"""Re-read the volumes and the sizes of an active pool.
|
|
152
|
+
|
|
153
|
+
:param pool: the pool.
|
|
154
|
+
:returns: the pool with the new sizes.
|
|
155
|
+
"""
|
|
156
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
157
|
+
yield Request("storage_pool_refresh", {"pool": handle, "flags": 0})
|
|
158
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", handle, Pool))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def get_pool_autostart(pool: PoolRef) -> Operation[bool]:
|
|
162
|
+
"""Tell whether a pool starts with the host.
|
|
163
|
+
|
|
164
|
+
:param pool: the pool.
|
|
165
|
+
:returns: ``True`` if it starts at boot.
|
|
166
|
+
"""
|
|
167
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
168
|
+
return bool(as_int((yield Request("storage_pool_get_autostart", {"pool": handle}))))
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def set_pool_autostart(pool: PoolRef, enabled: bool) -> Operation[None]:
|
|
172
|
+
"""Make a pool start (or not) with the host.
|
|
173
|
+
|
|
174
|
+
:param pool: the pool.
|
|
175
|
+
:param enabled: ``True`` to start it at boot.
|
|
176
|
+
"""
|
|
177
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
178
|
+
yield Request(
|
|
179
|
+
"storage_pool_set_autostart", {"pool": handle, "autostart": int(enabled)}
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def list_pool_volumes(pool: PoolRef) -> Operation[list[Volume]]:
|
|
184
|
+
"""Return the volumes of a storage pool.
|
|
185
|
+
|
|
186
|
+
:param pool: the pool.
|
|
187
|
+
:returns: the volumes.
|
|
188
|
+
"""
|
|
189
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
190
|
+
arguments = {"pool": handle, "need_results": 1, "flags": 0}
|
|
191
|
+
handles = yield from many_handles(
|
|
192
|
+
Request("storage_pool_list_all_volumes", arguments)
|
|
193
|
+
)
|
|
194
|
+
return (yield from fetch_models("storage_vol_get_xml_desc", handles, Volume))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def lookup_pool_volume(pool: PoolRef, volume: VolumeRef) -> Operation[Volume]:
|
|
198
|
+
"""Return one volume of a storage pool.
|
|
199
|
+
|
|
200
|
+
:param pool: the pool.
|
|
201
|
+
:param volume: a name, a key or an absolute path, or a ``Volume`` model.
|
|
202
|
+
:returns: the volume.
|
|
203
|
+
:raises NoStorageVolumeError: if there is no such volume.
|
|
204
|
+
"""
|
|
205
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
206
|
+
found = yield from one_handle(volume_lookup(handle, volume))
|
|
207
|
+
return (yield from fetch_model("storage_vol_get_xml_desc", found, Volume))
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def create_pool_volume(
|
|
211
|
+
pool: PoolRef, volume: Volume | str, *, flags: int = 0
|
|
212
|
+
) -> Operation[Volume]:
|
|
213
|
+
"""Create a volume in a storage pool.
|
|
214
|
+
|
|
215
|
+
:param pool: the pool.
|
|
216
|
+
:param volume: the volume description, as a model or XML.
|
|
217
|
+
:param flags: ``virStorageVolCreateFlags``.
|
|
218
|
+
:returns: the volume as the daemon created it (key, path, ...).
|
|
219
|
+
"""
|
|
220
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
221
|
+
arguments = {"pool": handle, "xml": as_xml(volume), "flags": flags}
|
|
222
|
+
created = yield from one_handle(Request("storage_vol_create_xml", arguments))
|
|
223
|
+
return (yield from fetch_model("storage_vol_get_xml_desc", created, Volume))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def delete_pool_volume(
|
|
227
|
+
pool: PoolRef, volume: VolumeRef, *, flags: int = 0
|
|
228
|
+
) -> Operation[None]:
|
|
229
|
+
"""Delete a volume of a storage pool.
|
|
230
|
+
|
|
231
|
+
:param pool: the pool.
|
|
232
|
+
:param volume: a name, a key or an absolute path, or a ``Volume`` model.
|
|
233
|
+
:param flags: ``virStorageVolDeleteFlags``.
|
|
234
|
+
"""
|
|
235
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
236
|
+
found = yield from one_handle(volume_lookup(handle, volume))
|
|
237
|
+
yield Request("storage_vol_delete", {"vol": found, "flags": flags})
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def resize_pool_volume(
|
|
241
|
+
pool: PoolRef, volume: VolumeRef, capacity: int, *, flags: int = 0
|
|
242
|
+
) -> Operation[Volume]:
|
|
243
|
+
"""Change the capacity of a volume.
|
|
244
|
+
|
|
245
|
+
:param pool: the pool.
|
|
246
|
+
:param volume: a name, a key or an absolute path, or a ``Volume`` model.
|
|
247
|
+
:param capacity: the new capacity, in bytes.
|
|
248
|
+
:param flags: ``virStorageVolResizeFlags``.
|
|
249
|
+
:returns: the volume with the new capacity.
|
|
250
|
+
"""
|
|
251
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
252
|
+
found = yield from one_handle(volume_lookup(handle, volume))
|
|
253
|
+
yield Request(
|
|
254
|
+
"storage_vol_resize", {"vol": found, "capacity": capacity, "flags": flags}
|
|
255
|
+
)
|
|
256
|
+
return (yield from fetch_model("storage_vol_get_xml_desc", found, Volume))
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def wipe_pool_volume(pool: PoolRef, volume: VolumeRef) -> Operation[None]:
|
|
260
|
+
"""Overwrite the data of a volume.
|
|
261
|
+
|
|
262
|
+
:param pool: the pool.
|
|
263
|
+
:param volume: a name, a key or an absolute path, or a ``Volume`` model.
|
|
264
|
+
"""
|
|
265
|
+
handle = yield from one_handle(pool_lookup(pool))
|
|
266
|
+
found = yield from one_handle(volume_lookup(handle, volume))
|
|
267
|
+
yield Request("storage_vol_wipe", {"vol": found, "flags": 0})
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Operations that read facts about storage pools and volumes."""
|
|
2
|
+
|
|
3
|
+
from libvirtpy.client.operations._common import (
|
|
4
|
+
as_bool,
|
|
5
|
+
as_struct,
|
|
6
|
+
as_text,
|
|
7
|
+
as_xml,
|
|
8
|
+
fetch_model,
|
|
9
|
+
on_pool,
|
|
10
|
+
on_volume,
|
|
11
|
+
one_handle,
|
|
12
|
+
)
|
|
13
|
+
from libvirtpy.client.references import (
|
|
14
|
+
PoolRef,
|
|
15
|
+
VolumeRef,
|
|
16
|
+
pool_lookup,
|
|
17
|
+
volume_lookup,
|
|
18
|
+
)
|
|
19
|
+
from libvirtpy.client.transport import Operation, Request
|
|
20
|
+
from libvirtpy.rpc.protocol import types
|
|
21
|
+
from libvirtpy.xml.storage import Pool, Volume
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"create_pool_volume_from",
|
|
25
|
+
"find_pool_sources",
|
|
26
|
+
"get_pool_info",
|
|
27
|
+
"get_pool_volume_info",
|
|
28
|
+
"get_pool_volume_path",
|
|
29
|
+
"is_pool_active",
|
|
30
|
+
"is_pool_persistent",
|
|
31
|
+
"lookup_pool_by_target_path",
|
|
32
|
+
"lookup_pool_by_volume",
|
|
33
|
+
"wipe_pool_volume_with_pattern",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_pool_info(pool: PoolRef) -> Operation[types.StoragePoolGetInfoRet]:
|
|
38
|
+
"""Return the state and the sizes of a storage pool.
|
|
39
|
+
|
|
40
|
+
:param pool: the pool.
|
|
41
|
+
:returns: ``state`` (``virStoragePoolState``) and ``capacity``, ``allocation``
|
|
42
|
+
and ``available`` in bytes.
|
|
43
|
+
"""
|
|
44
|
+
reply = yield from on_pool(pool, "storage_pool_get_info")
|
|
45
|
+
return as_struct(reply, types.StoragePoolGetInfoRet)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def is_pool_active(pool: PoolRef) -> Operation[bool]:
|
|
49
|
+
"""Tell whether a storage pool is started.
|
|
50
|
+
|
|
51
|
+
:param pool: the pool.
|
|
52
|
+
:returns: ``True`` if it is active.
|
|
53
|
+
"""
|
|
54
|
+
return as_bool((yield from on_pool(pool, "storage_pool_is_active")))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def is_pool_persistent(pool: PoolRef) -> Operation[bool]:
|
|
58
|
+
"""Tell whether a storage pool has a stored configuration.
|
|
59
|
+
|
|
60
|
+
:param pool: the pool.
|
|
61
|
+
:returns: ``True`` if persistent, ``False`` if transient.
|
|
62
|
+
"""
|
|
63
|
+
return as_bool((yield from on_pool(pool, "storage_pool_is_persistent")))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def lookup_pool_by_target_path(path: str) -> Operation[Pool]:
|
|
67
|
+
"""Find the storage pool whose target is a directory.
|
|
68
|
+
|
|
69
|
+
:param path: the target path of the pool.
|
|
70
|
+
:returns: the pool.
|
|
71
|
+
:raises NoStoragePoolError: if no pool has that target.
|
|
72
|
+
"""
|
|
73
|
+
found = yield from one_handle(
|
|
74
|
+
Request("storage_pool_lookup_by_target_path", {"path": path})
|
|
75
|
+
)
|
|
76
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", found, Pool))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def lookup_pool_by_volume(pool: PoolRef, volume: VolumeRef) -> Operation[Pool]:
|
|
80
|
+
"""Find the pool a volume belongs to.
|
|
81
|
+
|
|
82
|
+
:param pool: a pool that contains the volume (it is needed to find it).
|
|
83
|
+
:param volume: the volume.
|
|
84
|
+
:returns: the pool of the volume.
|
|
85
|
+
"""
|
|
86
|
+
pool_handle = yield from one_handle(pool_lookup(pool))
|
|
87
|
+
volume_handle = yield from one_handle(volume_lookup(pool_handle, volume))
|
|
88
|
+
found = yield from one_handle(
|
|
89
|
+
Request("storage_pool_lookup_by_volume", {"vol": volume_handle})
|
|
90
|
+
)
|
|
91
|
+
return (yield from fetch_model("storage_pool_get_xml_desc", found, Pool))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_pool_volume_info(
|
|
95
|
+
pool: PoolRef, volume: VolumeRef, *, flags: int = 0
|
|
96
|
+
) -> Operation[types.StorageVolGetInfoFlagsRet]:
|
|
97
|
+
"""Return the type and the sizes of a volume.
|
|
98
|
+
|
|
99
|
+
:param pool: the pool.
|
|
100
|
+
:param volume: the volume.
|
|
101
|
+
:param flags: ``virStorageVolInfoFlags``: 1 the real size on the host.
|
|
102
|
+
:returns: ``type`` (``virStorageVolType``), ``capacity`` and ``allocation`` in
|
|
103
|
+
bytes.
|
|
104
|
+
"""
|
|
105
|
+
reply = yield from on_volume(
|
|
106
|
+
pool, volume, "storage_vol_get_info_flags", flags=flags
|
|
107
|
+
)
|
|
108
|
+
return as_struct(reply, types.StorageVolGetInfoFlagsRet)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def get_pool_volume_path(pool: PoolRef, volume: VolumeRef) -> Operation[str]:
|
|
112
|
+
"""Return the path of a volume on the host.
|
|
113
|
+
|
|
114
|
+
:param pool: the pool.
|
|
115
|
+
:param volume: the volume.
|
|
116
|
+
:returns: the absolute path.
|
|
117
|
+
"""
|
|
118
|
+
return as_text((yield from on_volume(pool, volume, "storage_vol_get_path")))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def create_pool_volume_from(
|
|
122
|
+
pool: PoolRef,
|
|
123
|
+
volume: Volume | str,
|
|
124
|
+
source: VolumeRef,
|
|
125
|
+
*,
|
|
126
|
+
source_pool: PoolRef | None = None,
|
|
127
|
+
flags: int = 0,
|
|
128
|
+
) -> Operation[Volume]:
|
|
129
|
+
"""Create a volume as a copy of another one.
|
|
130
|
+
|
|
131
|
+
:param pool: the pool of the new volume.
|
|
132
|
+
:param volume: the new volume's description, as a model or XML.
|
|
133
|
+
:param source: the volume to copy.
|
|
134
|
+
:param source_pool: the pool of ``source``; ``pool`` if left out.
|
|
135
|
+
:param flags: ``virStorageVolCreateFlags``.
|
|
136
|
+
:returns: the new volume as the daemon created it.
|
|
137
|
+
"""
|
|
138
|
+
target = yield from one_handle(pool_lookup(pool))
|
|
139
|
+
origin_pool = yield from one_handle(pool_lookup(source_pool or pool))
|
|
140
|
+
origin = yield from one_handle(volume_lookup(origin_pool, source))
|
|
141
|
+
|
|
142
|
+
created = yield from one_handle(
|
|
143
|
+
Request(
|
|
144
|
+
"storage_vol_create_xml_from",
|
|
145
|
+
{
|
|
146
|
+
"pool": target,
|
|
147
|
+
"xml": as_xml(volume),
|
|
148
|
+
"clonevol": origin,
|
|
149
|
+
"flags": flags,
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
return (yield from fetch_model("storage_vol_get_xml_desc", created, Volume))
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def wipe_pool_volume_with_pattern(
|
|
157
|
+
pool: PoolRef, volume: VolumeRef, algorithm: int, *, flags: int = 0
|
|
158
|
+
) -> Operation[None]:
|
|
159
|
+
"""Overwrite a volume with a pattern.
|
|
160
|
+
|
|
161
|
+
:param pool: the pool.
|
|
162
|
+
:param volume: the volume.
|
|
163
|
+
:param algorithm: ``virStorageVolWipeAlgorithm``: 0 zero, 1 NNSA, 2 DoD,
|
|
164
|
+
3 BSI, 4 Gutmann, 5 Schneier, 6 Pfitzner (7 passes), 7 Pfitzner (33),
|
|
165
|
+
8 random, 9 trim.
|
|
166
|
+
:param flags: reserved, 0.
|
|
167
|
+
"""
|
|
168
|
+
yield from on_volume(
|
|
169
|
+
pool, volume, "storage_vol_wipe_pattern", algorithm=algorithm, flags=flags
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def find_pool_sources(
|
|
174
|
+
pool_type: str, spec: str | None = None, *, flags: int = 0
|
|
175
|
+
) -> Operation[str]:
|
|
176
|
+
"""Discover possible sources for a new storage pool (for example NFS exports).
|
|
177
|
+
|
|
178
|
+
:param pool_type: the pool type (``netfs``, ``logical``, ``iscsi``, ...).
|
|
179
|
+
:param spec: the source description as XML (``<source><host
|
|
180
|
+
name=.../></source>``).
|
|
181
|
+
:param flags: reserved, 0.
|
|
182
|
+
:returns: the sources found, as ``<sources>`` XML.
|
|
183
|
+
"""
|
|
184
|
+
reply = yield Request(
|
|
185
|
+
"connect_find_storage_pool_sources",
|
|
186
|
+
{"type": pool_type, "src_spec": spec, "flags": flags},
|
|
187
|
+
)
|
|
188
|
+
return as_text(reply)
|