{"action":"created","comment":{"url":"https://api.github.com/repos/fedora-modularity/conu/pulls/comments/175760648","pull_request_review_id":105325649,"id":175760648,"diff_hunk":"@@ -0,0 +1,261 @@\n+# -*- coding: utf-8 -*-\n+#\n+# This program is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+\n+\"\"\"\n+Implementation of a docker container\n+\"\"\"\n+from __future__ import print_function, unicode_literals\n+\n+import functools\n+import logging\n+import subprocess\n+import time\n+import glob\n+\n+\n+from conu.apidefs.container import Container\n+from conu.apidefs.filesystem import Filesystem\n+from conu.exceptions import ConuException\n+from conu.utils import check_port, run_cmd, random_str, output_decode\n+from conu.utils.probes import Probe\n+import constants\n+\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class NspawnContainer(Container):\n+    systemd_wait_support = None\n+\n+    def __init__(self, image, container_id, name=None, popen_instance=None):\n+        super(NspawnContainer, self).__init__(image, container_id, name)\n+        if not name:\n+            self.name = self._id\n+        self.popen_instance = popen_instance\n+\n+    def __repr__(self):\n+        return \"NspawnContainer(image=%s, id=%s)\" % (self.image, self.get_id())\n+\n+    def __str__(self):\n+        return self.get_id()\n+\n+    def get_id(self):\n+        return self._id\n+\n+    def inspect(self, refresh=True):\n+        \"\"\"\n+        return cached metadata by default (a convenience method)\n+\n+        :param refresh: bool, returns up to date metadata if set to True\n+        :return: dict\n+        \"\"\"\n+        return self.get_metadata(refresh=refresh)\n+\n+    def get_metadata(self, refresh=True):\n+        \"\"\"\n+        return cached metadata by default\n+\n+        :param refresh: bool, returns up to date metadata if set to True\n+        :return: dict\n+        \"\"\"\n+        if refresh or not self._metadata:\n+            ident = self._id or self.name\n+            if not ident:\n+                raise ConuException(\"This container does not have a valid identifier.\")\n+            self._metadata = output_decode(run_cmd([\"machinectl\", \"show\",  ident], return_output=True))\n+        return self._metadata\n+\n+    def is_running(self):\n+        return \"running\" == self.get_metadata(refresh=True)[\"State\"]\n+\n+    def copy_to(self, src, dest):\n+        \"\"\"\n+        copy a file or a directory from host system to a container\n+\n+        :param src: str, path to a file or a directory on host system\n+        :param dest: str, path to a file or a directory within container\n+        :return: None\n+        \"\"\"\n+        # using `docker cp` b/c put_archive is too complicated\n+        logger.debug(\"copying %s from host to container at %s\", src, dest)\n+        cmd = [\"machinectl\", \"copy-to\",self.get_id(), src, dest]\n+        run_cmd(cmd)\n+\n+    def copy_from(self, src, dest):\n+        \"\"\"\n+        copy a file or a directory from container or image to host system.\n+\n+        :param src: str, path to a file or a directory within container or image\n+        :param dest: str, path to a file or a directory on host system\n+        :return: None\n+        \"\"\"\n+        # using `docker cp` b/c get_archive is too complicated\n+        logger.debug(\"copying %s from host to container at %s\", src, dest)\n+        cmd = [\"machinectl\", \"copy-from\", self.get_id(), src, dest]\n+        run_cmd(cmd)\n+\n+\n+    def stop(self):\n+        \"\"\"\n+        stop this container\n+\n+        :return: None\n+        \"\"\"\n+        self.kill()\n+\n+    def kill(self, signal=None):\n+        try:\n+            run_cmd([\"machinectl\", \"poweroff\", self.get_id()])\n+        except BaseException as poweroffex:\n+            logger.debug(\"Unable to stop machine via poweroff, terminating : %s\" % poweroffex)\n+            try:\n+                run_cmd([\"machinectl\", \"terminate\", self.get_id()])\n+                self.image._is_killed(self.get_id())\n+            except BaseException as poweroffexterm:\n+                logger.debug(\"Unable to stop machine via terminate, STRANGE: %s\" % poweroffexterm)\n+                time.sleep(constants.DEFAULT_RETRYTIMEOUT)","path":"conu/backend/nspawn/container.py","position":132,"original_position":129,"commit_id":"a203f11da36b0ad641fcb9c5d600f91f0a312dcf","original_commit_id":"c377160d720b48144a567c26ef128fee419bb3dd","user":{"login":"dhodovsk","id":31201372,"avatar_url":"https://avatars2.githubusercontent.com/u/31201372?v=4","gravatar_id":"","url":"https://api.github.com/users/dhodovsk","html_url":"https://github.com/dhodovsk","followers_url":"https://api.github.com/users/dhodovsk/followers","following_url":"https://api.github.com/users/dhodovsk/following{/other_user}","gists_url":"https://api.github.com/users/dhodovsk/gists{/gist_id}","starred_url":"https://api.github.com/users/dhodovsk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhodovsk/subscriptions","organizations_url":"https://api.github.com/users/dhodovsk/orgs","repos_url":"https://api.github.com/users/dhodovsk/repos","events_url":"https://api.github.com/users/dhodovsk/events{/privacy}","received_events_url":"https://api.github.com/users/dhodovsk/received_events","type":"User","site_admin":false},"body":"Please provide an explanation of this sleep. Could its absence affect methods called after?","created_at":"2018-03-20T13:20:24Z","updated_at":"2018-03-20T14:04:56Z","html_url":"https://github.com/fedora-modularity/conu/pull/169#discussion_r175760648","pull_request_url":"https://api.github.com/repos/fedora-modularity/conu/pulls/169","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/fedora-modularity/conu/pulls/comments/175760648"},"html":{"href":"https://github.com/fedora-modularity/conu/pull/169#discussion_r175760648"},"pull_request":{"href":"https://api.github.com/repos/fedora-modularity/conu/pulls/169"}}},"pull_request":{"url":"https://api.github.com/repos/fedora-modularity/conu/pulls/169","id":175196219,"html_url":"https://github.com/fedora-modularity/conu/pull/169","diff_url":"https://github.com/fedora-modularity/conu/pull/169.diff","patch_url":"https://github.com/fedora-modularity/conu/pull/169.patch","issue_url":"https://api.github.com/repos/fedora-modularity/conu/issues/169","number":169,"state":"open","locked":false,"title":"WIP: systemd-nspawn container support","user":{"login":"jscotka","id":8735467,"avatar_url":"https://avatars0.githubusercontent.com/u/8735467?v=4","gravatar_id":"","url":"https://api.github.com/users/jscotka","html_url":"https://github.com/jscotka","followers_url":"https://api.github.com/users/jscotka/followers","following_url":"https://api.github.com/users/jscotka/following{/other_user}","gists_url":"https://api.github.com/users/jscotka/gists{/gist_id}","starred_url":"https://api.github.com/users/jscotka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscotka/subscriptions","organizations_url":"https://api.github.com/users/jscotka/orgs","repos_url":"https://api.github.com/users/jscotka/repos","events_url":"https://api.github.com/users/jscotka/events{/privacy}","received_events_url":"https://api.github.com/users/jscotka/received_events","type":"User","site_admin":false},"body":"It is more less ready","created_at":"2018-03-15T09:51:12Z","updated_at":"2018-03-20T14:04:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b30de518555733f29808bd71827b17640bcccb2d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/fedora-modularity/conu/pulls/169/commits","review_comments_url":"https://api.github.com/repos/fedora-modularity/conu/pulls/169/comments","review_comment_url":"https://api.github.com/repos/fedora-modularity/conu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fedora-modularity/conu/issues/169/comments","statuses_url":"https://api.github.com/repos/fedora-modularity/conu/statuses/a203f11da36b0ad641fcb9c5d600f91f0a312dcf","head":{"label":"jscotka:nspawn","ref":"nspawn","sha":"a203f11da36b0ad641fcb9c5d600f91f0a312dcf","user":{"login":"jscotka","id":8735467,"avatar_url":"https://avatars0.githubusercontent.com/u/8735467?v=4","gravatar_id":"","url":"https://api.github.com/users/jscotka","html_url":"https://github.com/jscotka","followers_url":"https://api.github.com/users/jscotka/followers","following_url":"https://api.github.com/users/jscotka/following{/other_user}","gists_url":"https://api.github.com/users/jscotka/gists{/gist_id}","starred_url":"https://api.github.com/users/jscotka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscotka/subscriptions","organizations_url":"https://api.github.com/users/jscotka/orgs","repos_url":"https://api.github.com/users/jscotka/repos","events_url":"https://api.github.com/users/jscotka/events{/privacy}","received_events_url":"https://api.github.com/users/jscotka/received_events","type":"User","site_admin":false},"repo":{"id":103252646,"name":"conu","full_name":"jscotka/conu","owner":{"login":"jscotka","id":8735467,"avatar_url":"https://avatars0.githubusercontent.com/u/8735467?v=4","gravatar_id":"","url":"https://api.github.com/users/jscotka","html_url":"https://github.com/jscotka","followers_url":"https://api.github.com/users/jscotka/followers","following_url":"https://api.github.com/users/jscotka/following{/other_user}","gists_url":"https://api.github.com/users/jscotka/gists{/gist_id}","starred_url":"https://api.github.com/users/jscotka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscotka/subscriptions","organizations_url":"https://api.github.com/users/jscotka/orgs","repos_url":"https://api.github.com/users/jscotka/repos","events_url":"https://api.github.com/users/jscotka/events{/privacy}","received_events_url":"https://api.github.com/users/jscotka/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jscotka/conu","description":"CONtainers Util functions to help you with testing of your containers.","fork":true,"url":"https://api.github.com/repos/jscotka/conu","forks_url":"https://api.github.com/repos/jscotka/conu/forks","keys_url":"https://api.github.com/repos/jscotka/conu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jscotka/conu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jscotka/conu/teams","hooks_url":"https://api.github.com/repos/jscotka/conu/hooks","issue_events_url":"https://api.github.com/repos/jscotka/conu/issues/events{/number}","events_url":"https://api.github.com/repos/jscotka/conu/events","assignees_url":"https://api.github.com/repos/jscotka/conu/assignees{/user}","branches_url":"https://api.github.com/repos/jscotka/conu/branches{/branch}","tags_url":"https://api.github.com/repos/jscotka/conu/tags","blobs_url":"https://api.github.com/repos/jscotka/conu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jscotka/conu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jscotka/conu/git/refs{/sha}","trees_url":"https://api.github.com/repos/jscotka/conu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jscotka/conu/statuses/{sha}","languages_url":"https://api.github.com/repos/jscotka/conu/languages","stargazers_url":"https://api.github.com/repos/jscotka/conu/stargazers","contributors_url":"https://api.github.com/repos/jscotka/conu/contributors","subscribers_url":"https://api.github.com/repos/jscotka/conu/subscribers","subscription_url":"https://api.github.com/repos/jscotka/conu/subscription","commits_url":"https://api.github.com/repos/jscotka/conu/commits{/sha}","git_commits_url":"https://api.github.com/repos/jscotka/conu/git/commits{/sha}","comments_url":"https://api.github.com/repos/jscotka/conu/comments{/number}","issue_comment_url":"https://api.github.com/repos/jscotka/conu/issues/comments{/number}","contents_url":"https://api.github.com/repos/jscotka/conu/contents/{+path}","compare_url":"https://api.github.com/repos/jscotka/conu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jscotka/conu/merges","archive_url":"https://api.github.com/repos/jscotka/conu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jscotka/conu/downloads","issues_url":"https://api.github.com/repos/jscotka/conu/issues{/number}","pulls_url":"https://api.github.com/repos/jscotka/conu/pulls{/number}","milestones_url":"https://api.github.com/repos/jscotka/conu/milestones{/number}","notifications_url":"https://api.github.com/repos/jscotka/conu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jscotka/conu/labels{/name}","releases_url":"https://api.github.com/repos/jscotka/conu/releases{/id}","deployments_url":"https://api.github.com/repos/jscotka/conu/deployments","created_at":"2017-09-12T09:47:09Z","updated_at":"2017-09-12T08:48:56Z","pushed_at":"2018-03-20T14:04:45Z","git_url":"git://github.com/jscotka/conu.git","ssh_url":"git@github.com:jscotka/conu.git","clone_url":"https://github.com/jscotka/conu.git","svn_url":"https://github.com/jscotka/conu","homepage":"","size":2026,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fedora-modularity:master","ref":"master","sha":"bba2551bd494e5275716184e84d2b96b7c5fab95","user":{"login":"fedora-modularity","id":20321118,"avatar_url":"https://avatars0.githubusercontent.com/u/20321118?v=4","gravatar_id":"","url":"https://api.github.com/users/fedora-modularity","html_url":"https://github.com/fedora-modularity","followers_url":"https://api.github.com/users/fedora-modularity/followers","following_url":"https://api.github.com/users/fedora-modularity/following{/other_user}","gists_url":"https://api.github.com/users/fedora-modularity/gists{/gist_id}","starred_url":"https://api.github.com/users/fedora-modularity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fedora-modularity/subscriptions","organizations_url":"https://api.github.com/users/fedora-modularity/orgs","repos_url":"https://api.github.com/users/fedora-modularity/repos","events_url":"https://api.github.com/users/fedora-modularity/events{/privacy}","received_events_url":"https://api.github.com/users/fedora-modularity/received_events","type":"Organization","site_admin":false},"repo":{"id":103242244,"name":"conu","full_name":"fedora-modularity/conu","owner":{"login":"fedora-modularity","id":20321118,"avatar_url":"https://avatars0.githubusercontent.com/u/20321118?v=4","gravatar_id":"","url":"https://api.github.com/users/fedora-modularity","html_url":"https://github.com/fedora-modularity","followers_url":"https://api.github.com/users/fedora-modularity/followers","following_url":"https://api.github.com/users/fedora-modularity/following{/other_user}","gists_url":"https://api.github.com/users/fedora-modularity/gists{/gist_id}","starred_url":"https://api.github.com/users/fedora-modularity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fedora-modularity/subscriptions","organizations_url":"https://api.github.com/users/fedora-modularity/orgs","repos_url":"https://api.github.com/users/fedora-modularity/repos","events_url":"https://api.github.com/users/fedora-modularity/events{/privacy}","received_events_url":"https://api.github.com/users/fedora-modularity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fedora-modularity/conu","description":"conu - python API for your containers","fork":false,"url":"https://api.github.com/repos/fedora-modularity/conu","forks_url":"https://api.github.com/repos/fedora-modularity/conu/forks","keys_url":"https://api.github.com/repos/fedora-modularity/conu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fedora-modularity/conu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fedora-modularity/conu/teams","hooks_url":"https://api.github.com/repos/fedora-modularity/conu/hooks","issue_events_url":"https://api.github.com/repos/fedora-modularity/conu/issues/events{/number}","events_url":"https://api.github.com/repos/fedora-modularity/conu/events","assignees_url":"https://api.github.com/repos/fedora-modularity/conu/assignees{/user}","branches_url":"https://api.github.com/repos/fedora-modularity/conu/branches{/branch}","tags_url":"https://api.github.com/repos/fedora-modularity/conu/tags","blobs_url":"https://api.github.com/repos/fedora-modularity/conu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fedora-modularity/conu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fedora-modularity/conu/git/refs{/sha}","trees_url":"https://api.github.com/repos/fedora-modularity/conu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fedora-modularity/conu/statuses/{sha}","languages_url":"https://api.github.com/repos/fedora-modularity/conu/languages","stargazers_url":"https://api.github.com/repos/fedora-modularity/conu/stargazers","contributors_url":"https://api.github.com/repos/fedora-modularity/conu/contributors","subscribers_url":"https://api.github.com/repos/fedora-modularity/conu/subscribers","subscription_url":"https://api.github.com/repos/fedora-modularity/conu/subscription","commits_url":"https://api.github.com/repos/fedora-modularity/conu/commits{/sha}","git_commits_url":"https://api.github.com/repos/fedora-modularity/conu/git/commits{/sha}","comments_url":"https://api.github.com/repos/fedora-modularity/conu/comments{/number}","issue_comment_url":"https://api.github.com/repos/fedora-modularity/conu/issues/comments{/number}","contents_url":"https://api.github.com/repos/fedora-modularity/conu/contents/{+path}","compare_url":"https://api.github.com/repos/fedora-modularity/conu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fedora-modularity/conu/merges","archive_url":"https://api.github.com/repos/fedora-modularity/conu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fedora-modularity/conu/downloads","issues_url":"https://api.github.com/repos/fedora-modularity/conu/issues{/number}","pulls_url":"https://api.github.com/repos/fedora-modularity/conu/pulls{/number}","milestones_url":"https://api.github.com/repos/fedora-modularity/conu/milestones{/number}","notifications_url":"https://api.github.com/repos/fedora-modularity/conu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fedora-modularity/conu/labels{/name}","releases_url":"https://api.github.com/repos/fedora-modularity/conu/releases{/id}","deployments_url":"https://api.github.com/repos/fedora-modularity/conu/deployments","created_at":"2017-09-12T08:14:37Z","updated_at":"2018-03-19T19:13:32Z","pushed_at":"2018-03-20T14:04:46Z","git_url":"git://github.com/fedora-modularity/conu.git","ssh_url":"git@github.com:fedora-modularity/conu.git","clone_url":"https://github.com/fedora-modularity/conu.git","svn_url":"https://github.com/fedora-modularity/conu","homepage":"http://conu.readthedocs.io/en/latest/","size":2009,"stargazers_count":53,"watchers_count":53,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"archived":false,"open_issues_count":27,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":15,"open_issues":27,"watchers":53,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fedora-modularity/conu/pulls/169"},"html":{"href":"https://github.com/fedora-modularity/conu/pull/169"},"issue":{"href":"https://api.github.com/repos/fedora-modularity/conu/issues/169"},"comments":{"href":"https://api.github.com/repos/fedora-modularity/conu/issues/169/comments"},"review_comments":{"href":"https://api.github.com/repos/fedora-modularity/conu/pulls/169/comments"},"review_comment":{"href":"https://api.github.com/repos/fedora-modularity/conu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fedora-modularity/conu/pulls/169/commits"},"statuses":{"href":"https://api.github.com/repos/fedora-modularity/conu/statuses/a203f11da36b0ad641fcb9c5d600f91f0a312dcf"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dhodovsk"}}