{"action":"created","issue":{"url":"https://api.github.com/repos/lxc/lxd/issues/1772","repository_url":"https://api.github.com/repos/lxc/lxd","labels_url":"https://api.github.com/repos/lxc/lxd/issues/1772/labels{/name}","comments_url":"https://api.github.com/repos/lxc/lxd/issues/1772/comments","events_url":"https://api.github.com/repos/lxc/lxd/issues/1772/events","html_url":"https://github.com/lxc/lxd/issues/1772","id":141650848,"number":1772,"title":"Pulling an image fails when properties hash is passed","user":{"login":"jsuwo","id":898045,"avatar_url":"https://avatars.githubusercontent.com/u/898045?v=3","gravatar_id":"","url":"https://api.github.com/users/jsuwo","html_url":"https://github.com/jsuwo","followers_url":"https://api.github.com/users/jsuwo/followers","following_url":"https://api.github.com/users/jsuwo/following{/other_user}","gists_url":"https://api.github.com/users/jsuwo/gists{/gist_id}","starred_url":"https://api.github.com/users/jsuwo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsuwo/subscriptions","organizations_url":"https://api.github.com/users/jsuwo/orgs","repos_url":"https://api.github.com/users/jsuwo/repos","events_url":"https://api.github.com/users/jsuwo/events{/privacy}","received_events_url":"https://api.github.com/users/jsuwo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lxc/lxd/labels/Bug","name":"Bug","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/lxc/lxd/milestones/40","html_url":"https://github.com/lxc/lxd/milestones/lxd-2.0.0.rc5","labels_url":"https://api.github.com/repos/lxc/lxd/milestones/40/labels","id":1649363,"number":40,"title":"lxd-2.0.0.rc5","description":"","creator":{"login":"stgraber","id":2230599,"avatar_url":"https://avatars.githubusercontent.com/u/2230599?v=3","gravatar_id":"","url":"https://api.github.com/users/stgraber","html_url":"https://github.com/stgraber","followers_url":"https://api.github.com/users/stgraber/followers","following_url":"https://api.github.com/users/stgraber/following{/other_user}","gists_url":"https://api.github.com/users/stgraber/gists{/gist_id}","starred_url":"https://api.github.com/users/stgraber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stgraber/subscriptions","organizations_url":"https://api.github.com/users/stgraber/orgs","repos_url":"https://api.github.com/users/stgraber/repos","events_url":"https://api.github.com/users/stgraber/events{/privacy}","received_events_url":"https://api.github.com/users/stgraber/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":0,"state":"open","created_at":"2016-03-17T02:11:51Z","updated_at":"2016-03-17T17:27:02Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2016-03-17T17:26:03Z","updated_at":"2016-03-17T18:59:06Z","closed_at":null,"body":"# Required information\r\n\r\n * Distribution: Ubuntu\r\n * Distribution version: 14.04.4\r\n * The output of \"lxc info\" or if that fails:\r\n   * Kernel version: 3.19.0-43-generic\r\n   * LXC version: 1.1.5\r\n   * LXD version: 2.0.0.rc2\r\n   * Storage backend in use: btrfs\r\n\r\n# Issue description\r\n\r\nWhen `POST`-ing to `/1.0/images` with mode set to `pull` to copy an image from a remote LXD server, if you add a `properties` hash to the `POST`-ed data, the operation fails with an error.\r\n\r\n```\r\ncurl -k -X POST \\\r\n  -H \"Content-Type: application/json\" \\\r\n  -d '{\"auto_update\":true,\"public\":false,\"source\":{\"certificate\":\"\",\"fingerprint\":\"07d1a93ca98d3480b4b763c4defb9d05b082b764b1abac7a4dc00f482d6faf09\",\"mode\":\"pull\",\"protocol\":\"\",\"server\":\"https://images.linuxcontainers.org:8443\",\"type\":\"image\",\"properties\":{\"hello\":\"world\"}}}' \\\r\n  --key ~/.config/lxc/client.key \\\r\n  --cert ~/.config/lxc/client.crt \\\r\n  https://127.0.0.1:8443/1.0/images\r\n```\r\n\r\nError in the logs:\r\n\r\n```\r\nt=2016-03-17T12:52:26-0400 lvl=eror msg=\"Failed to get image metadata\" function=getImgPostInfo err=\"detectCompression failed, err='Unsupported compression.', tarfile='/var/lib/lxd/images/lxd_build_368759448/lxd_tar_798899082'\"\r\n```\r\n\r\nYet, when you *don't* add the `properties` hash, the operation succeeds.  The following works just fine and properly imports the image:\r\n\r\n```\r\n$ curl -k -X POST \\\r\n  -H \"Content-Type: application/json\" \\\r\n  -d '{\"auto_update\":true,\"public\":false,\"source\":{\"certificate\":\"\",\"fingerprint\":\"07d1a93ca98d3480b4b763c4defb9d05b082b764b1abac7a4dc00f482d6faf09\",\"mode\":\"pull\",\"protocol\":\"\",\"server\":\"https://images.linuxcontainers.org:8443\",\"type\":\"image\"}}' \\\r\n  --key ~/.config/lxc/client.key \\\r\n  --cert ~/.config/lxc/client.crt \\\r\n  https://127.0.0.1:8443/1.0/images\r\n\r\n$ lxc image list\r\n+-------+--------------+--------+----------------------------------------+--------+---------+------------------------------+\r\n| ALIAS | FINGERPRINT  | PUBLIC |              DESCRIPTION               |  ARCH  |  SIZE   |         UPLOAD DATE          |\r\n+-------+--------------+--------+----------------------------------------+--------+---------+------------------------------+\r\n|       | 07d1a93ca98d | no     | Ubuntu xenial (amd64) (20160317_03:49) | x86_64 | 84.12MB | Mar 17, 2016 at 5:23pm (UTC) |\r\n+-------+--------------+--------+----------------------------------------+--------+---------+------------------------------+\r\n```\r\n\r\nIf I import from a local tarball and specify the properties in the `X-LXD-properties` header, it also works just fine:\r\n\r\n```\r\n$ lxc image list\r\n+-------+-------------+--------+-------------+------+------+-------------+\r\n| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE |\r\n+-------+-------------+--------+-------------+------+------+-------------+\r\n\r\n$ curl -k -X POST \\\r\n  -H \"Content-Type: application/octet-stream\" \\\r\n  -H \"X-LXD-properties: hello=world\" \\\r\n  --key ~/.config/lxc/client.key \\\r\n  --cert ~/.config/lxc/client.crt \\\r\n  -T /tmp/busybox-1.21.1-amd64-lxc.tar.xz \\\r\n  https://127.0.0.1:8443/1.0/images\r\n\r\n$ lxc image list\r\n+-------+--------------+--------+----------------+--------+--------+------------------------------+\r\n| ALIAS | FINGERPRINT  | PUBLIC |  DESCRIPTION   |  ARCH  |  SIZE  |         UPLOAD DATE          |\r\n+-------+--------------+--------+----------------+--------+--------+------------------------------+\r\n|       | 097e75d6f741 | no     | Busybox x86_64 | x86_64 | 0.77MB | Mar 17, 2016 at 5:21pm (UTC) |\r\n+-------+--------------+--------+----------------+--------+--------+------------------------------+\r\n\r\n$ lxc image info 097\r\nFingerprint: 097e75d6f7419d3a5e204d8125582f2d7bdd4ee4c35bd324513321c645f0c415\r\nSize: 0.77MB\r\nArchitecture: x86_64\r\nPublic: no\r\nTimestamps:\r\n    Created: 2016/01/11 17:17 UTC\r\n    Uploaded: 2016/03/17 17:17 UTC\r\n    Expires: never\r\nProperties:\r\n    architecture: x86_64\r\n    description: Busybox x86_64\r\n    hello: world                     <--------- note the property\r\n    name: busybox-x86_64\r\n    os: Busybox\r\nAliases:\r\nAuto update: disabled\r\n```\r\n\r\nNot sure if this is a bug in LXD, or simply a doc bug.  The API docs contain the following, indicating that a `properties` hash can be passed:\r\n\r\n```\r\nIn the source image case, the following dict must be used:\r\n\r\n{\r\n    \"filename\": filename,                   # Used for export (optional)\r\n    \"public\": true,                         # Whether the image can be downloaded by untrusted users (defaults to false\r\n    \"properties\": {                         # Image properties (optional, applied on top of source properties)\r\n        \"os\": \"Ubuntu\"\r\n    },\r\n    \"source\": {\r\n        \"type\": \"image\",\r\n        \"mode\": \"pull\",                     # Only pull is supported for now\r\n        \"server\": \"https://10.0.2.3:8443\",  # Remote server (pull mode only)\r\n        \"protocol\": \"lxd\",                  # Protocol (one of lxd or simplestreams, defaults to lxd)\r\n        \"secret\": \"my-secret-string\",       # Secret (pull mode only, private images only)\r\n        \"certificate\": \"PEM certificate\",   # Optional PEM certificate. If not mentioned, system CA is used.\r\n        \"fingerprint\": \"SHA256\",            # Fingerprint of the image (must be set if alias isn't)\r\n        \"alias\": \"ubuntu/devel\",            # Name of the alias (must be set if fingerprint isn't)\r\n    }\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/lxc/lxd/issues/comments/198034536","html_url":"https://github.com/lxc/lxd/issues/1772#issuecomment-198034536","issue_url":"https://api.github.com/repos/lxc/lxd/issues/1772","id":198034536,"user":{"login":"stgraber","id":2230599,"avatar_url":"https://avatars.githubusercontent.com/u/2230599?v=3","gravatar_id":"","url":"https://api.github.com/users/stgraber","html_url":"https://github.com/stgraber","followers_url":"https://api.github.com/users/stgraber/followers","following_url":"https://api.github.com/users/stgraber/following{/other_user}","gists_url":"https://api.github.com/users/stgraber/gists{/gist_id}","starred_url":"https://api.github.com/users/stgraber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stgraber/subscriptions","organizations_url":"https://api.github.com/users/stgraber/orgs","repos_url":"https://api.github.com/users/stgraber/repos","events_url":"https://api.github.com/users/stgraber/events{/privacy}","received_events_url":"https://api.github.com/users/stgraber/received_events","type":"User","site_admin":false},"created_at":"2016-03-17T18:59:06Z","updated_at":"2016-03-17T18:59:06Z","body":"Oh, I found the problem, your request is incorrect.\r\n\r\nThe \"properties\" key isn't valid inside the \"source\" map, it's valid at the root of the request, so you instead want:\r\n\r\n```\r\ncurl -k -X POST   -H \"Content-Type: application/json\"   -d '{\"auto_update\":true,\"public\":false,\"source\":{\"certificate\":\"\",\"fingerprint\":\"07d1a93ca98d3480b4b763c4defb9d05b082b764b1abac7a4dc00f482d6faf09\",\"mode\":\"pull\",\"protocol\":\"\",\"server\":\"https://images.linuxcontainers.org:8443\",\"type\":\"image\"}, \"properties\":{\"a\":\"b\", \"c\": \"d\"}}'   --key ~/.config/lxc/client.key   --cert ~/.config/lxc/client.crt   https://127.0.0.1:8443/1.0/images\r\n```"}}