Python API¶
The API allows you to perform actions on instances programmatically. Below is an example of changing parameters and launching the myinstance instance.
import logging
from compute import Session
logging.basicConfig(level=logging.DEBUG)
with Session() as session:
instance = session.get_instance('myinstance')
instance.set_vcpus(4)
instance.start()
instance.set_autostart(enabled=True)
Session
context manager provides an abstraction over libvirt.virConnect
and returns objects of other classes of the present library.
Entity representation¶
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
Volume
.
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 VolumeConfig
.
Pydantic models are used to validate input data.
For example VolumeSchema
.
Modules documentation¶
session
instance
instance
Instance
Instance.__init__()
Instance.attach_device()
Instance.delete()
Instance.delete_ssh_keys()
Instance.detach_device()
Instance.detach_disk()
Instance.dump_xml()
Instance.get_disks()
Instance.get_info()
Instance.get_max_memory()
Instance.get_max_vcpus()
Instance.get_ssh_keys()
Instance.get_status()
Instance.is_autostart()
Instance.is_running()
Instance.pause()
Instance.power_reset()
Instance.reboot()
Instance.reset()
Instance.resize_disk()
Instance.resume()
Instance.set_autostart()
Instance.set_memory()
Instance.set_ssh_keys()
Instance.set_user_password()
Instance.set_vcpus()
Instance.shutdown()
Instance.start()
InstanceConfig
InstanceInfo
guest_agent
schemas
storage
utils
exceptions