[lxc-devel] [pylxd/master] Handle mode/uid/gid in FilesManager.put()

keesbos on Github lxc-bot at linuxcontainers.org
Thu Dec 22 14:26:20 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161222/8449db07/attachment.bin>
-------------- next part --------------
From cb9c3eb3490cd4300157a4db28d4662c63089205 Mon Sep 17 00:00:00 2001
From: Kees Bos <cornelis.bos at gmail.com>
Date: Thu, 22 Dec 2016 15:23:48 +0100
Subject: [PATCH] Handle mode/uid/gid in FilesManager.put()

---
 pylxd/models/container.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/pylxd/models/container.py b/pylxd/models/container.py
index fde1b6b..ae186a3 100644
--- a/pylxd/models/container.py
+++ b/pylxd/models/container.py
@@ -77,7 +77,20 @@ def __init__(self, client, container):
             self._client = client
             self._container = container
 
-        def put(self, filepath, data):
+        def put(self, filepath, data, mode=None, uid=None, gid=None):
+
+            if isinstance(mode, int):
+                mode = oct(mode)
+            elif not mode.startswith('0'):
+                mode = '0{0}'.format(mode)
+            headers = {}
+            if mode is not None:
+                headers['X-LXD-mode'] = mode
+            if uid is not None:
+                headers['X-LXD-uid'] = str(uid)
+            if gid is not None:
+                headers['X-LXD-gid'] = str(gid)
+
             response = self._client.api.containers[
                 self._container.name].files.post(
                 params={'path': filepath}, data=data)


More information about the lxc-devel mailing list