{"action":"created","comment":{"url":"https://api.github.com/repos/lxc/lxd/pulls/comments/25087719","id":25087719,"diff_hunk":"@@ -159,6 +292,123 @@ type containerStatePutReq struct {\n \tForce   bool   `json:\"force\"`\n }\n \n+type lxdContainer struct {\n+\tc *lxc.Container\n+\tid int\n+}\n+\n+func (c *lxdContainer) Start() error {\n+\treturn c.c.Start()\n+}\n+\n+func (c *lxdContainer) Reboot() error {\n+\treturn c.c.Reboot()\n+}\n+\n+func (c *lxdContainer) Freeze() error {\n+\treturn c.c.Freeze()\n+}\n+\n+func (c *lxdContainer) Shutdown(timeout time.Duration) error {\n+\treturn c.c.Shutdown(timeout)\n+}\n+\n+func (c *lxdContainer) Stop() error {\n+\treturn c.c.Stop()\n+}\n+\n+func (c *lxdContainer) Unfreeze() error {\n+\treturn c.Unfreeze()\n+}\n+\n+func newLxdContainer(name string, daemon *Daemon) (*lxdContainer, error) {\n+\td := &lxdContainer{}\n+\n+\tcertdbname := shared.VarPath(\"lxd.db\")\n+\tdb, err := sql.Open(\"sqlite3\", certdbname)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tdefer db.Close()\n+\trows, err := db.Query(\"select id, architecture from containers where name = ?\", name);\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tdefer rows.Close()\n+\td.id = -1\n+\tarch := 0\n+\tfor rows.Next() {\n+\t\tvar id int\n+\t\trows.Scan(&id, &arch)\n+\t\td.id = id\n+\t}\n+\tif d.id == -1 {\n+\t\treturn nil, fmt.Errorf(\"Unknown container\")\n+\t}\n+\n+\tc, err := lxc.NewContainer(name, daemon.lxcpath)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\terr = c.SetConfigItem(\"lxc.include\", \"/usr/share/lxc/config/ubuntu.common.conf\")\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tvar txtarch string\n+\tswitch (arch) {\n+\tcase 0:\n+\t\ttxtarch = \"x86_64\"\n+\tdefault:\n+\t\ttxtarch = \"x86_64\"\n+\t}\n+\terr = c.SetConfigItem(\"lxc.arch\", txtarch)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\t/* todo - get and translate containers_config entries\n+\t * for now we hardcode some sane entries */\n+\trootfsPath := shared.VarPath(\"lxc\", name, \"rootfs\")\n+\terr = c.SetConfigItem(\"lxc.rootfs\", rootfsPath)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\terr = c.SetConfigItem(\"lxc.devttydir\", \"\")\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tuidstr := fmt.Sprintf(\"u 0 %d %d\\n\", daemon.id_map.Uidmin, daemon.id_map.Uidrange)\n+\terr = c.SetConfigItem(\"lxc.id_map\", uidstr)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tgidstr := fmt.Sprintf(\"g 0 %d %d\\n\", daemon.id_map.Gidmin, daemon.id_map.Gidrange)\n+\terr = c.SetConfigItem(\"lxc.id_map\", gidstr)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\terr = c.SetConfigItem(\"lxc.loglevel\", \"0\")\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tlogfile := shared.VarPath(\"lxc\", name, \"log\")\n+\terr = c.SetConfigItem(\"lxc.logfile\", logfile)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\terr = c.SetConfigItem(\"lxc.utsname\", name)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\td.c = c\n+\tc.SaveConfigFile(\"/tmp/config1\")","path":"lxd/containers.go","position":407,"original_position":407,"commit_id":"869eb68043b9dd84bd5c6e979004b0d70afab4ba","original_commit_id":"869eb68043b9dd84bd5c6e979004b0d70afab4ba","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},"body":"That could be a bit of a problem when creating multiple containers in parallel :)\r\n\r\nIsn't there a mktemp equivalent in Go?","created_at":"2015-02-20T17:47:23Z","updated_at":"2015-02-20T17:47:23Z","html_url":"https://github.com/lxc/lxd/pull/214#discussion_r25087719","pull_request_url":"https://api.github.com/repos/lxc/lxd/pulls/214","_links":{"self":{"href":"https://api.github.com/repos/lxc/lxd/pulls/comments/25087719"},"html":{"href":"https://github.com/lxc/lxd/pull/214#discussion_r25087719"},"pull_request":{"href":"https://api.github.com/repos/lxc/lxd/pulls/214"}}},"pull_request":{"url":"https://api.github.com/repos/lxc/lxd/pulls/214","id":29672802,"html_url":"https://github.com/lxc/lxd/pull/214","diff_url":"https://github.com/lxc/lxd/pull/214.diff","patch_url":"https://github.com/lxc/lxd/pull/214.patch","issue_url":"https://api.github.com/repos/lxc/lxd/issues/214","number":214,"state":"open","locked":false,"title":"Start conversion to using db","user":{"login":"hallyn","id":1359441,"avatar_url":"https://avatars.githubusercontent.com/u/1359441?v=3","gravatar_id":"","url":"https://api.github.com/users/hallyn","html_url":"https://github.com/hallyn","followers_url":"https://api.github.com/users/hallyn/followers","following_url":"https://api.github.com/users/hallyn/following{/other_user}","gists_url":"https://api.github.com/users/hallyn/gists{/gist_id}","starred_url":"https://api.github.com/users/hallyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hallyn/subscriptions","organizations_url":"https://api.github.com/users/hallyn/orgs","repos_url":"https://api.github.com/users/hallyn/repos","events_url":"https://api.github.com/users/hallyn/events{/privacy}","received_events_url":"https://api.github.com/users/hallyn/received_events","type":"User","site_admin":false},"body":"This adds a createdb.sh script, which should eventually be done\r\nin go whenever we find lxd.db doesn't exist.\r\n\r\nCurrently we open the db connection when we need it.  It would\r\nseem more elegant to keep the connection for as long as lxd is\r\nrunning.  I'm not sure though whether that could lead to\r\ndb corruption in case of lxd crash.\r\n\r\nCurrently the db is used for\r\n  client certificates\r\n  container names\r\n  images\r\n\r\nThe container_config is not actually used yet.  Rather, we are\r\nhardcoding some usually-sane configs at newLxdContainer().\r\n\r\nTo use this, I did:\r\n\r\n1. create an image:\r\n\tcp ~/.cache/lxc/download/ubuntu/vivid/amd64/default/rootfs.tar.xz .\r\n\tcat > metadata.yaml << EOF\r\n{\r\n\t'architecture': \"x86_64\",\r\n\t'creation_date': 1424284563,\r\n\t'properties': {\r\n\t\t'os': \"Ubuntu\",\r\n\t\t'release': [\"trusty\", \"14.04\"],\r\n\t\t'description': \"Ubuntu 14.04 LTS Intel 64bit\"},\r\n\t\t'name': \"ubuntu-14.04-amd64-20150218\"\r\n\t}\r\n}\r\nEOF\r\n\ttar Jcf image.tar.xz metadata.yaml rootfs.tar.xz\r\n2. upload the image to lxd running on test1:\r\n\tlxc image import ./image.tar.xz test1:\r\n3. launch a container:\r\n\tlxc launch ececfb52e7edb55cbbd34d609dab545754c6c28bb660bcfd3edfc7d36ca30802 test1:c1\r\nThe image currently is only addressed using its sha256sum.  You can\r\neither call sa256sum over the image, or get the fingerprint from the\r\ndb or from lxd's debug output\r\n4. attach to the container,\r\n\tlxc exec test1:c1 -- /bin/bash\r\nStop is hanging (as apparently it was before - i've not looked into\r\nwhy) so poweroff from the shell.  Then\r\n5. destroy:\r\n\tlxc delete test1:c1\r\n\r\nSigned-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>","created_at":"2015-02-20T04:46:55Z","updated_at":"2015-02-20T17:47:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6c8f7fc6a152baed093c7539e58300a975ae9d11","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lxc/lxd/pulls/214/commits","review_comments_url":"https://api.github.com/repos/lxc/lxd/pulls/214/comments","review_comment_url":"https://api.github.com/repos/lxc/lxd/pulls/comments/{number}","comments_url":"https://api.github.com/repos/lxc/lxd/issues/214/comments","statuses_url":"https://api.github.com/repos/lxc/lxd/statuses/869eb68043b9dd84bd5c6e979004b0d70afab4ba","head":{"label":"hallyn:db.7","ref":"db.7","sha":"869eb68043b9dd84bd5c6e979004b0d70afab4ba","user":{"login":"hallyn","id":1359441,"avatar_url":"https://avatars.githubusercontent.com/u/1359441?v=3","gravatar_id":"","url":"https://api.github.com/users/hallyn","html_url":"https://github.com/hallyn","followers_url":"https://api.github.com/users/hallyn/followers","following_url":"https://api.github.com/users/hallyn/following{/other_user}","gists_url":"https://api.github.com/users/hallyn/gists{/gist_id}","starred_url":"https://api.github.com/users/hallyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hallyn/subscriptions","organizations_url":"https://api.github.com/users/hallyn/orgs","repos_url":"https://api.github.com/users/hallyn/repos","events_url":"https://api.github.com/users/hallyn/events{/privacy}","received_events_url":"https://api.github.com/users/hallyn/received_events","type":"User","site_admin":false},"repo":{"id":26297086,"name":"lxd","full_name":"hallyn/lxd","owner":{"login":"hallyn","id":1359441,"avatar_url":"https://avatars.githubusercontent.com/u/1359441?v=3","gravatar_id":"","url":"https://api.github.com/users/hallyn","html_url":"https://github.com/hallyn","followers_url":"https://api.github.com/users/hallyn/followers","following_url":"https://api.github.com/users/hallyn/following{/other_user}","gists_url":"https://api.github.com/users/hallyn/gists{/gist_id}","starred_url":"https://api.github.com/users/hallyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hallyn/subscriptions","organizations_url":"https://api.github.com/users/hallyn/orgs","repos_url":"https://api.github.com/users/hallyn/repos","events_url":"https://api.github.com/users/hallyn/events{/privacy}","received_events_url":"https://api.github.com/users/hallyn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hallyn/lxd","description":"lxd (pronounced lex-dee) is a REST API, command line tool and OpenStack plugin based on liblxc","fork":true,"url":"https://api.github.com/repos/hallyn/lxd","forks_url":"https://api.github.com/repos/hallyn/lxd/forks","keys_url":"https://api.github.com/repos/hallyn/lxd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hallyn/lxd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hallyn/lxd/teams","hooks_url":"https://api.github.com/repos/hallyn/lxd/hooks","issue_events_url":"https://api.github.com/repos/hallyn/lxd/issues/events{/number}","events_url":"https://api.github.com/repos/hallyn/lxd/events","assignees_url":"https://api.github.com/repos/hallyn/lxd/assignees{/user}","branches_url":"https://api.github.com/repos/hallyn/lxd/branches{/branch}","tags_url":"https://api.github.com/repos/hallyn/lxd/tags","blobs_url":"https://api.github.com/repos/hallyn/lxd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hallyn/lxd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hallyn/lxd/git/refs{/sha}","trees_url":"https://api.github.com/repos/hallyn/lxd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hallyn/lxd/statuses/{sha}","languages_url":"https://api.github.com/repos/hallyn/lxd/languages","stargazers_url":"https://api.github.com/repos/hallyn/lxd/stargazers","contributors_url":"https://api.github.com/repos/hallyn/lxd/contributors","subscribers_url":"https://api.github.com/repos/hallyn/lxd/subscribers","subscription_url":"https://api.github.com/repos/hallyn/lxd/subscription","commits_url":"https://api.github.com/repos/hallyn/lxd/commits{/sha}","git_commits_url":"https://api.github.com/repos/hallyn/lxd/git/commits{/sha}","comments_url":"https://api.github.com/repos/hallyn/lxd/comments{/number}","issue_comment_url":"https://api.github.com/repos/hallyn/lxd/issues/comments/{number}","contents_url":"https://api.github.com/repos/hallyn/lxd/contents/{+path}","compare_url":"https://api.github.com/repos/hallyn/lxd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hallyn/lxd/merges","archive_url":"https://api.github.com/repos/hallyn/lxd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hallyn/lxd/downloads","issues_url":"https://api.github.com/repos/hallyn/lxd/issues{/number}","pulls_url":"https://api.github.com/repos/hallyn/lxd/pulls{/number}","milestones_url":"https://api.github.com/repos/hallyn/lxd/milestones{/number}","notifications_url":"https://api.github.com/repos/hallyn/lxd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hallyn/lxd/labels{/name}","releases_url":"https://api.github.com/repos/hallyn/lxd/releases{/id}","created_at":"2014-11-07T00:48:12Z","updated_at":"2014-11-06T23:52:05Z","pushed_at":"2015-02-20T17:30:28Z","git_url":"git://github.com/hallyn/lxd.git","ssh_url":"git@github.com:hallyn/lxd.git","clone_url":"https://github.com/hallyn/lxd.git","svn_url":"https://github.com/hallyn/lxd","homepage":"https://linuxcontainers.org","size":818,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lxc:master","ref":"master","sha":"a81db68ac25ea6bd474f634e2f632940dde7cd5a","user":{"login":"lxc","id":2301756,"avatar_url":"https://avatars.githubusercontent.com/u/2301756?v=3","gravatar_id":"","url":"https://api.github.com/users/lxc","html_url":"https://github.com/lxc","followers_url":"https://api.github.com/users/lxc/followers","following_url":"https://api.github.com/users/lxc/following{/other_user}","gists_url":"https://api.github.com/users/lxc/gists{/gist_id}","starred_url":"https://api.github.com/users/lxc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lxc/subscriptions","organizations_url":"https://api.github.com/users/lxc/orgs","repos_url":"https://api.github.com/users/lxc/repos","events_url":"https://api.github.com/users/lxc/events{/privacy}","received_events_url":"https://api.github.com/users/lxc/received_events","type":"Organization","site_admin":false},"repo":{"id":26192117,"name":"lxd","full_name":"lxc/lxd","owner":{"login":"lxc","id":2301756,"avatar_url":"https://avatars.githubusercontent.com/u/2301756?v=3","gravatar_id":"","url":"https://api.github.com/users/lxc","html_url":"https://github.com/lxc","followers_url":"https://api.github.com/users/lxc/followers","following_url":"https://api.github.com/users/lxc/following{/other_user}","gists_url":"https://api.github.com/users/lxc/gists{/gist_id}","starred_url":"https://api.github.com/users/lxc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lxc/subscriptions","organizations_url":"https://api.github.com/users/lxc/orgs","repos_url":"https://api.github.com/users/lxc/repos","events_url":"https://api.github.com/users/lxc/events{/privacy}","received_events_url":"https://api.github.com/users/lxc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lxc/lxd","description":"REST API, command line tool and OpenStack plugin based on liblxc","fork":false,"url":"https://api.github.com/repos/lxc/lxd","forks_url":"https://api.github.com/repos/lxc/lxd/forks","keys_url":"https://api.github.com/repos/lxc/lxd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lxc/lxd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lxc/lxd/teams","hooks_url":"https://api.github.com/repos/lxc/lxd/hooks","issue_events_url":"https://api.github.com/repos/lxc/lxd/issues/events{/number}","events_url":"https://api.github.com/repos/lxc/lxd/events","assignees_url":"https://api.github.com/repos/lxc/lxd/assignees{/user}","branches_url":"https://api.github.com/repos/lxc/lxd/branches{/branch}","tags_url":"https://api.github.com/repos/lxc/lxd/tags","blobs_url":"https://api.github.com/repos/lxc/lxd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lxc/lxd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lxc/lxd/git/refs{/sha}","trees_url":"https://api.github.com/repos/lxc/lxd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lxc/lxd/statuses/{sha}","languages_url":"https://api.github.com/repos/lxc/lxd/languages","stargazers_url":"https://api.github.com/repos/lxc/lxd/stargazers","contributors_url":"https://api.github.com/repos/lxc/lxd/contributors","subscribers_url":"https://api.github.com/repos/lxc/lxd/subscribers","subscription_url":"https://api.github.com/repos/lxc/lxd/subscription","commits_url":"https://api.github.com/repos/lxc/lxd/commits{/sha}","git_commits_url":"https://api.github.com/repos/lxc/lxd/git/commits{/sha}","comments_url":"https://api.github.com/repos/lxc/lxd/comments{/number}","issue_comment_url":"https://api.github.com/repos/lxc/lxd/issues/comments/{number}","contents_url":"https://api.github.com/repos/lxc/lxd/contents/{+path}","compare_url":"https://api.github.com/repos/lxc/lxd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lxc/lxd/merges","archive_url":"https://api.github.com/repos/lxc/lxd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lxc/lxd/downloads","issues_url":"https://api.github.com/repos/lxc/lxd/issues{/number}","pulls_url":"https://api.github.com/repos/lxc/lxd/pulls{/number}","milestones_url":"https://api.github.com/repos/lxc/lxd/milestones{/number}","notifications_url":"https://api.github.com/repos/lxc/lxd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lxc/lxd/labels{/name}","releases_url":"https://api.github.com/repos/lxc/lxd/releases{/id}","created_at":"2014-11-04T22:40:52Z","updated_at":"2015-02-20T10:27:32Z","pushed_at":"2015-02-19T19:46:03Z","git_url":"git://github.com/lxc/lxd.git","ssh_url":"git@github.com:lxc/lxd.git","clone_url":"https://github.com/lxc/lxd.git","svn_url":"https://github.com/lxc/lxd","homepage":"https://linuxcontainers.org","size":2189,"stargazers_count":245,"watchers_count":245,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":23,"forks":28,"open_issues":23,"watchers":245,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lxc/lxd/pulls/214"},"html":{"href":"https://github.com/lxc/lxd/pull/214"},"issue":{"href":"https://api.github.com/repos/lxc/lxd/issues/214"},"comments":{"href":"https://api.github.com/repos/lxc/lxd/issues/214/comments"},"review_comments":{"href":"https://api.github.com/repos/lxc/lxd/pulls/214/comments"},"review_comment":{"href":"https://api.github.com/repos/lxc/lxd/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/lxc/lxd/pulls/214/commits"},"statuses":{"href":"https://api.github.com/repos/lxc/lxd/statuses/869eb68043b9dd84bd5c6e979004b0d70afab4ba"}}}}