Metadata-Version: 2.5
Name: trytond_strings_xo_compute
Version: 8.0.0.3
Summary: Xen Orchestra Compute Inventory
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: inventory,orchestra,tryton,virtualization,xcp-ng,xen
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Requires-Dist: trytond-company<8.1,>=8.0
Requires-Dist: trytond-strings-xo-infrastructure<8.1,>=8.0
Requires-Dist: trytond-strings-xo<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Description-Content-Type: text/x-rst

Xen Orchestra Compute
=====================

The ``strings_xo_compute`` module mirrors the compute inventory of a
Xen Orchestra (XO) instance into Tryton: the virtual machines, the
templates and the disk and network attachments of the ``/vms``,
``/vm-templates``, ``/vbds`` and ``/vifs`` collections are kept in sync
as read-only records.

Features
--------

- **Virtual machines**: name, description, power state, pool, host,
  template, CPU number and topology, CPU weight and cap, memory size,
  usage and dynamic range, primary address and guest address list,
  operating system and its details, BIOS strings, other configuration,
  tags, notes, secure boot, auto power on, high availability policy,
  resource set, virtualization mode, start, install and start delay.
- **Templates**: name, description, pool, CPU topology, memory,
  operating system, template information (disks and install methods),
  default template flag, secure boot, virtualization mode, tags and
  notes.
- **Power and lifecycle actions**: a virtual machine is started, paused,
  suspended, shut down and rebooted through the power operations of Xen
  Orchestra, either gracefully or by destroying the guest.  An action is
  guarded by the power state of the machine, the destructive ones are
  confirmed by the user, and every action is tracked by an asynchronous
  task linked to the machine.
- **Disk attachments (VBD)**: virtual machine, disk, device, position,
  bootable, attached, read-only and CD drive flags.
- **Interfaces (VIF)**: virtual machine, network, device, MAC, MTU,
  address, attached flag, locking mode, rate limit, TX checksumming and
  the allowed IPv4 and IPv6 addresses.
- **Read-only synchronisation**: an idempotent upsert keyed on the
  ``(server, uuid)`` pair, driven from the Xen Orchestra REST API v0
  through the ``strings_xo`` client and the generic synchronisation
  framework of the ``strings_xo`` base module.  Records that are no
  longer reported by Xen Orchestra are deactivated instead of being
  deleted.
- **Relationships**: a virtual machine belongs to a pool, runs on a
  host and may reference a template; it owns its disk attachments and
  its interfaces, and its disks are resolved through the attachments; a
  disk exposes the machines it is attached to and the machine using it;
  a host, a pool and a network expose the machines and the interfaces
  they carry.
- **XVA export and import**: an archive of a virtual machine is
  streamed from Xen Orchestra to a destination and back without ever
  being buffered in memory.  An interrupted export is resumable and its
  archive is checksummed; an import only destroys a machine that is
  explicitly selected.
- **Security**: dedicated access rights reusing the ``strings_xo``
  groups, with read-only access for Xen Orchestra users and full access
  for the Xen Orchestra administration group.  The power operations are
  restricted to the administration groups: reading a machine never lets
  an operation through.

Integration
-----------

The module extends the models of ``strings_xo_infrastructure`` instead
of redefining them, as required by the VDI inventory of that module:

- ``xo.vdi`` gains the ``vbd_ids`` collection and the ``vm_ids`` and
  ``vm`` relations resolving the virtual machines using a disk.
- ``xo.host`` gains its ``vm_ids`` collection.
- ``xo.network`` gains its ``vif_ids`` collection.
- ``xo.server`` gains the compute collections, the *Sync Compute*
  button and the resolution of the interface addresses.
- ``xo.task`` gains the virtual machine as a target model, so that the
  task started by an action is linked to the machine it acts upon.

Xen Orchestra reports templates as a distinct object type served by the
``/vm-templates`` collection instead of a flag on the virtual machines,
therefore the templates are mirrored by the dedicated ``xo.vm.template``
model rather than by an ``is_template`` flag on ``xo.vm``.

Xen Orchestra does not report the template of a virtual machine, the
address of an interface nor the host of a machine directly: the host is
resolved from the ``$container`` of the machine (the host it runs on, or
the pool of a machine that is not running) and the address of an
interface is resolved from the guest addresses reported on its machine.

XVA Export and Import
---------------------

A *destination* (``xo.xva.destination``) is a configured location the
archives are written to and read from.  A destination is a directory of
the server running Tryton today; the model is the extension point for
the other storage backends of the suite, which register their own type.
The directory must exist and be writable by the user running Tryton,
and the name of an archive is restricted to the last component of the
requested name, so that a crafted name can neither leave the
destination nor address a hidden file.

An export streams ``GET /rest/v0/vms/<uuid>.<format>`` into a partial
file of the destination, which is renamed once the archive is complete;
the checksum covers the whole archive.  Xen Orchestra does not announce
the size of the streamed archive, so the progress of an export is only
known once it completes.  An interrupted export resumes from the
partial file it left behind when Xen Orchestra honours the ranged
request, and starts over otherwise.

An import streams ``POST /rest/v0/pools/<pool>/vms`` from an archive of
the destination, optionally into a given storage repository.  An
existing machine is only destroyed when it is explicitly selected in
the transfer: the machine to replace is never inferred from the
archive.  The archive itself is only read, which makes a failed import
safe to retry.

A transfer is created in the ``queued`` state and processed by the
scheduled *Xen Orchestra: Process XVA Transfers* action; the *Run*
button and the *Process XVA* button of a server process the selected
transfers immediately.  A transfer is only cancellable while it has not
started: a transfer that is already running cannot be stopped, its
stream being driven by the process performing it.  The counters of a
transfer are written in the transaction of the caller, so a run
publishes its journal and its counters when it completes.

Power and Lifecycle Actions
---------------------------

The power operations of Xen Orchestra are exposed as buttons of a
virtual machine, grouped on its form and, for the most common ones, on
its list:

- ``start`` and ``start_on`` power a halted machine on, the latter on a
  host selected in the *Start on Host* wizard, which is the only
  operation taking a parameter;
- ``pause``, ``unpause``, ``suspend`` and ``resume`` change the state of
  a machine without ending its guest;
- ``shutdown``, ``clean_shutdown``, ``reboot`` and ``clean_reboot`` stop
  or restart a running machine gracefully;
- ``hard_shutdown`` and ``hard_reboot`` destroy the guest.

An action is guarded by the power state the machine reports: its button
is hidden outside of the states the operation applies to, and the guard
is enforced again when the button is pressed, so that an inconsistent
state never reaches Xen Orchestra.  A machine reporting an unknown power
state is never guarded, the server remaining the authority; a selection
containing an impossible action is refused as a whole and no machine is
acted upon.

The operations destroying the guest are confirmed by the user before
the task is started.  The confirmation is remembered per user and per
action, so that acknowledging a hard shutdown never acknowledges a hard
reboot.

Every action starts a task of the Xen Orchestra instance, mirrored by
the ``xo.task`` model of the ``strings_xo`` base module and linked to
the machine it acts upon.  The tasks of a machine are listed in the
*Lifecycle* page of its form, where their state and their error are
read, and they are followed by the scheduled task polling of the base
module; the *Poll* and *Show Error* buttons of a task and the
*Poll Tasks* button of a server act on them as on any other task.

Configuration
-------------

After installing the module, open *Xen Orchestra > Servers* and use the
*Sync Compute* button on a server to pull its compute inventory.  The
whole inventory is synchronised by the *Sync* button, the *Manual Sync*
wizard and the scheduled *Xen Orchestra: Synchronise* action.  The
synchronised compute inventory is available under *Xen Orchestra >
Compute*.

The XVA transfers are configured in the ``[strings_xo]`` section of
``trytond.conf``:

- ``xva_cron`` — whether the queued transfers are processed by the
  scheduled action; defaults to enabled.  When it is disabled, the
  wizards process the transfers they create immediately.
- ``xva_chunk_size`` — the size in bytes of the chunks an archive is
  streamed in; defaults to 1 MiB.
- ``xva_progress_interval`` — the number of bytes between two progress
  updates of a running transfer; defaults to 16 MiB.  The intermediate
  updates are disabled with ``0``.

Dependencies
------------

- Tryton modules: ``ir``, ``res``, ``company``, ``strings_xo``,
  ``strings_xo_infrastructure``.

Models
------

- ``xo.vm`` — ``XOVM``: a virtual machine.
- ``xo.vm.template`` — ``XOVMTemplate``: a virtual machine template.
- ``xo.vm.vbd`` — ``XOVMBD``: a disk attachment of a virtual machine.
- ``xo.vm.vif`` — ``XOVMIF``: an interface of a virtual machine.
- ``xo.xva.destination`` — ``XOXVADestination``: a location the XVA
  archives are stored in.
- ``xo.xva.transfer`` — ``XOXVATransfer``: one export or one import of
  an archive.

Cron Jobs
---------

The module plugs into the generic *Xen Orchestra: Synchronise*
(``xo.server|sync_cron``) scheduled action of the ``strings_xo`` base
module, which synchronises the whole inventory of every active server.

The module also registers the *Xen Orchestra: Process XVA Transfers*
(``xo.xva.transfer|process_cron``) scheduled action, which processes
the queued XVA transfers of every server.  An error on a single
transfer is recorded on the transfer and does not abort the run.

Wizards
-------

The module plugs into the generic *Manual Sync* wizard of the
``strings_xo`` base module.  The *Sync Compute* button of a server
synchronises the compute collections only.

The module adds the *Export XVA* wizard, opened from the *Export XVA*
button of a virtual machine, and the *Import XVA* wizard.  Both create
their transfers in the ``queued`` state and process them immediately
when the ``xva_cron`` setting is disabled.

The module also adds the *Start on Host* wizard, opened from the *Start
on Host* button of a virtual machine, which starts the selected
machines on a host of their own server and reports the tasks it
started.  Every other power operation is run directly from its button.
