API documentation


class pylxd.client.Client(endpoint=None, version='1.0', cert=None, verify=True)

Client class for LXD REST API.

This client wraps all the functionality required to interact with LXD, and is meant to be the sole entry point.


Instance of Client.Containers:


Instance of Client.Images.


Instance of Client.Operations.


Instance of Client.Profiles.


This attribute provides tree traversal syntax to LXD’s REST API for lower-level interaction.

Use the name of the url part as attribute or item of an api object to create another api object appended with the new url part name, ie:

>>> api = Client().api
# /
>>> response = api.get()
# Check status code and response
>>> print response.status_code, response.json()
# /containers/test/
>>> print api.containers['test'].get().json()

Get a websocket client for getting events.

/events is a websocket url, and so must be handled differently than most other LXD API endpoints. This method returns a client that can be interacted with like any regular python socket.

An optional websocket_client parameter can be specified for implementation-specific handling of events as they occur.


class pylxd.certificate.Certificate(client, **kwargs)

A LXD certificate.

classmethod all(client)

Get all certificates.

classmethod create(client, password, cert_data)

Create a new certificate.

classmethod get(client, fingerprint)

Get a certificate by fingerprint.


class pylxd.container.Container(*args, **kwargs)

An LXD Container.

This class is not intended to be used directly, but rather to be used via Client.containers.create.

class FilesManager(client, container)

A pseudo-manager for namespacing file operations.

classmethod all(client)

Get all containers.

Containers returned from this method will only have the name set, as that is the only property returned from LXD. If more information is needed, Container.sync is the method call that should be used.

classmethod create(client, config, wait=False)

Create a new container config.

execute(commands, environment={})

Execute a command on the container.

freeze(timeout=30, force=True, wait=False)

Freeze the container.

classmethod get(client, name)

Get a container by name.

migrate(new_client, wait=False)

Migrate a container.

Destination host information is contained in the client connection passed in.

If the container is running, it either must be shut down first or criu must be installed on the source and destination machines.

publish(public=False, wait=False)

Publish a container as an image.

The container must be stopped in order publish it as an image. This method does not enforce that constraint, so a LXDAPIException may be raised if this method is called on a running container.

If wait=True, an Image is returned.

rename(name, wait=False)

Rename a container.

restart(timeout=30, force=True, wait=False)

Restart the container.

start(timeout=30, force=True, wait=False)

Start the container.

stop(timeout=30, force=True, wait=False)

Stop the container.

unfreeze(timeout=30, force=True, wait=False)

Unfreeze the container.

class pylxd.container.Snapshot(client, **kwargs)

A container snapshot.

publish(public=False, wait=False)

Publish a snapshot as an image.

If wait=True, an Image is returned.

This functionality is currently broken in LXD. Please see https://github.com/lxc/lxd/issues/2201 - The implementation here is mostly a guess. Once that bug is fixed, we can verify that this works, or file a bug to fix it appropriately.

rename(new_name, wait=False)

Rename a snapshot.


class pylxd.image.Image(client, **kwargs)

A LXD Image.

add_alias(name, description)

Add an alias to the image.

classmethod all(client)

Get all images.

copy(new_client, public=None, auto_update=None, wait=False)

Copy an image to a another LXD.

Destination host information is contained in the client connection passed in.

classmethod create(client, image_data, public=False, wait=False)

Create an image.

classmethod create_from_simplestreams(client, server, alias, public=False, auto_update=False)

Copy an image from simplestreams.

classmethod create_from_url(client, url, public=False, auto_update=False)

Copy an image from an url.


Delete an alias from the image.


Export the image.

classmethod get(client, fingerprint)

Get an image.

classmethod get_by_alias(client, alias)

Get an image by its alias.


class pylxd.network.Network(client, **kwargs)

A LXD network.

classmethod all(client)

Get all networks.


Delete is not available for networks.

classmethod get(client, name)

Get a network by name.


Save is not available for networks.


class pylxd.operation.Operation(**kwargs)

A LXD operation.

classmethod get(client, operation_id)

Get an operation.


Wait for the operation to complete and return.

classmethod wait_for_operation(client, operation_id)

Get an operation and wait for it to complete.


class pylxd.profile.Profile(client, **kwargs)

A LXD profile.

classmethod all(client)

Get all profiles.

classmethod create(client, name, config=None, devices=None)

Create a profile.

classmethod get(client, name)

Get a profile.


Rename the profile.