Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
New: basic support for LXC profiles. Refs #68 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingxiaoyang authored and ellmetha committed May 12, 2017
1 parent 8707408 commit 3b87dc6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/conf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ Here is an example on how to set up a privileged container in your LXDock file:

Please refer to :doc:`glossary` for more details on these notions.

profiles
----------

The ``profiles`` option defines the configuration profiles to use when creating containers. It should
contain a list of profile names that exist in ``lxc profile list``. Please use ``lxc profile`` command
to manage profiles as they are system-wide.

.. code-block:: yaml
name: myproject
image: ubuntu/xenial
profiles:
- default
- docker
containers:
- name: test01
- name: test02
protocol
--------

Expand Down
2 changes: 2 additions & 0 deletions docs/release_notes/v0.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ New features
`#75 <https://github.com/lxdock/lxdock/pull/75>`_)
* Add support for passing a command line with ``lxdock shell``
(`#67 <https://github.com/lxdock/lxdock/pull/67>`_)
* Add basic support for LXC profile in LXDock files
(`#77 <https://github.com/lxdock/lxdock/pull/77>`_)
1 change: 1 addition & 0 deletions lxdock/conf/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'lxc_config': {Extra: str},
'mode': In(['local', 'pull', ]),
'privileged': bool,
'profiles': [str, ],
'protocol': In(['lxd', 'simplestreams', ]),
'provisioning': [], # will be set dynamically using provisioner classes...
'server': Url(),
Expand Down
4 changes: 4 additions & 0 deletions lxdock/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ def _get_container(self, create=True):
'config': lxc_config,
}

profiles = self.options.get('profiles')
if profiles:
container_config['profiles'] = profiles.copy()

try:
return self.client.containers.create(container_config, wait=True)
except LXDAPIException as e:
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import types
import unittest.mock

import pytest
from pylxd.exceptions import NotFound

from lxdock import constants
from lxdock.container import Container, must_be_created_and_running
from lxdock.exceptions import ContainerOperationFailed
from lxdock.test.testcases import LXDTestCase


Expand Down Expand Up @@ -252,3 +254,20 @@ def mock_create(container_config, *args, **kwargs):
assert container._get_container() is cont_return
assert client_mock.containers.get.called
assert client_mock.containers.create.called

def test_can_set_profiles(self):
container_options = {
'name': self.containername('newcontainer'), 'image': 'ubuntu/xenial', 'mode': 'pull',
'profiles': ['default']}
container = Container('myproject', THIS_DIR, self.client, **container_options)
container.up()
assert container._container.status_code == constants.CONTAINER_RUNNING
assert container._container.profiles == ['default']

def test_raises_an_error_if_profile_does_not_exist(self):
container_options = {
'name': self.containername('newcontainer'), 'image': 'ubuntu/xenial', 'mode': 'pull',
'profiles': ['default', '39mJQrJcZ5vIKJVIfwsKOZajhbPw0']}
container = Container('myproject', THIS_DIR, self.client, **container_options)
with pytest.raises(ContainerOperationFailed):
container.up()

0 comments on commit 3b87dc6

Please sign in to comment.