{"action":"created","comment":{"url":"https://api.github.com/repos/StackStorm/st2/pulls/comments/31933363","id":31933363,"diff_hunk":"@@ -0,0 +1,109 @@\n+# Licensed to the StackStorm, Inc ('StackStorm') under one or more\n+# contributor license agreements.  See the NOTICE file distributed with\n+# this work for additional information regarding copyright ownership.\n+# The ASF licenses this file to You under the Apache License, Version 2.0\n+# (the \"License\"); you may not use this file except in compliance with\n+# the License.  You may obtain a copy of the License at\n+#\n+# http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+import uuid\n+\n+import os\n+import tempfile\n+from oslo.config import cfg\n+from eventlet.green import subprocess\n+from st2common.util.shell import quote_unix\n+from st2common.util.green.shell import run_command\n+from st2common import log as logging\n+from st2actions.runners import ActionRunner\n+from st2actions.runners import ShellRunnerMixin\n+from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED\n+from st2common.constants.action import LIVEACTION_STATUS_FAILED\n+from st2common.constants.runners import LOCAL_RUNNER_DEFAULT_ACTION_TIMEOUT\n+import st2common.util.jsonify as jsonify\n+\n+\n+LOG = logging.getLogger(__name__)\n+\n+# constants to lookup in runner_parameters.\n+RUNNER_PATH = 'flow_path'\n+RUNNER_INPUTS = 'inputs'\n+RUNNER_TIMEOUT = 'timeout'\n+\n+\n+def get_runner():\n+    return CloudSlangRunner(str(uuid.uuid4()))\n+\n+\n+class CloudSlangRunner(ActionRunner, ShellRunnerMixin):\n+    \"\"\"\n+    Runner which executes cloudslang flows and operations as single action\n+    \"\"\"\n+    KEYS_TO_TRANSFORM = ['stdout', 'stderr']\n+\n+    def __init__(self, runner_id):\n+        super(CloudSlangRunner, self).__init__(runner_id=runner_id)\n+\n+    def pre_run(self):\n+        self._user = cfg.CONF.system_user.user\n+        self._cloudslang_home = cfg.CONF.cloudslang.home_dir\n+        self._path = self.runner_parameters.get(RUNNER_PATH)\n+        self._inputs = self.runner_parameters.get(RUNNER_INPUTS)\n+        self._timeout = self.runner_parameters.get(RUNNER_TIMEOUT,\n+                                                   LOCAL_RUNNER_DEFAULT_ACTION_TIMEOUT)\n+\n+    def run(self, action_parameters):\n+        LOG.debug('    action_parameters = %s', action_parameters)\n+\n+        inputs_file = tempfile.NamedTemporaryFile()\n+        has_inputs = self._inputs is not None\n+        if has_inputs:\n+            LOG.info(self._inputs)\n+            inputs_dict = dict(pair.split(\"=\") for pair in self._inputs.split(\",\"))\n+            LOG.info(inputs_dict)\n+            import yaml\n+            inputs_file.write(yaml.safe_dump(inputs_dict, default_flow_style=False))\n+            inputs_file.seek(0)\n+\n+            for line in inputs_file:\n+                LOG.info(line.rstrip())\n+\n+        LOG.info(self._cloudslang_home)\n+        cloudslang_binary = os.path.join(self._cloudslang_home, \"bin/cslang\")\n+        LOG.info(cloudslang_binary)\n+        command_args = ['--f', self._path,\n+                        '--if', inputs_file.name if has_inputs else \"\",\n+                        '--cp', self._cloudslang_home]\n+        command = cloudslang_binary + \" run \" + \" \".join([quote_unix(arg) for arg in command_args])\n+\n+        LOG.info('Executing action via CloudSlangRunner: %s', self.runner_id)\n+        LOG.debug('command is: %s', command)\n+\n+        exit_code, stdout, stderr, timed_out = run_command(","path":"st2actions/st2actions/runners/cloudslang/cloudslang_runner.py","position":89,"original_position":89,"commit_id":"1eec258446d08ad4b8dee5ea2434d2cb6dd7a9cc","original_commit_id":"014bad47b936d4021ac39e60b3a2652e6e0ae562","user":{"login":"orius123","id":4418018,"avatar_url":"https://avatars.githubusercontent.com/u/4418018?v=3","gravatar_id":"","url":"https://api.github.com/users/orius123","html_url":"https://github.com/orius123","followers_url":"https://api.github.com/users/orius123/followers","following_url":"https://api.github.com/users/orius123/following{/other_user}","gists_url":"https://api.github.com/users/orius123/gists{/gist_id}","starred_url":"https://api.github.com/users/orius123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orius123/subscriptions","organizations_url":"https://api.github.com/users/orius123/orgs","repos_url":"https://api.github.com/users/orius123/repos","events_url":"https://api.github.com/users/orius123/events{/privacy}","received_events_url":"https://api.github.com/users/orius123/received_events","type":"User","site_admin":false},"body":"Will do next","created_at":"2015-06-08T16:34:31Z","updated_at":"2015-06-08T16:34:31Z","html_url":"https://github.com/StackStorm/st2/pull/1491#discussion_r31933363","pull_request_url":"https://api.github.com/repos/StackStorm/st2/pulls/1491","_links":{"self":{"href":"https://api.github.com/repos/StackStorm/st2/pulls/comments/31933363"},"html":{"href":"https://github.com/StackStorm/st2/pull/1491#discussion_r31933363"},"pull_request":{"href":"https://api.github.com/repos/StackStorm/st2/pulls/1491"}}},"pull_request":{"url":"https://api.github.com/repos/StackStorm/st2/pulls/1491","id":35631866,"html_url":"https://github.com/StackStorm/st2/pull/1491","diff_url":"https://github.com/StackStorm/st2/pull/1491.diff","patch_url":"https://github.com/StackStorm/st2/pull/1491.patch","issue_url":"https://api.github.com/repos/StackStorm/st2/issues/1491","number":1491,"state":"open","locked":false,"title":"[WIP] Integrate CloudSlang with StackStorm","user":{"login":"meirwah","id":6059211,"avatar_url":"https://avatars.githubusercontent.com/u/6059211?v=3","gravatar_id":"","url":"https://api.github.com/users/meirwah","html_url":"https://github.com/meirwah","followers_url":"https://api.github.com/users/meirwah/followers","following_url":"https://api.github.com/users/meirwah/following{/other_user}","gists_url":"https://api.github.com/users/meirwah/gists{/gist_id}","starred_url":"https://api.github.com/users/meirwah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meirwah/subscriptions","organizations_url":"https://api.github.com/users/meirwah/orgs","repos_url":"https://api.github.com/users/meirwah/repos","events_url":"https://api.github.com/users/meirwah/events{/privacy}","received_events_url":"https://api.github.com/users/meirwah/received_events","type":"User","site_admin":false},"body":"We are looking to integrate CloudSlang (http://www.cloudslang.io/) workflow engine with StackStorm.\r\n\r\nAdding @orius123 from CloudSlang team...\r\n\r\nThis is an early WIP, to make sure we are doing it the right way..\r\nThe idea is to add a new Runner (just added here a copy of LocalShellRunner, so ignore the new file content) , that will trigger CloudSlang (as a script, using simple shell cmd). \r\n\r\nThis is for first phase...\r\n\r\nAny thoughts ? comments?\r\n \r\n","created_at":"2015-05-18T13:13:55Z","updated_at":"2015-06-08T16:34:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"813c900b37434f13d4cb7bed43285e03a0511875","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/StackStorm/st2/pulls/1491/commits","review_comments_url":"https://api.github.com/repos/StackStorm/st2/pulls/1491/comments","review_comment_url":"https://api.github.com/repos/StackStorm/st2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/StackStorm/st2/issues/1491/comments","statuses_url":"https://api.github.com/repos/StackStorm/st2/statuses/1eec258446d08ad4b8dee5ea2434d2cb6dd7a9cc","head":{"label":"meirwah:master","ref":"master","sha":"1eec258446d08ad4b8dee5ea2434d2cb6dd7a9cc","user":{"login":"meirwah","id":6059211,"avatar_url":"https://avatars.githubusercontent.com/u/6059211?v=3","gravatar_id":"","url":"https://api.github.com/users/meirwah","html_url":"https://github.com/meirwah","followers_url":"https://api.github.com/users/meirwah/followers","following_url":"https://api.github.com/users/meirwah/following{/other_user}","gists_url":"https://api.github.com/users/meirwah/gists{/gist_id}","starred_url":"https://api.github.com/users/meirwah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meirwah/subscriptions","organizations_url":"https://api.github.com/users/meirwah/orgs","repos_url":"https://api.github.com/users/meirwah/repos","events_url":"https://api.github.com/users/meirwah/events{/privacy}","received_events_url":"https://api.github.com/users/meirwah/received_events","type":"User","site_admin":false},"repo":{"id":35494023,"name":"st2","full_name":"meirwah/st2","owner":{"login":"meirwah","id":6059211,"avatar_url":"https://avatars.githubusercontent.com/u/6059211?v=3","gravatar_id":"","url":"https://api.github.com/users/meirwah","html_url":"https://github.com/meirwah","followers_url":"https://api.github.com/users/meirwah/followers","following_url":"https://api.github.com/users/meirwah/following{/other_user}","gists_url":"https://api.github.com/users/meirwah/gists{/gist_id}","starred_url":"https://api.github.com/users/meirwah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meirwah/subscriptions","organizations_url":"https://api.github.com/users/meirwah/orgs","repos_url":"https://api.github.com/users/meirwah/repos","events_url":"https://api.github.com/users/meirwah/events{/privacy}","received_events_url":"https://api.github.com/users/meirwah/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/meirwah/st2","description":"StackStorm event driven automation code.  With workflow, rules engine, many to many integration and more.  Aka IFTTT for Ops (uber orchestration).  Ping us on IRC #stackstorm. ","fork":true,"url":"https://api.github.com/repos/meirwah/st2","forks_url":"https://api.github.com/repos/meirwah/st2/forks","keys_url":"https://api.github.com/repos/meirwah/st2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meirwah/st2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meirwah/st2/teams","hooks_url":"https://api.github.com/repos/meirwah/st2/hooks","issue_events_url":"https://api.github.com/repos/meirwah/st2/issues/events{/number}","events_url":"https://api.github.com/repos/meirwah/st2/events","assignees_url":"https://api.github.com/repos/meirwah/st2/assignees{/user}","branches_url":"https://api.github.com/repos/meirwah/st2/branches{/branch}","tags_url":"https://api.github.com/repos/meirwah/st2/tags","blobs_url":"https://api.github.com/repos/meirwah/st2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meirwah/st2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meirwah/st2/git/refs{/sha}","trees_url":"https://api.github.com/repos/meirwah/st2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meirwah/st2/statuses/{sha}","languages_url":"https://api.github.com/repos/meirwah/st2/languages","stargazers_url":"https://api.github.com/repos/meirwah/st2/stargazers","contributors_url":"https://api.github.com/repos/meirwah/st2/contributors","subscribers_url":"https://api.github.com/repos/meirwah/st2/subscribers","subscription_url":"https://api.github.com/repos/meirwah/st2/subscription","commits_url":"https://api.github.com/repos/meirwah/st2/commits{/sha}","git_commits_url":"https://api.github.com/repos/meirwah/st2/git/commits{/sha}","comments_url":"https://api.github.com/repos/meirwah/st2/comments{/number}","issue_comment_url":"https://api.github.com/repos/meirwah/st2/issues/comments{/number}","contents_url":"https://api.github.com/repos/meirwah/st2/contents/{+path}","compare_url":"https://api.github.com/repos/meirwah/st2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meirwah/st2/merges","archive_url":"https://api.github.com/repos/meirwah/st2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meirwah/st2/downloads","issues_url":"https://api.github.com/repos/meirwah/st2/issues{/number}","pulls_url":"https://api.github.com/repos/meirwah/st2/pulls{/number}","milestones_url":"https://api.github.com/repos/meirwah/st2/milestones{/number}","notifications_url":"https://api.github.com/repos/meirwah/st2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meirwah/st2/labels{/name}","releases_url":"https://api.github.com/repos/meirwah/st2/releases{/id}","created_at":"2015-05-12T14:46:36Z","updated_at":"2015-05-12T14:46:38Z","pushed_at":"2015-06-08T15:28:15Z","git_url":"git://github.com/meirwah/st2.git","ssh_url":"git@github.com:meirwah/st2.git","clone_url":"https://github.com/meirwah/st2.git","svn_url":"https://github.com/meirwah/st2","homepage":"http://www.stackstorm.com/","size":7940,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"StackStorm:master","ref":"master","sha":"a0e9b3d00a003dc41493d212763cd48fec8d62a7","user":{"login":"StackStorm","id":4969009,"avatar_url":"https://avatars.githubusercontent.com/u/4969009?v=3","gravatar_id":"","url":"https://api.github.com/users/StackStorm","html_url":"https://github.com/StackStorm","followers_url":"https://api.github.com/users/StackStorm/followers","following_url":"https://api.github.com/users/StackStorm/following{/other_user}","gists_url":"https://api.github.com/users/StackStorm/gists{/gist_id}","starred_url":"https://api.github.com/users/StackStorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StackStorm/subscriptions","organizations_url":"https://api.github.com/users/StackStorm/orgs","repos_url":"https://api.github.com/users/StackStorm/repos","events_url":"https://api.github.com/users/StackStorm/events{/privacy}","received_events_url":"https://api.github.com/users/StackStorm/received_events","type":"Organization","site_admin":false},"repo":{"id":19051806,"name":"st2","full_name":"StackStorm/st2","owner":{"login":"StackStorm","id":4969009,"avatar_url":"https://avatars.githubusercontent.com/u/4969009?v=3","gravatar_id":"","url":"https://api.github.com/users/StackStorm","html_url":"https://github.com/StackStorm","followers_url":"https://api.github.com/users/StackStorm/followers","following_url":"https://api.github.com/users/StackStorm/following{/other_user}","gists_url":"https://api.github.com/users/StackStorm/gists{/gist_id}","starred_url":"https://api.github.com/users/StackStorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StackStorm/subscriptions","organizations_url":"https://api.github.com/users/StackStorm/orgs","repos_url":"https://api.github.com/users/StackStorm/repos","events_url":"https://api.github.com/users/StackStorm/events{/privacy}","received_events_url":"https://api.github.com/users/StackStorm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/StackStorm/st2","description":"StackStorm event driven automation code.  With workflow, rules engine, many to many integration and more.  Aka IFTTT for Ops (uber orchestration).  Ping us on IRC #stackstorm. ","fork":false,"url":"https://api.github.com/repos/StackStorm/st2","forks_url":"https://api.github.com/repos/StackStorm/st2/forks","keys_url":"https://api.github.com/repos/StackStorm/st2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/StackStorm/st2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/StackStorm/st2/teams","hooks_url":"https://api.github.com/repos/StackStorm/st2/hooks","issue_events_url":"https://api.github.com/repos/StackStorm/st2/issues/events{/number}","events_url":"https://api.github.com/repos/StackStorm/st2/events","assignees_url":"https://api.github.com/repos/StackStorm/st2/assignees{/user}","branches_url":"https://api.github.com/repos/StackStorm/st2/branches{/branch}","tags_url":"https://api.github.com/repos/StackStorm/st2/tags","blobs_url":"https://api.github.com/repos/StackStorm/st2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/StackStorm/st2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/StackStorm/st2/git/refs{/sha}","trees_url":"https://api.github.com/repos/StackStorm/st2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/StackStorm/st2/statuses/{sha}","languages_url":"https://api.github.com/repos/StackStorm/st2/languages","stargazers_url":"https://api.github.com/repos/StackStorm/st2/stargazers","contributors_url":"https://api.github.com/repos/StackStorm/st2/contributors","subscribers_url":"https://api.github.com/repos/StackStorm/st2/subscribers","subscription_url":"https://api.github.com/repos/StackStorm/st2/subscription","commits_url":"https://api.github.com/repos/StackStorm/st2/commits{/sha}","git_commits_url":"https://api.github.com/repos/StackStorm/st2/git/commits{/sha}","comments_url":"https://api.github.com/repos/StackStorm/st2/comments{/number}","issue_comment_url":"https://api.github.com/repos/StackStorm/st2/issues/comments{/number}","contents_url":"https://api.github.com/repos/StackStorm/st2/contents/{+path}","compare_url":"https://api.github.com/repos/StackStorm/st2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/StackStorm/st2/merges","archive_url":"https://api.github.com/repos/StackStorm/st2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/StackStorm/st2/downloads","issues_url":"https://api.github.com/repos/StackStorm/st2/issues{/number}","pulls_url":"https://api.github.com/repos/StackStorm/st2/pulls{/number}","milestones_url":"https://api.github.com/repos/StackStorm/st2/milestones{/number}","notifications_url":"https://api.github.com/repos/StackStorm/st2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/StackStorm/st2/labels{/name}","releases_url":"https://api.github.com/repos/StackStorm/st2/releases{/id}","created_at":"2014-04-23T00:51:34Z","updated_at":"2015-06-08T15:04:51Z","pushed_at":"2015-06-08T16:18:15Z","git_url":"git://github.com/StackStorm/st2.git","ssh_url":"git@github.com:StackStorm/st2.git","clone_url":"https://github.com/StackStorm/st2.git","svn_url":"https://github.com/StackStorm/st2","homepage":"http://www.stackstorm.com/","size":23022,"stargazers_count":197,"watchers_count":197,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":26,"forks":45,"open_issues":26,"watchers":197,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/StackStorm/st2/pulls/1491"},"html":{"href":"https://github.com/StackStorm/st2/pull/1491"},"issue":{"href":"https://api.github.com/repos/StackStorm/st2/issues/1491"},"comments":{"href":"https://api.github.com/repos/StackStorm/st2/issues/1491/comments"},"review_comments":{"href":"https://api.github.com/repos/StackStorm/st2/pulls/1491/comments"},"review_comment":{"href":"https://api.github.com/repos/StackStorm/st2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/StackStorm/st2/pulls/1491/commits"},"statuses":{"href":"https://api.github.com/repos/StackStorm/st2/statuses/1eec258446d08ad4b8dee5ea2434d2cb6dd7a9cc"}}}}