Networks

Network objects show the current networks available to LXD. Creation and / or modification of networks is possible only if ‘network’ LXD API extension is present (see network_extension_available())

Manager methods

Networks can be queried through the following client manager methods:

  • all() - Retrieve all networks.
  • exists() - See if a profile with a name exists. Returns bool.
  • get() - Get a specific network, by its name.
  • create() - Create a new network. The name of the network is required. description, type and config are optional and the scope of their contents is documented in the LXD documentation.

Network attributes

  • name - The name of the network.
  • description - The description of the network.
  • type - The type of the network.
  • used_by - A list of containers using this network.
  • config - The configuration associated with the network.
  • managed - boolean; whether LXD manages the network.

Profile methods

  • rename() - Rename the network.
  • save() - Save the network. This uses the PUT HTTP method and not the PATCH.
  • delete() - Deletes the network.

Examples

Network operations follow the same manager-style as other classes. Networks are keyed on a unique name.

>>> network = client.networks.get('lxdbr0')

>>> network
Network(config={"ipv4.address": "10.74.126.1/24", "ipv4.nat": "true", "ipv6.address": "none"}, description="", name="lxdbr0", type="bridge")

>>> print(network)
{
  "name": "lxdbr0",
  "description": "",
  "type": "bridge",
  "config": {
    "ipv4.address": "10.74.126.1/24",
    "ipv4.nat": "true",
    "ipv6.address": "none"
  },
  "managed": true,
  "used_by": []
}

The network can then be modified and saved.

>>> network.config['ipv4.address'] = '10.253.10.1/24'
>>> network.save()

To create a new network, use create() with a name, and optional arguments: description and type and config.

>>> network = client.networks.create(
...     'lxdbr1', description='My new network', type='bridge', config={})
>>> network = client.networks.create(
...     'lxdbr1', description='My new network', type='bridge', config={})
>>> network = client.networks.create(
...     'lxdbr1', description='My new network', type='bridge', config={})