{"action":"created","comment":{"url":"https://api.github.com/repos/xiar/infrasim-compute/pulls/comments/89332505","pull_request_review_id":9878093,"id":89332505,"diff_hunk":"@@ -0,0 +1,191 @@\n+import sys\n+import time\n+import argparse\n+import config\n+import model\n+from yaml_loader import YAMLLoader\n+from init import infrasim_init\n+from version import version\n+import helper\n+\n+\n+def args(*args, **kwargs):\n+    def _decorator(func):\n+        func.__dict__.setdefault('args', []).insert(0, (args, kwargs))\n+        return func\n+    return _decorator\n+\n+\n+class NodeCommands(object):\n+    def _get_node(self, config_file=None):\n+        node_config = config_file or config.infrasim_initial_config\n+        with open(node_config, \"r\") as f:\n+            node_info = YAMLLoader(f).get_data()\n+\n+        return model.CNode(node_info)\n+\n+    def _node_preinit(self, node):\n+        node.init()\n+        node.precheck()\n+\n+    @args(\"-c\", \"--config-file\", action=\"store\", dest=\"config_file\", help=\"Node configuration file\")\n+    def start(self, config_file=None):\n+        node = self._get_node(config_file)\n+        self._node_preinit(node)\n+        node.start()\n+\n+        # get IP address\n+        print \"Infrasim service started.\\n\" \\\n+            \"Node {} graphic interface accessible via: \\n\" \\\n+            \"VNC port: 5901 \\n\" \\\n+            \"Either host IP: {} \\n\" \\\n+            \"depending on host in which network VNC viewer is running\". \\\n+            format(node.get_node_name(), helper.ip4_addresses())\n+\n+    @args(\"-c\", \"--config-file\", action=\"store\", dest=\"config_file\", help=\"Node configuration file\")\n+    def stop(self, config_file=None):\n+        node = self._get_node(config_file)\n+        self._node_preinit(node)\n+        node.stop()\n+\n+    @args(\"-c\", \"--config-file\", action=\"store\", dest=\"config_file\", help=\"Node configuration file\")\n+    def restart(self, config_file=None):\n+        self.stop()\n+        time.sleep(0.5)\n+        self.start()\n+\n+    @args(\"-c\", \"--config-file\", action=\"store\", dest=\"config_file\", help=\"Node configuration file\")\n+    def status(self, config_file=None):\n+        node = self._get_node(config_file)\n+        self._node_preinit(node)\n+        node.status()\n+\n+    @args(\"-c\", \"--config-file\", action=\"store\", dest=\"config_file\", help=\"Node configuration file\")\n+    def destroy(self, config_file=None):\n+        node = self._get_node(config_file)\n+        self._node_preinit(node)\n+        node.stop()\n+        node.terminate_workspace()\n+\n+    @args(\"-t\", \"--type\", action=\"store_true\", dest=\"type\", help=\"Query node info\")\n+    def info(self, type=True):\n+        pass\n+\n+\n+class ChassisCommands(object):\n+    @args(\"-n\", \"--node-name\", action=\"store\", dest=\"node_name\", help=\"Node name\")\n+    def start(self, node_name=None):\n+        print node_name\n+\n+    @args(\"-n\", \"--node-name\", action=\"store\", dest=\"node_name\", help=\"Node name\")\n+    def stop(self, node_name=None):\n+        print node_name\n+\n+    @args(\"-n\", \"--node-name\", action=\"store\", dest=\"node_name\", help=\"Node name\")\n+    def restart(self, node_name=None):\n+        print node_name\n+\n+    @args(\"-n\", \"--node-name\", action=\"store\", dest=\"node_name\", help=\"Node name\")\n+    def destroy(self, node_name=None):\n+        print node_name\n+\n+\n+def methods_of(obj):\n+    result = []\n+    for i in dir(obj):\n+        if callable(getattr(obj, i)) and not i.startswith('_'):\n+            result.append((i, getattr(obj, i)))\n+    return result\n+\n+\n+def get_arg_string(args):\n+    args = args.strip('-')\n+\n+    if args:\n+        args = args.replace('-', '_')\n+\n+    return args\n+\n+\n+def get_func_args(func, matchargs):\n+    fn_args = []\n+    for args, kwargs in getattr(func, 'args', []):\n+        # The for loop is for supporting short and long options\n+        for arg in args:\n+            try:\n+                arg = kwargs.get('dest') or get_arg_string(args[0])\n+                parm = getattr(matchargs, arg)\n+            except AttributeError:\n+                continue\n+\n+            fn_args.append(parm)\n+\n+            # If we already got one params for fn, then exit loop.\n+            if len(fn_args) > 0:\n+                break\n+\n+    return fn_args\n+\n+\n+CATEGORIES = {\n+    'node': NodeCommands,\n+    'chassis': ChassisCommands\n+}\n+\n+\n+def add_command_parsers(subparser):\n+    for category in CATEGORIES:\n+        command_object = CATEGORIES[category]()\n+\n+        parser = subparser.add_parser(category)\n+        parser.set_defaults(command_object=command_object)\n+\n+        category_subparsers = parser.add_subparsers(dest=\"action\")\n+\n+        for (action, action_fn) in methods_of(command_object):\n+            parser = category_subparsers.add_parser(action)\n+\n+            action_kwargs = []\n+            for args, kwargs in getattr(action_fn, 'args', []):\n+                parser.add_argument(*args, **kwargs)\n+\n+            parser.set_defaults(action_fn=action_fn)\n+            parser.set_defaults(action_kwargs=action_kwargs)\n+\n+\n+\n+\n+def command_handler():\n+    parser = argparse.ArgumentParser()\n+\n+    subparsers = parser.add_subparsers(title=\"InfraSIM Commands:\")\n+    add_command_parsers(subparsers)\n+\n+    # for init command\n+    init_parser = subparsers.add_parser(\"init\", help=\"init infrasim environment\")\n+    init_parser.set_defaults(init=\"init\")\n+    init_parser.add_argument(\"-s\", \"--skip-installation\", action=\"store_true\",\n+                             help=\"Ignore qemu/openipmi package installation\")\n+    init_parser.add_argument(\"-i\", \"--infrasim-home\", action=\"store\",\n+                             help=\"Target infrasim home foler, default $HOME/.infrasim\")\n+    exclusive_group = init_parser.add_mutually_exclusive_group()\n+    exclusive_group.add_argument(\"-c\", \"--config-file\", action=\"store\", help=\"Node configuration file\")\n+    exclusive_group.add_argument(\"-t\", \"--type\", action=\"store\", default=\"quanta_d51\", help=\"Node type\")\n+\n+    # version command\n+    version_parser = subparsers.add_parser(\"version\", help=\"check version of infrasim and dependencies\")\n+    version_parser.set_defaults(version=\"version\")\n+\n+    args = parser.parse_args(sys.argv[1:])\n+    if hasattr(args, \"init\"):\n+        # Do init\n+        infrasim_init(args.type, args.skip_installation, args.infrasim_home, args.config_file)","path":"infrasim/cli.py","position":182,"original_position":182,"commit_id":"185dfdb92f2c552f9ce2ada9d5ccb27f3acbd411","original_commit_id":"185dfdb92f2c552f9ce2ada9d5ccb27f3acbd411","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"line too long (94 > 79 characters)","created_at":"2016-11-23T15:00:23Z","updated_at":"2016-11-23T15:00:23Z","html_url":"https://github.com/xiar/infrasim-compute/pull/1#discussion_r89332505","pull_request_url":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/xiar/infrasim-compute/pulls/comments/89332505"},"html":{"href":"https://github.com/xiar/infrasim-compute/pull/1#discussion_r89332505"},"pull_request":{"href":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1","id":95016445,"html_url":"https://github.com/xiar/infrasim-compute/pull/1","diff_url":"https://github.com/xiar/infrasim-compute/pull/1.diff","patch_url":"https://github.com/xiar/infrasim-compute/pull/1.patch","issue_url":"https://api.github.com/repos/xiar/infrasim-compute/issues/1","number":1,"state":"open","locked":false,"title":"Enhancement/redesign infrasim commandline interface","user":{"login":"xiar","id":14065584,"avatar_url":"https://avatars.githubusercontent.com/u/14065584?v=3","gravatar_id":"","url":"https://api.github.com/users/xiar","html_url":"https://github.com/xiar","followers_url":"https://api.github.com/users/xiar/followers","following_url":"https://api.github.com/users/xiar/following{/other_user}","gists_url":"https://api.github.com/users/xiar/gists{/gist_id}","starred_url":"https://api.github.com/users/xiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiar/subscriptions","organizations_url":"https://api.github.com/users/xiar/orgs","repos_url":"https://api.github.com/users/xiar/repos","events_url":"https://api.github.com/users/xiar/events{/privacy}","received_events_url":"https://api.github.com/users/xiar/received_events","type":"User","site_admin":false},"body":"just test flake8","created_at":"2016-11-23T14:46:10Z","updated_at":"2016-11-23T15:00:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b100596c37e5e9e9d25e991b9ad35c8934316dd4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1/commits","review_comments_url":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1/comments","review_comment_url":"https://api.github.com/repos/xiar/infrasim-compute/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xiar/infrasim-compute/issues/1/comments","statuses_url":"https://api.github.com/repos/xiar/infrasim-compute/statuses/185dfdb92f2c552f9ce2ada9d5ccb27f3acbd411","head":{"label":"xiar:enhancement/redesign-infrasim-commandline-interface","ref":"enhancement/redesign-infrasim-commandline-interface","sha":"185dfdb92f2c552f9ce2ada9d5ccb27f3acbd411","user":{"login":"xiar","id":14065584,"avatar_url":"https://avatars.githubusercontent.com/u/14065584?v=3","gravatar_id":"","url":"https://api.github.com/users/xiar","html_url":"https://github.com/xiar","followers_url":"https://api.github.com/users/xiar/followers","following_url":"https://api.github.com/users/xiar/following{/other_user}","gists_url":"https://api.github.com/users/xiar/gists{/gist_id}","starred_url":"https://api.github.com/users/xiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiar/subscriptions","organizations_url":"https://api.github.com/users/xiar/orgs","repos_url":"https://api.github.com/users/xiar/repos","events_url":"https://api.github.com/users/xiar/events{/privacy}","received_events_url":"https://api.github.com/users/xiar/received_events","type":"User","site_admin":false},"repo":{"id":67292120,"name":"infrasim-compute","full_name":"xiar/infrasim-compute","owner":{"login":"xiar","id":14065584,"avatar_url":"https://avatars.githubusercontent.com/u/14065584?v=3","gravatar_id":"","url":"https://api.github.com/users/xiar","html_url":"https://github.com/xiar","followers_url":"https://api.github.com/users/xiar/followers","following_url":"https://api.github.com/users/xiar/following{/other_user}","gists_url":"https://api.github.com/users/xiar/gists{/gist_id}","starred_url":"https://api.github.com/users/xiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiar/subscriptions","organizations_url":"https://api.github.com/users/xiar/orgs","repos_url":"https://api.github.com/users/xiar/repos","events_url":"https://api.github.com/users/xiar/events{/privacy}","received_events_url":"https://api.github.com/users/xiar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xiar/infrasim-compute","description":null,"fork":true,"url":"https://api.github.com/repos/xiar/infrasim-compute","forks_url":"https://api.github.com/repos/xiar/infrasim-compute/forks","keys_url":"https://api.github.com/repos/xiar/infrasim-compute/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xiar/infrasim-compute/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xiar/infrasim-compute/teams","hooks_url":"https://api.github.com/repos/xiar/infrasim-compute/hooks","issue_events_url":"https://api.github.com/repos/xiar/infrasim-compute/issues/events{/number}","events_url":"https://api.github.com/repos/xiar/infrasim-compute/events","assignees_url":"https://api.github.com/repos/xiar/infrasim-compute/assignees{/user}","branches_url":"https://api.github.com/repos/xiar/infrasim-compute/branches{/branch}","tags_url":"https://api.github.com/repos/xiar/infrasim-compute/tags","blobs_url":"https://api.github.com/repos/xiar/infrasim-compute/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xiar/infrasim-compute/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xiar/infrasim-compute/git/refs{/sha}","trees_url":"https://api.github.com/repos/xiar/infrasim-compute/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xiar/infrasim-compute/statuses/{sha}","languages_url":"https://api.github.com/repos/xiar/infrasim-compute/languages","stargazers_url":"https://api.github.com/repos/xiar/infrasim-compute/stargazers","contributors_url":"https://api.github.com/repos/xiar/infrasim-compute/contributors","subscribers_url":"https://api.github.com/repos/xiar/infrasim-compute/subscribers","subscription_url":"https://api.github.com/repos/xiar/infrasim-compute/subscription","commits_url":"https://api.github.com/repos/xiar/infrasim-compute/commits{/sha}","git_commits_url":"https://api.github.com/repos/xiar/infrasim-compute/git/commits{/sha}","comments_url":"https://api.github.com/repos/xiar/infrasim-compute/comments{/number}","issue_comment_url":"https://api.github.com/repos/xiar/infrasim-compute/issues/comments{/number}","contents_url":"https://api.github.com/repos/xiar/infrasim-compute/contents/{+path}","compare_url":"https://api.github.com/repos/xiar/infrasim-compute/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xiar/infrasim-compute/merges","archive_url":"https://api.github.com/repos/xiar/infrasim-compute/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xiar/infrasim-compute/downloads","issues_url":"https://api.github.com/repos/xiar/infrasim-compute/issues{/number}","pulls_url":"https://api.github.com/repos/xiar/infrasim-compute/pulls{/number}","milestones_url":"https://api.github.com/repos/xiar/infrasim-compute/milestones{/number}","notifications_url":"https://api.github.com/repos/xiar/infrasim-compute/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xiar/infrasim-compute/labels{/name}","releases_url":"https://api.github.com/repos/xiar/infrasim-compute/releases{/id}","deployments_url":"https://api.github.com/repos/xiar/infrasim-compute/deployments","created_at":"2016-09-03T13:40:00Z","updated_at":"2016-10-25T10:20:19Z","pushed_at":"2016-11-23T15:00:04Z","git_url":"git://github.com/xiar/infrasim-compute.git","ssh_url":"git@github.com:xiar/infrasim-compute.git","clone_url":"https://github.com/xiar/infrasim-compute.git","svn_url":"https://github.com/xiar/infrasim-compute","homepage":null,"size":19511,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"xiar:master","ref":"master","sha":"05e387be74b57753492717aec3127bb402e8ac32","user":{"login":"xiar","id":14065584,"avatar_url":"https://avatars.githubusercontent.com/u/14065584?v=3","gravatar_id":"","url":"https://api.github.com/users/xiar","html_url":"https://github.com/xiar","followers_url":"https://api.github.com/users/xiar/followers","following_url":"https://api.github.com/users/xiar/following{/other_user}","gists_url":"https://api.github.com/users/xiar/gists{/gist_id}","starred_url":"https://api.github.com/users/xiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiar/subscriptions","organizations_url":"https://api.github.com/users/xiar/orgs","repos_url":"https://api.github.com/users/xiar/repos","events_url":"https://api.github.com/users/xiar/events{/privacy}","received_events_url":"https://api.github.com/users/xiar/received_events","type":"User","site_admin":false},"repo":{"id":67292120,"name":"infrasim-compute","full_name":"xiar/infrasim-compute","owner":{"login":"xiar","id":14065584,"avatar_url":"https://avatars.githubusercontent.com/u/14065584?v=3","gravatar_id":"","url":"https://api.github.com/users/xiar","html_url":"https://github.com/xiar","followers_url":"https://api.github.com/users/xiar/followers","following_url":"https://api.github.com/users/xiar/following{/other_user}","gists_url":"https://api.github.com/users/xiar/gists{/gist_id}","starred_url":"https://api.github.com/users/xiar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiar/subscriptions","organizations_url":"https://api.github.com/users/xiar/orgs","repos_url":"https://api.github.com/users/xiar/repos","events_url":"https://api.github.com/users/xiar/events{/privacy}","received_events_url":"https://api.github.com/users/xiar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xiar/infrasim-compute","description":null,"fork":true,"url":"https://api.github.com/repos/xiar/infrasim-compute","forks_url":"https://api.github.com/repos/xiar/infrasim-compute/forks","keys_url":"https://api.github.com/repos/xiar/infrasim-compute/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xiar/infrasim-compute/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xiar/infrasim-compute/teams","hooks_url":"https://api.github.com/repos/xiar/infrasim-compute/hooks","issue_events_url":"https://api.github.com/repos/xiar/infrasim-compute/issues/events{/number}","events_url":"https://api.github.com/repos/xiar/infrasim-compute/events","assignees_url":"https://api.github.com/repos/xiar/infrasim-compute/assignees{/user}","branches_url":"https://api.github.com/repos/xiar/infrasim-compute/branches{/branch}","tags_url":"https://api.github.com/repos/xiar/infrasim-compute/tags","blobs_url":"https://api.github.com/repos/xiar/infrasim-compute/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xiar/infrasim-compute/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xiar/infrasim-compute/git/refs{/sha}","trees_url":"https://api.github.com/repos/xiar/infrasim-compute/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xiar/infrasim-compute/statuses/{sha}","languages_url":"https://api.github.com/repos/xiar/infrasim-compute/languages","stargazers_url":"https://api.github.com/repos/xiar/infrasim-compute/stargazers","contributors_url":"https://api.github.com/repos/xiar/infrasim-compute/contributors","subscribers_url":"https://api.github.com/repos/xiar/infrasim-compute/subscribers","subscription_url":"https://api.github.com/repos/xiar/infrasim-compute/subscription","commits_url":"https://api.github.com/repos/xiar/infrasim-compute/commits{/sha}","git_commits_url":"https://api.github.com/repos/xiar/infrasim-compute/git/commits{/sha}","comments_url":"https://api.github.com/repos/xiar/infrasim-compute/comments{/number}","issue_comment_url":"https://api.github.com/repos/xiar/infrasim-compute/issues/comments{/number}","contents_url":"https://api.github.com/repos/xiar/infrasim-compute/contents/{+path}","compare_url":"https://api.github.com/repos/xiar/infrasim-compute/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xiar/infrasim-compute/merges","archive_url":"https://api.github.com/repos/xiar/infrasim-compute/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xiar/infrasim-compute/downloads","issues_url":"https://api.github.com/repos/xiar/infrasim-compute/issues{/number}","pulls_url":"https://api.github.com/repos/xiar/infrasim-compute/pulls{/number}","milestones_url":"https://api.github.com/repos/xiar/infrasim-compute/milestones{/number}","notifications_url":"https://api.github.com/repos/xiar/infrasim-compute/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xiar/infrasim-compute/labels{/name}","releases_url":"https://api.github.com/repos/xiar/infrasim-compute/releases{/id}","deployments_url":"https://api.github.com/repos/xiar/infrasim-compute/deployments","created_at":"2016-09-03T13:40:00Z","updated_at":"2016-10-25T10:20:19Z","pushed_at":"2016-11-23T15:00:04Z","git_url":"git://github.com/xiar/infrasim-compute.git","ssh_url":"git@github.com:xiar/infrasim-compute.git","clone_url":"https://github.com/xiar/infrasim-compute.git","svn_url":"https://github.com/xiar/infrasim-compute","homepage":null,"size":19511,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1"},"html":{"href":"https://github.com/xiar/infrasim-compute/pull/1"},"issue":{"href":"https://api.github.com/repos/xiar/infrasim-compute/issues/1"},"comments":{"href":"https://api.github.com/repos/xiar/infrasim-compute/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/xiar/infrasim-compute/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xiar/infrasim-compute/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/xiar/infrasim-compute/statuses/185dfdb92f2c552f9ce2ada9d5ccb27f3acbd411"}}}}
{"actor":{"display_login":"houndci-bot"}}