{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/40236582","id":40236582,"diff_hunk":"@@ -211,6 +247,161 @@ def get_locations\n           location.match(VALID_LOCATION).to_s\n         end\n       end\n+\n+      def parse_stack(deployment)\n+        name = deployment.fetch_path('name')\n+        uid = resource_uid(@subscription_id,\n+                           deployment.fetch_path('resourceGroup'),\n+                           TYPE_DEPLOYMENT,\n+                           name)\n+        child_stacks, resources = find_stack_resources(deployment)\n+        new_result = {\n+          :type        => ManageIQ::Providers::Azure::CloudManager::OrchestrationStack.name,\n+          :ems_ref     => deployment.fetch_path('id'),\n+          :name        => name,\n+          :description => name,\n+          :status      => deployment.fetch_path('properties', 'provisioningState'),\n+          :children    => child_stacks,\n+          :resources   => resources,\n+          :outputs     => find_stack_outputs(deployment),\n+          :parameters  => find_stack_parameters(deployment),\n+\n+          :orchestration_template => find_stack_template(deployment)\n+        }\n+        return uid, new_result\n+      end\n+\n+      def find_stack_template(deployment)\n+        uri = deployment.fetch_path('properties', 'templateLink', 'uri')\n+        return unless uri\n+\n+        content = download_template(uri)\n+        return unless content\n+\n+        get_stack_template(deployment, content)\n+        @data_index.fetch_path(:orchestration_templates, deployment.fetch_path('id'))\n+      end\n+\n+      def download_template(uri)\n+        require 'open-uri'\n+        open(uri) { |f| f.read }\n+      rescue => e\n+        _log.error(\"Failed to download Azure template #{uri}. Reason: #{e.inspect}\")\n+        nil\n+      end\n+\n+      def find_stack_parameters(deployment)\n+        raw_parameters = deployment.fetch_path('properties', 'parameters')\n+        return [] if raw_parameters.blank?\n+\n+        stack_id = deployment.fetch_path('id')\n+        get_stack_parameters(stack_id, raw_parameters)\n+        raw_parameters.collect do |param_key, _val|\n+          @data_index.fetch_path(:orchestration_stack_parameters, resource_uid(stack_id, param_key))\n+        end\n+      end\n+\n+      def find_stack_outputs(deployment)\n+        raw_outputs = deployment.fetch_path('properties', 'outputs')\n+        return [] if raw_outputs.blank?\n+\n+        stack_id = deployment.fetch_path('id')\n+        get_stack_outputs(stack_id, raw_outputs)\n+        raw_outputs.collect do |output_key, _val|\n+          @data_index.fetch_path(:orchestration_stack_outputs, resource_uid(stack_id, output_key))\n+        end\n+      end\n+\n+      def find_stack_resources(deployment)\n+        group = deployment.fetch_path('resourceGroup')\n+        name = deployment.fetch_path('name')\n+        stack_uid = resource_uid(@subscription_id, group, TYPE_DEPLOYMENT, name)\n+        raw_resources = @tds.list_deployment_operations(name, group)\n+\n+        raw_resources.reject! { |r| r.fetch_path('properties', 'targetResource', 'id').nil? }","path":"app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb","position":188,"original_position":188,"commit_id":"cfe96a34263d85e143c4930b32d63cd1a4153dc1","original_commit_id":"cfe96a34263d85e143c4930b32d63cd1a4153dc1","user":{"login":"bronaghs","id":4379675,"avatar_url":"https://avatars.githubusercontent.com/u/4379675?v=3","gravatar_id":"","url":"https://api.github.com/users/bronaghs","html_url":"https://github.com/bronaghs","followers_url":"https://api.github.com/users/bronaghs/followers","following_url":"https://api.github.com/users/bronaghs/following{/other_user}","gists_url":"https://api.github.com/users/bronaghs/gists{/gist_id}","starred_url":"https://api.github.com/users/bronaghs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bronaghs/subscriptions","organizations_url":"https://api.github.com/users/bronaghs/orgs","repos_url":"https://api.github.com/users/bronaghs/repos","events_url":"https://api.github.com/users/bronaghs/events{/privacy}","received_events_url":"https://api.github.com/users/bronaghs/received_events","type":"User","site_admin":false},"body":"@bzwei - ah I see you can't, you use raw_resources below","created_at":"2015-09-23T18:06:33Z","updated_at":"2015-09-23T18:06:33Z","html_url":"https://github.com/ManageIQ/manageiq/pull/4477#discussion_r40236582","pull_request_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/40236582"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/4477#discussion_r40236582"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477","id":45698596,"html_url":"https://github.com/ManageIQ/manageiq/pull/4477","diff_url":"https://github.com/ManageIQ/manageiq/pull/4477.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/4477.patch","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/4477","number":4477,"state":"open","locked":false,"title":"Azure deployments refresh","user":{"login":"bzwei","id":7047579,"avatar_url":"https://avatars.githubusercontent.com/u/7047579?v=3","gravatar_id":"","url":"https://api.github.com/users/bzwei","html_url":"https://github.com/bzwei","followers_url":"https://api.github.com/users/bzwei/followers","following_url":"https://api.github.com/users/bzwei/following{/other_user}","gists_url":"https://api.github.com/users/bzwei/gists{/gist_id}","starred_url":"https://api.github.com/users/bzwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzwei/subscriptions","organizations_url":"https://api.github.com/users/bzwei/orgs","repos_url":"https://api.github.com/users/bzwei/repos","events_url":"https://api.github.com/users/bzwei/events{/privacy}","received_events_url":"https://api.github.com/users/bzwei/received_events","type":"User","site_admin":false},"body":"Provider refresh now scans through Azure deployments and converts them into orchestration stacks. In Azure deployments are created from templates. If a deployment is created through a template URL, this URL is included in the deployment information returned by Azure resource manager API. If a deployment is created directly from a template, the content of the template is not retrievable through the API. This is a limitation comparing with other providers such as OpenStack or AWS.\r\n\r\nDuring the refresh if a template URL can be obtained, its content will be downloaded and saved as `OrchestrationTemplateAzure`. Otherwise the stack is left without an associated template.\r\n\r\nEach stack can have multiple resources, parameters, and outputs. Some resources have models in manageiq such as instances, security groups, and networks. Currently only instances are linked with stacks. The linkage between other types can be added in the future.","created_at":"2015-09-22T18:23:04Z","updated_at":"2015-09-23T18:06:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"841831bebb315bac60120b0a182ccba4007356c0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/4477/comments","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/cfe96a34263d85e143c4930b32d63cd1a4153dc1","head":{"label":"bzwei:azure_deployments_refresh","ref":"azure_deployments_refresh","sha":"cfe96a34263d85e143c4930b32d63cd1a4153dc1","user":{"login":"bzwei","id":7047579,"avatar_url":"https://avatars.githubusercontent.com/u/7047579?v=3","gravatar_id":"","url":"https://api.github.com/users/bzwei","html_url":"https://github.com/bzwei","followers_url":"https://api.github.com/users/bzwei/followers","following_url":"https://api.github.com/users/bzwei/following{/other_user}","gists_url":"https://api.github.com/users/bzwei/gists{/gist_id}","starred_url":"https://api.github.com/users/bzwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzwei/subscriptions","organizations_url":"https://api.github.com/users/bzwei/orgs","repos_url":"https://api.github.com/users/bzwei/repos","events_url":"https://api.github.com/users/bzwei/events{/privacy}","received_events_url":"https://api.github.com/users/bzwei/received_events","type":"User","site_admin":false},"repo":{"id":20813025,"name":"manageiq","full_name":"bzwei/manageiq","owner":{"login":"bzwei","id":7047579,"avatar_url":"https://avatars.githubusercontent.com/u/7047579?v=3","gravatar_id":"","url":"https://api.github.com/users/bzwei","html_url":"https://github.com/bzwei","followers_url":"https://api.github.com/users/bzwei/followers","following_url":"https://api.github.com/users/bzwei/following{/other_user}","gists_url":"https://api.github.com/users/bzwei/gists{/gist_id}","starred_url":"https://api.github.com/users/bzwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzwei/subscriptions","organizations_url":"https://api.github.com/users/bzwei/orgs","repos_url":"https://api.github.com/users/bzwei/repos","events_url":"https://api.github.com/users/bzwei/events{/privacy}","received_events_url":"https://api.github.com/users/bzwei/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bzwei/manageiq","description":"ManageIQ Cloud Management Platform","fork":true,"url":"https://api.github.com/repos/bzwei/manageiq","forks_url":"https://api.github.com/repos/bzwei/manageiq/forks","keys_url":"https://api.github.com/repos/bzwei/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bzwei/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bzwei/manageiq/teams","hooks_url":"https://api.github.com/repos/bzwei/manageiq/hooks","issue_events_url":"https://api.github.com/repos/bzwei/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/bzwei/manageiq/events","assignees_url":"https://api.github.com/repos/bzwei/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/bzwei/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/bzwei/manageiq/tags","blobs_url":"https://api.github.com/repos/bzwei/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bzwei/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bzwei/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/bzwei/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bzwei/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/bzwei/manageiq/languages","stargazers_url":"https://api.github.com/repos/bzwei/manageiq/stargazers","contributors_url":"https://api.github.com/repos/bzwei/manageiq/contributors","subscribers_url":"https://api.github.com/repos/bzwei/manageiq/subscribers","subscription_url":"https://api.github.com/repos/bzwei/manageiq/subscription","commits_url":"https://api.github.com/repos/bzwei/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/bzwei/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/bzwei/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/bzwei/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/bzwei/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/bzwei/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bzwei/manageiq/merges","archive_url":"https://api.github.com/repos/bzwei/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bzwei/manageiq/downloads","issues_url":"https://api.github.com/repos/bzwei/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/bzwei/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/bzwei/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/bzwei/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bzwei/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/bzwei/manageiq/releases{/id}","created_at":"2014-06-13T18:02:48Z","updated_at":"2014-06-24T18:52:43Z","pushed_at":"2015-09-22T19:01:37Z","git_url":"git://github.com/bzwei/manageiq.git","ssh_url":"git@github.com:bzwei/manageiq.git","clone_url":"https://github.com/bzwei/manageiq.git","svn_url":"https://github.com/bzwei/manageiq","homepage":null,"size":84928,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"ManageIQ:master","ref":"master","sha":"c6dcc95371f2b76425d7dac4276e88399c6eb816","user":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":20789757,"name":"manageiq","full_name":"ManageIQ/manageiq","owner":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ManageIQ/manageiq","description":"ManageIQ Cloud Management Platform","fork":false,"url":"https://api.github.com/repos/ManageIQ/manageiq","forks_url":"https://api.github.com/repos/ManageIQ/manageiq/forks","keys_url":"https://api.github.com/repos/ManageIQ/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/manageiq/teams","hooks_url":"https://api.github.com/repos/ManageIQ/manageiq/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/manageiq/events","assignees_url":"https://api.github.com/repos/ManageIQ/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/manageiq/tags","blobs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/manageiq/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/manageiq/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/manageiq/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/manageiq/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/manageiq/subscription","commits_url":"https://api.github.com/repos/ManageIQ/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/ManageIQ/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/manageiq/merges","archive_url":"https://api.github.com/repos/ManageIQ/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/manageiq/downloads","issues_url":"https://api.github.com/repos/ManageIQ/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/manageiq/releases{/id}","created_at":"2014-06-13T02:31:26Z","updated_at":"2015-09-22T01:10:08Z","pushed_at":"2015-09-23T17:58:07Z","git_url":"git://github.com/ManageIQ/manageiq.git","ssh_url":"git@github.com:ManageIQ/manageiq.git","clone_url":"https://github.com/ManageIQ/manageiq.git","svn_url":"https://github.com/ManageIQ/manageiq","homepage":"manageiq.org","size":162303,"stargazers_count":152,"watchers_count":152,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":416,"forks":156,"open_issues":416,"watchers":152,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/4477"},"issue":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/4477"},"comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/4477/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4477/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/manageiq/statuses/cfe96a34263d85e143c4930b32d63cd1a4153dc1"}}}}