[lxc-devel] [pylxd/master] Add support for container and snapshot publish.
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/157 This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Snapshot publish is broken in LXD, but this is a guess for how it is supposed to work, based on how it works in container publish. From 592646263f05d1a2bfe70ced05eae08d4e74930e Mon Sep 17 00:00:00 2001 From: Paul Hummer Date: Tue, 12 Jul 2016 21:29:37 -0600 Subject: [PATCH] Add support for container and snapshot publish. Snapshot publish is broken in LXD, but this is a guess for how it is supposed to work, based on how it works in container publish. --- pylxd/container.py| 49 + pylxd/exceptions.py | 3 +++ pylxd/operation.py| 15 + pylxd/tests/test_container.py | 51 +++ 4 files changed, 114 insertions(+), 4 deletions(-) diff --git a/pylxd/container.py b/pylxd/container.py index 3f49b32..7495572 100644 --- a/pylxd/container.py +++ b/pylxd/container.py @@ -289,6 +289,30 @@ def migrate(self, new_client, wait=False): } return new_client.containers.create(config, wait=wait) +def publish(self, public=False, wait=False): +"""Publish a container as an image. + +The container must be stopped in order publish it as an image. This +method does not enforce that constraint, so a LXDAPIException may be +raised if this method is called on a running container. + +If wait=True, an Image is returned. +""" +data = { +'public': public, +'source': { +'type': 'container', +'name': self.name, +} +} + +response = self.client.api.images.post(json=data) +if wait: +operation = Operation.wait_for_operation( +self.client, response.json()['operation']) + +return self.client.images.get(operation.metadata['fingerprint']) + class _CommandWebsocketClient(WebSocketBaseClient): # pragma: no cover def __init__(self, manager, *args, **kwargs): @@ -374,3 +398,28 @@ def rename(self, new_name, wait=False): Operation.wait_for_operation( self.client, response.json()['operation']) self.name = new_name + +def publish(self, public=False, wait=False): +"""Publish a snapshot as an image. + +If wait=True, an Image is returned. + +This functionality is currently broken in LXD. Please see +https://github.com/lxc/lxd/issues/2201 - The implementation +here is mostly a guess. Once that bug is fixed, we can verify +that this works, or file a bug to fix it appropriately. +""" +data = { +'public': public, +'source': { +'type': 'snapshot', +'name': '{}/{}'.format(self.container.name, self.name), +'alias': 'lololol', +} +} + +response = self.client.api.images.post(json=data) +if wait: +operation = Operation.wait_for_operation( +self.client, response.json()['operation']) +return self.client.images.get(operation.metadata['fingerprint']) diff --git a/pylxd/exceptions.py b/pylxd/exceptions.py index 36d8086..d5b6b5e 100644 --- a/pylxd/exceptions.py +++ b/pylxd/exceptions.py @@ -15,6 +15,9 @@ def __init__(self, response): self.response = response def __str__(self): +if self.response.status_code == 200: # Operation failure +return self.response.json()['metadata']['err'] + try: data = self.response.json() return data['error'] diff --git a/pylxd/operation.py b/pylxd/operation.py index 09c9d24..1594680 100644 --- a/pylxd/operation.py +++ b/pylxd/operation.py @@ -11,7 +11,7 @@ #WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #License for the specific language governing permissions and limitations #under the License. -import six +from pylxd import exceptions class Operation(object): @@ -27,7 +27,7 @@ def wait_for_operation(cls, client, operation_id): """Get an operation and wait for it to complete.""" operation = cls.get(client, operation_id) operation.wait() -return operation +return cls.get(client, operation.id) @classmethod def get(cls, client, operation_id): @@ -39,9 +39,16 @@ def get(cls, client, operation_id): def __init__(self, **kwargs): super(Operation, self).__init__() -for key, value in six.iteritems(kwargs): +for key, value in kwargs.items(): setattr(self, key, value) def wait(self): """Wait for the operation to complete and return.""" -
[lxc-devel] [lxd/master] better errors when sanity checking devices
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2202 This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === let's always include the path, so it's obvious which device is broken. Signed-off-by: Tycho Andersen From 0f708ae6e2e04ff5b1beb399bf41c7b6f9a192b3 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Tue, 12 Jul 2016 12:33:32 -0600 Subject: [PATCH] better errors when sanity checking devices let's always include the path, so it's obvious which device is broken. Signed-off-by: Tycho Andersen --- lxd/container_lxc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go index 7cde497..5d1503b 100644 --- a/lxd/container_lxc.go +++ b/lxd/container_lxc.go @@ -3536,10 +3536,10 @@ func (c *containerLXC) createUnixDevice(name string, m shared.Device) (string, e // If no major and minor are set, use those from the device on the host _, major, minor, err = deviceGetAttributes(srcPath) if err != nil { - return "", fmt.Errorf("Failed to get device attributes: %s", err) + return "", fmt.Errorf("Failed to get device attributes for %s: %s", m["path"], err) } } else if m["major"] == "" || m["minor"] == "" { - return "", fmt.Errorf("Both major and minor must be supplied for devices") + return "", fmt.Errorf("Both major and minor must be supplied for device: %s", m["path"]) } else { major, err = strconv.Atoi(m["major"]) if err != nil { ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxd/master] don't fail db upgrade if $LXD_DIR/containers doesn't exist
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2199 This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === The user may not have actually started LXD or imported any containers, so let's not fail in this case. Launchpad #1602025 Signed-off-by: Tycho Andersen From c3c749cb78fe2c13a12decec9eb7fd68aac0 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Tue, 12 Jul 2016 08:38:31 -0600 Subject: [PATCH] don't fail db upgrade if $LXD_DIR/containers doesn't exist The user may not have actually started LXD or imported any containers, so let's not fail in this case. Launchpad #1602025 Signed-off-by: Tycho Andersen --- lxd/db_update.go | 7 +++ 1 file changed, 7 insertions(+) diff --git a/lxd/db_update.go b/lxd/db_update.go index db5c913..b3c6894 100644 --- a/lxd/db_update.go +++ b/lxd/db_update.go @@ -136,6 +136,13 @@ func dbUpdateFromV30(currentVersion int, version int, d *Daemon) error { entries, err := ioutil.ReadDir(shared.VarPath("containers")) if err != nil { + /* If the directory didn't exist before, the user had never +* started containers, so we don't need to fix up permissions +* on anything. +*/ + if os.IsNotExist(err) { + return nil + } return err } ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxc/lxc] ceecc9: add missing cgroup namespace to ns_info struct
Branch: refs/heads/master Home: https://github.com/lxc/lxc Commit: ceecc92c422a19bf580ed3c6c854e832000d4b47 https://github.com/lxc/lxc/commit/ceecc92c422a19bf580ed3c6c854e832000d4b47 Author: Christian Brauner Date: 2016-07-11 (Mon, 11 Jul 2016) Changed paths: M src/lxc/start.c M src/lxc/start.h Log Message: --- add missing cgroup namespace to ns_info struct Signed-off-by: Christian Brauner Commit: a4abe1bbb531417decc2493b2beadb960258b100 https://github.com/lxc/lxc/commit/a4abe1bbb531417decc2493b2beadb960258b100 Author: Stéphane Graber Date: 2016-07-12 (Tue, 12 Jul 2016) Changed paths: M src/lxc/start.c M src/lxc/start.h Log Message: --- Merge pull request #1078 from brauner/2016-07-11/add_cgns add missing cgroup namespace to ns_info struct Compare: https://github.com/lxc/lxc/compare/9e390993d482...a4abe1bbb531___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel