craft_providers.lxd.launcher module

LXD Instance Provider.

craft_providers.lxd.launcher.launch(name, *, base_configuration, image_name, image_remote, auto_clean=False, auto_create_project=False, ephemeral=False, map_user_uid=False, uid=None, use_snapshots=None, use_base_instance=False, project='default', remote='local', lxc=<craft_providers.lxd.lxc.LXC object>)[source]

Create, start, and configure an instance.

On the first run of an application, an instance will be launched from an image (i.e. an image from https://cloud-images.ubuntu.com). The instance is setup according to the Base configuration passed to this function.

After setup, a copy of this instance is saved (or cached) as a ‘base instance’. This is done to reduce setup time on subsequent runs. When the application requests a new instance on a subsequent run, the base instance will be copied to create the new instance. This instance is run through a small subset of the setup, which is referred to as ‘warmup’.

To keep build environments clean, consistent, and up-to-date, any base instance older than 3 months (90 days) is deleted and recreated.

Parameters
  • name (str) – Name of instance.

  • base_configuration (Base) – Base configuration to apply to the instance.

  • image_name (str) – LXD image to use, e.g. “20.04”.

  • image_remote (str) – LXD image to use, e.g. “ubuntu”.

  • auto_clean (bool) – If true and the existing instance is incompatible, then the

instance will be deleted and rebuilt. If false and the existing instance is incompatible, then a BaseCompatibilityError is raised. :type auto_create_project: bool :param auto_create_project: Automatically create LXD project, if needed. :type ephemeral: bool :param ephemeral: After the instance is stopped, delete it. Non-ephemeral instances cannot be converted to ephemeral instances, so if the instance already exists, it will be deleted, then recreated as an ephemeral instance. :type map_user_uid: bool :param map_user_uid: Map host uid/gid to instance’s root uid/gid. :type uid: Optional[int] :param uid: The uid to be mapped, if map_user_id is enabled. :type use_base_instance: Optional[bool] :param use_base_instance: Use the base instance mechanisms to reduce setup time. :type use_snapshots: Optional[bool] :param use_snapshots: Deprecated parameter replaced by use_base_instance. :type project: str :param project: LXD project to create instance in. :type remote: str :param remote: LXD remote to create instance on. :type lxc: LXC :param lxc: LXC client.

Return type

LXDInstance

Returns

LXD instance.

Raises