Shortcut functions

Idempotent functions and shortcuts.

Functions here have the following similarities:

  • take a API as first argument,
  • return True if something has changed, False otherwise,
  • except _get() functions such as container_get() which return APIResult for an lxdapi.api.API.get() or False.
lxdapi.shortcuts.container_absent(api, container)[source]

Ensure a container is absent.

Container is an APIResult for the container, to be able to compare the configuration with.

It is expected that the user manages the HTTP transactions, here’s an example usage:

container_absent(api, container_get('yourcontainer'))
lxdapi.shortcuts.container_apply_config(api, container, config)[source]

Apply a configuration on a container.

Container is an:class:`lxdapi.api.APIResult`for the container, to be able to compare the configuration with.

Config is the dict to pass as JSON to the HTTP API.

Example usage:

container_apply_config(api, container_get('yourcontainer'))
lxdapi.shortcuts.container_apply_status(api, container, status)[source]

Apply an LXD status to a container.

Container is an:class:`lxdapi.api.APIResult`for the container, to be able to compare the status with.

Status is a string, choices are: Running, Stopped, Frozen.

Example usage:

container_apply_status(api, container_get('yourcontainer'), 'Running')
lxdapi.shortcuts.container_get(api, name)[source]

Return the:class:`lxdapi.api.APIResult`for a container or False.

lxdapi.shortcuts.image_absent(api, fingerprint)[source]

Return False if the image is absent, otherwise delete it and return True.

lxdapi.shortcuts.image_alias_present(api, name, target, description=None)[source]

Ensure an image has an alias.

lxdapi.shortcuts.image_get(api, fingerprint)[source]

Return the APIResult for a fingerprint or False.

lxdapi.shortcuts.image_get_fingerprint(path)[source]

Return the fingerprint for an image.

lxdapi.shortcuts.image_present(api, path, fingerprint=None)[source]

Ensure an image is present.