Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the instances and virtual-machines endpoints. #387

Merged
merged 5 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def stdout_handler(msg):

def test_publish(self):
"""A container is published."""
# Hack to get around mocked data
self.container.type = 'container'
image = self.container.publish(wait=True)

self.assertIn(
Expand Down
22 changes: 17 additions & 5 deletions pylxd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def __getattr__(self, name):
:returns: new _APINode with /<name> on the end
:rtype: _APINode
"""
# Special case for storage_pools which needs to become 'storage-pools'
if name == 'storage_pools':
name = 'storage-pools'
# '-' can't be used in variable names
if name in ('storage_pools', 'virtual_machines'):
name = name.replace('_', '-')
return self.__class__('{}/{}'.format(self._api_endpoint, name),
cert=self.session.cert,
verify=self.session.verify,
Expand Down Expand Up @@ -222,11 +222,21 @@ class Client(object):
This client wraps all the functionality required to interact with
LXD, and is meant to be the sole entry point.

.. attribute:: instances

Instance of :class:`Client.Instances
<pylxd.client.Client.Instances>`:

.. attribute:: containers

Instance of :class:`Client.Containers
<pylxd.client.Client.Containers>`:

.. attribute:: virtual_machines

Instance of :class:`Client.VirtualMachines
<pylxd.client.Client.VirtualMachines>`:

.. attribute:: images

Instance of :class:`Client.Images <pylxd.client.Client.Images>`.
Expand All @@ -253,8 +263,8 @@ class Client(object):
>>> response = api.get()
# Check status code and response
>>> print response.status_code, response.json()
# /containers/test/
>>> print api.containers['test'].get().json()
# /instances/test/
>>> print api.instances['test'].get().json()

"""

Expand Down Expand Up @@ -316,7 +326,9 @@ def __init__(

self.cluster = managers.ClusterManager(self)
self.certificates = managers.CertificateManager(self)
self.instances = managers.InstanceManager(self)
self.containers = managers.ContainerManager(self)
self.virtual_machines = managers.VirtualMachineManager(self)
self.images = managers.ImageManager(self)
self.networks = managers.NetworkManager(self)
self.operations = managers.OperationManager(self)
Expand Down
8 changes: 8 additions & 0 deletions pylxd/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class CertificateManager(BaseManager):
manager_for = 'pylxd.models.Certificate'


class InstanceManager(BaseManager):
manager_for = 'pylxd.models.Instance'


class ContainerManager(BaseManager):
manager_for = 'pylxd.models.Container'


class VirtualMachineManager(BaseManager):
manager_for = 'pylxd.models.VirtualMachine'


class ImageManager(BaseManager):
manager_for = 'pylxd.models.Image'

Expand Down
4 changes: 3 additions & 1 deletion pylxd/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pylxd.models.cluster import (Cluster, ClusterMember) # NOQA
from pylxd.models.certificate import Certificate # NOQA
from pylxd.models.container import Container, Snapshot # NOQA
from pylxd.models.instance import Instance, Snapshot # NOQA
from pylxd.models.container import Container # NOQA
from pylxd.models.virtual_machine import VirtualMachine # NOQA
from pylxd.models.image import Image # NOQA
from pylxd.models.network import Network # NOQA
from pylxd.models.operation import Operation # NOQA
Expand Down
5 changes: 4 additions & 1 deletion pylxd/models/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def __new__(cls, name, bases, attrs):
for_removal = []
managers = []

for base in bases:
if hasattr(base, '__attributes__'):
attributes.update(base.__attributes__)

for key, val in attrs.items():
if type(val) == Attribute:
attributes[key] = val
Expand Down Expand Up @@ -178,7 +182,6 @@ def sync(self, rollback=False):
if key not in self.__dirty__ or rollback:
try:
setattr(self, key, val)
self.__dirty__.remove(key)
except AttributeError:
# We have received an attribute from the server that we
# don't support in our model. Ignore this error, it
Expand Down
Loading