2023-11-06 17:47:56 +03:00
|
|
|
Python API
|
|
|
|
==========
|
|
|
|
|
2023-12-01 01:39:26 +03:00
|
|
|
The API allows you to perform actions on instances programmatically.
|
2023-11-06 17:47:56 +03:00
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
2023-12-01 01:39:26 +03:00
|
|
|
import compute
|
2023-11-06 17:47:56 +03:00
|
|
|
|
2023-12-01 01:39:26 +03:00
|
|
|
with compute.Session() as session:
|
2023-11-06 17:47:56 +03:00
|
|
|
instance = session.get_instance('myinstance')
|
2023-12-01 01:39:26 +03:00
|
|
|
info = instance.get_info()
|
|
|
|
|
|
|
|
print(info)
|
2023-11-06 17:47:56 +03:00
|
|
|
|
|
|
|
|
2023-11-06 18:38:24 +03:00
|
|
|
:class:`Session` context manager provides an abstraction over :class:`libvirt.virConnect`
|
|
|
|
and returns objects of other classes of the present library.
|
2023-11-06 17:47:56 +03:00
|
|
|
|
2023-11-06 18:38:24 +03:00
|
|
|
Entity representation
|
|
|
|
---------------------
|
2023-11-06 17:47:56 +03:00
|
|
|
|
2023-11-06 18:38:24 +03:00
|
|
|
Entities such as a compute-instance are represented as classes. These classes directly
|
|
|
|
call libvirt methods to perform operations on the hypervisor. An example class is
|
|
|
|
:class:`Volume`.
|
2023-11-06 17:47:56 +03:00
|
|
|
|
2023-11-06 18:38:24 +03:00
|
|
|
The configuration files of various libvirt objects in `compute` are described by special
|
|
|
|
dataclasses. The dataclass stores object parameters in its properties and can return an
|
|
|
|
XML config for libvirt using the ``to_xml()`` method. For example :class:`VolumeConfig`.
|
2023-11-06 17:47:56 +03:00
|
|
|
|
2023-11-06 18:38:24 +03:00
|
|
|
`Pydantic <https://docs.pydantic.dev/>`_ models are used to validate input data.
|
|
|
|
For example :class:`VolumeSchema`.
|
2023-11-06 17:47:56 +03:00
|
|
|
|
2023-11-06 18:38:24 +03:00
|
|
|
Modules documentation
|
|
|
|
---------------------
|
2023-11-06 17:47:56 +03:00
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 4
|
|
|
|
|
|
|
|
session
|
|
|
|
instance/index
|
2023-11-06 18:38:24 +03:00
|
|
|
storage/index
|
2023-11-09 01:17:50 +03:00
|
|
|
utils
|
|
|
|
exceptions
|