[lxc-devel] [pylxd/master] Adding feature of update container configuration

rooty0 on Github lxc-bot at linuxcontainers.org
Fri Aug 12 20:06:41 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 302 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160812/4d4b8f84/attachment.bin>
-------------- next part --------------
From 39b059b2002214eaf30eb11dc8b4c1bdfcd1f8aa Mon Sep 17 00:00:00 2001
From: Stan Rudenko <me at rooty.name>
Date: Fri, 12 Aug 2016 13:05:50 -0700
Subject: [PATCH] Adding feature of update container configuration

---
 doc/source/containers.rst | 11 +++++++++++
 pylxd/container.py        |  8 ++++++++
 2 files changed, 19 insertions(+)

diff --git a/doc/source/containers.rst b/doc/source/containers.rst
index 12aa035..9e06ebe 100644
--- a/doc/source/containers.rst
+++ b/doc/source/containers.rst
@@ -56,6 +56,7 @@ Container methods
   - `restart` - Restart the container
   - `freeze` - Suspend the container
   - `unfreeze` - Resume the container
+  - `config_set` - Update container's configuration
   - `execute` - Execute a command on the container. The first argument is
     a list, in the form of `subprocess.Popen` with each item of the command
     as a separate item in the list. Returns a two part tuple of
@@ -100,6 +101,16 @@ you'll pass `wait=True` as well.
     <container.Container at 0x7f95d8af72b0>
 
 
+An example how to change configuration of any container or server.
+This method requires a first argument that is the config dict where
+properties should be specified.
+
+.. code-block:: python
+
+   >>> container = client.containers.get('my-container')
+   >>> container.config_set( { "devices": { "root": { "path": "/", "size": "9GB", "type": "disk", } } } )
+
+
 If you were to use an actual image source, you would be able to operate
 on the container, starting, stopping, snapshotting, and deleting the
 container.
diff --git a/pylxd/container.py b/pylxd/container.py
index af7a115..9541e0b 100644
--- a/pylxd/container.py
+++ b/pylxd/container.py
@@ -133,6 +133,14 @@ def rename(self, name, wait=False):
                 self.client, response.json()['operation'])
         self.name = name
 
+    def config_set(self, params, wait=False):
+        """Setting up container configuration"""
+        response = self.api.put(json=params)
+
+        if wait:
+            Operation.wait_for_operation(
+                self.client, response.json()['operation'])
+
     def _set_state(self, state, timeout=30, force=True, wait=False):
         response = self.api.state.put(json={
             'action': state,


More information about the lxc-devel mailing list