{"action":"created","comment":{"url":"https://api.github.com/repos/chef/ohai/pulls/comments/62764811","id":62764811,"diff_hunk":"@@ -18,53 +19,62 @@\n require \"ohai/mixin/ec2_metadata\"\n \n Ohai.plugin(:Openstack) do\n+  include Ohai::Mixin::Ec2Metadata\n+\n   provides \"openstack\"\n+  depends \"dmi\"\n+  depends \"etc\"\n \n-  include Ohai::Mixin::Ec2Metadata\n+  # do we have the openstack dmi data\n+  def openstack_dmi?\n+    # detect a manufacturer of OpenStack Foundation\n+    if dmi[:system][:all_records][0][:Manufacturer] =~ /OpenStack/\n+      Ohai::Log.debug(\"Plugin Openstack: has_openstack_dmi? == true\")\n+      true\n+    end\n+  rescue NoMethodError\n+    Ohai::Log.debug(\"Plugin Openstack: has_openstack_dmi? == false\")\n+    false\n+  end\n \n-  def collect_openstack_metadata(addr = Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, api_version = \"2013-04-04\")\n-    path = \"/openstack/#{api_version}/meta_data.json\"\n-    uri = \"http://#{addr}#{path}\"\n+  # check for the ohai hint and log debug messaging\n+  def openstack_hint?\n+    if hint?(\"openstack\")\n+      Ohai::Log.debug(\"Plugin Openstack: openstack hint present\")\n+      return true\n+    else\n+      Ohai::Log.debug(\"Plugin Openstack: openstack hint not present\")\n+      return false\n+    end\n+  end\n+\n+  # dreamhost systems have the dhc-user on them\n+  def openstack_provider\n     begin\n-      response = http_client.get_response(URI.parse(uri), nil, nil)\n-      case response.code\n-      when \"200\"\n-        FFI_Yajl::Parser.parse(response.body)\n-      when \"404\"\n-        Ohai::Log.debug(\"Encountered 404 response retreiving OpenStack specific metadata path: #{path} ; continuing.\")\n-        nil\n-      else\n-        raise \"Encountered error retrieving OpenStack specific metadata (#{path} returned #{response.code} response)\"\n-      end\n-    rescue => e\n-      Ohai::Log.debug(\"Encountered error retrieving OpenStack specific metadata (#{uri}), due to #{e.class}\")\n-      nil\n+      return \"dreamhost\" if etc[\"passwd\"][\"dhc-user\"]\n+    rescue NoMethodError\n+      # handle etc not existing on non-linux systems\n     end\n+    return \"openstack\"\n   end\n \n   collect_data do\n-    # Adds openstack Mash\n-    if hint?(\"openstack\") || hint?(\"hp\")\n-      Ohai::Log.debug(\"ohai openstack\")\n-\n-      if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)\n-        openstack Mash.new\n-        Ohai::Log.debug(\"connecting to the OpenStack metadata service\")\n-        fetch_metadata.each { |k, v| openstack[k] = v }\n+    # fetch data if we look like openstack\n+    if openstack_hint? || openstack_dmi?\n+      openstack Mash.new\n+      openstack[:provider] = openstack_provider\n \n-        if hint?(\"hp\")\n-          openstack[\"provider\"] = \"hp\"\n-        else\n-          openstack[\"provider\"] = \"openstack\"\n-          Ohai::Log.debug(\"connecting to the OpenStack specific metadata service\")\n-          openstack[\"metadata\"] = collect_openstack_metadata\n+      # fetch the metadata if we can do a simple socket connect first\n+      if can_metadata_connect?(\"169.254.169.254\", 80)","path":"lib/ohai/plugins/openstack.rb","position":88,"original_position":88,"commit_id":"7809966803e987241a03652411fb4b0c5ee1a09f","original_commit_id":"cbca3e0138445ad5478cb72a442dfb57d6977ffb","user":{"login":"tas50","id":1015200,"avatar_url":"https://avatars.githubusercontent.com/u/1015200?v=3","gravatar_id":"","url":"https://api.github.com/users/tas50","html_url":"https://github.com/tas50","followers_url":"https://api.github.com/users/tas50/followers","following_url":"https://api.github.com/users/tas50/following{/other_user}","gists_url":"https://api.github.com/users/tas50/gists{/gist_id}","starred_url":"https://api.github.com/users/tas50/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tas50/subscriptions","organizations_url":"https://api.github.com/users/tas50/orgs","repos_url":"https://api.github.com/users/tas50/repos","events_url":"https://api.github.com/users/tas50/events{/privacy}","received_events_url":"https://api.github.com/users/tas50/received_events","type":"User","site_admin":false},"body":"While it is the same thing it seems a bit odd to me to use that variable","created_at":"2016-05-10T22:24:23Z","updated_at":"2016-05-10T22:24:23Z","html_url":"https://github.com/chef/ohai/pull/818#discussion_r62764811","pull_request_url":"https://api.github.com/repos/chef/ohai/pulls/818","_links":{"self":{"href":"https://api.github.com/repos/chef/ohai/pulls/comments/62764811"},"html":{"href":"https://github.com/chef/ohai/pull/818#discussion_r62764811"},"pull_request":{"href":"https://api.github.com/repos/chef/ohai/pulls/818"}}},"pull_request":{"url":"https://api.github.com/repos/chef/ohai/pulls/818","id":69397749,"html_url":"https://github.com/chef/ohai/pull/818","diff_url":"https://github.com/chef/ohai/pull/818.diff","patch_url":"https://github.com/chef/ohai/pull/818.patch","issue_url":"https://api.github.com/repos/chef/ohai/issues/818","number":818,"state":"open","locked":false,"title":"Properly poll Openstack detection + other Openstack improvements","user":{"login":"tas50","id":1015200,"avatar_url":"https://avatars.githubusercontent.com/u/1015200?v=3","gravatar_id":"","url":"https://api.github.com/users/tas50","html_url":"https://github.com/tas50","followers_url":"https://api.github.com/users/tas50/followers","following_url":"https://api.github.com/users/tas50/following{/other_user}","gists_url":"https://api.github.com/users/tas50/gists{/gist_id}","starred_url":"https://api.github.com/users/tas50/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tas50/subscriptions","organizations_url":"https://api.github.com/users/tas50/orgs","repos_url":"https://api.github.com/users/tas50/repos","events_url":"https://api.github.com/users/tas50/events{/privacy}","received_events_url":"https://api.github.com/users/tas50/received_events","type":"User","site_admin":false},"body":"The existing Openstack metadata logic failed as it was hardcoded to use metadata from 2013 that doesn't seem to exist in standard installs. Instead lets use the logic in the EC2 metadata mixin to find the latest version we support.\r\nWrap metadata fetching around  socket connection check from the EC2 metadata plugin. This prevents hung Ohai runs on providers that don't support the metadata endpoint\r\nGrab the Openstack data correctly in the Cloud plugins\r\nDetect a system as being on Openstack based on DMI data\r\nRemove HP cloud logic since that's dead\r\nAdd debug logging so we can follow what's happening in the logs better\r\n\r\nPreviously nil data we now have:\r\n\r\n```json\r\n \"cloud\": {\r\n    \"public_ips\": [\r\n      \"172.16.20.52\"\r\n    ],\r\n    \"private_ips\": [\r\n      \"192.168.1.203\"\r\n    ],\r\n    \"public_ipv4\": \"172.16.20.52\",\r\n    \"public_hostname\": \"ohai.novalocal\",\r\n    \"local_ipv4\": \"192.168.1.203\",\r\n    \"local_hostname\": \"ohai.novalocal\",\r\n    \"provider\": \"openstack\"\r\n  },\r\n  \"cloud_v2\": {\r\n    \"public_ipv4_addrs\": [\r\n      \"172.16.20.52\"\r\n    ],\r\n    \"local_ipv4_addrs\": [\r\n      \"192.168.1.203\"\r\n    ],\r\n    \"provider\": \"openstack\",\r\n    \"public_hostname\": \"ohai.novalocal\",\r\n    \"local_hostname\": \"ohai.novalocal\",\r\n    \"public_ipv4\": \"172.16.20.52\",\r\n    \"local_ipv4\": \"192.168.1.203\"\r\n  },\r\n \"openstack\": {\r\n    \"provider\": \"openstack\",\r\n    \"metadata\": {\r\n      \"ami_id\": \"ami-00000002\",\r\n      \"ami_launch_index\": \"0\",\r\n      \"ami_manifest_path\": \"FIXME\",\r\n      \"block_device_mapping_ami\": \"vda\",\r\n      \"block_device_mapping_root\": \"/dev/vda\",\r\n      \"hostname\": \"ohai.novalocal\",\r\n      \"instance_action\": \"none\",\r\n      \"instance_id\": \"i-00000211\",\r\n      \"instance_type\": \"m1.medium\",\r\n      \"kernel_id\": \"None\",\r\n      \"local_hostname\": \"ohai.novalocal\",\r\n      \"local_ipv4\": \"192.168.1.203\",\r\n      \"placement_availability_zone\": \"nova\",\r\n      \"public_hostname\": \"ohai.novalocal\",\r\n      \"public_ipv4\": \"172.16.20.52\",\r\n      \"public_keys_0_openssh_key\": \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxAVkrfknXoHFQtyXtYZ6vONLHn7HTKQq4mkwvCOPMKb3gr6gsLQkCdzmO3CQwOcFl7uDWGdfjH/ocuSUSn6xMvfCdsdGzDiLQXcDJ4jGOuuyOioniN1N00IhAD7Tqsf4AvbQJ7gDqfPKDCw6LdlZ0d0d9pWlJf7eKf/Hq3x8RCqWek/+UCoU4l4T1eAM0N/bA5tj3EfvRuDniO8U5ClsuUbtJ1uxJmrWMhFox3jFp6oNrleHWFTiRsNKfbtfTrTJRYlqcOG2jGAb49JY+p6Ykku4vq0ezYZFYXGJki6a0yLu1kMg5aHJo9UX0d9JW6y11KfXbGKN4okeRcH/tSNov jasghar@remasghar01.local\",\r\n      \"ramdisk_id\": \"None\",\r\n      \"reservation_id\": \"r-nvo4xzvf\",\r\n      \"security_groups\": [\r\n      ]\r\n    }\r\n```","created_at":"2016-05-09T19:33:52Z","updated_at":"2016-05-10T22:24:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"40f6ee4f1e9f147b302403033c1cdac0dd2c396c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chef/ohai/pulls/818/commits","review_comments_url":"https://api.github.com/repos/chef/ohai/pulls/818/comments","review_comment_url":"https://api.github.com/repos/chef/ohai/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chef/ohai/issues/818/comments","statuses_url":"https://api.github.com/repos/chef/ohai/statuses/7809966803e987241a03652411fb4b0c5ee1a09f","head":{"label":"chef:openstack","ref":"openstack","sha":"7809966803e987241a03652411fb4b0c5ee1a09f","user":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"repo":{"id":108289,"name":"ohai","full_name":"chef/ohai","owner":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chef/ohai","description":"Ohai profiles your system and emits JSON","fork":false,"url":"https://api.github.com/repos/chef/ohai","forks_url":"https://api.github.com/repos/chef/ohai/forks","keys_url":"https://api.github.com/repos/chef/ohai/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chef/ohai/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chef/ohai/teams","hooks_url":"https://api.github.com/repos/chef/ohai/hooks","issue_events_url":"https://api.github.com/repos/chef/ohai/issues/events{/number}","events_url":"https://api.github.com/repos/chef/ohai/events","assignees_url":"https://api.github.com/repos/chef/ohai/assignees{/user}","branches_url":"https://api.github.com/repos/chef/ohai/branches{/branch}","tags_url":"https://api.github.com/repos/chef/ohai/tags","blobs_url":"https://api.github.com/repos/chef/ohai/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chef/ohai/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chef/ohai/git/refs{/sha}","trees_url":"https://api.github.com/repos/chef/ohai/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chef/ohai/statuses/{sha}","languages_url":"https://api.github.com/repos/chef/ohai/languages","stargazers_url":"https://api.github.com/repos/chef/ohai/stargazers","contributors_url":"https://api.github.com/repos/chef/ohai/contributors","subscribers_url":"https://api.github.com/repos/chef/ohai/subscribers","subscription_url":"https://api.github.com/repos/chef/ohai/subscription","commits_url":"https://api.github.com/repos/chef/ohai/commits{/sha}","git_commits_url":"https://api.github.com/repos/chef/ohai/git/commits{/sha}","comments_url":"https://api.github.com/repos/chef/ohai/comments{/number}","issue_comment_url":"https://api.github.com/repos/chef/ohai/issues/comments{/number}","contents_url":"https://api.github.com/repos/chef/ohai/contents/{+path}","compare_url":"https://api.github.com/repos/chef/ohai/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chef/ohai/merges","archive_url":"https://api.github.com/repos/chef/ohai/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chef/ohai/downloads","issues_url":"https://api.github.com/repos/chef/ohai/issues{/number}","pulls_url":"https://api.github.com/repos/chef/ohai/pulls{/number}","milestones_url":"https://api.github.com/repos/chef/ohai/milestones{/number}","notifications_url":"https://api.github.com/repos/chef/ohai/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chef/ohai/labels{/name}","releases_url":"https://api.github.com/repos/chef/ohai/releases{/id}","deployments_url":"https://api.github.com/repos/chef/ohai/deployments","created_at":"2009-01-15T20:50:43Z","updated_at":"2016-05-05T19:51:08Z","pushed_at":"2016-05-10T22:15:28Z","git_url":"git://github.com/chef/ohai.git","ssh_url":"git@github.com:chef/ohai.git","clone_url":"https://github.com/chef/ohai.git","svn_url":"https://github.com/chef/ohai","homepage":"https://docs.chef.io/ohai.html","size":6434,"stargazers_count":507,"watchers_count":507,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":368,"mirror_url":null,"open_issues_count":41,"forks":368,"open_issues":41,"watchers":507,"default_branch":"master"}},"base":{"label":"chef:master","ref":"master","sha":"780f7c5fbdebd9d65c4605f47bad9111d1176fcc","user":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"repo":{"id":108289,"name":"ohai","full_name":"chef/ohai","owner":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chef/ohai","description":"Ohai profiles your system and emits JSON","fork":false,"url":"https://api.github.com/repos/chef/ohai","forks_url":"https://api.github.com/repos/chef/ohai/forks","keys_url":"https://api.github.com/repos/chef/ohai/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chef/ohai/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chef/ohai/teams","hooks_url":"https://api.github.com/repos/chef/ohai/hooks","issue_events_url":"https://api.github.com/repos/chef/ohai/issues/events{/number}","events_url":"https://api.github.com/repos/chef/ohai/events","assignees_url":"https://api.github.com/repos/chef/ohai/assignees{/user}","branches_url":"https://api.github.com/repos/chef/ohai/branches{/branch}","tags_url":"https://api.github.com/repos/chef/ohai/tags","blobs_url":"https://api.github.com/repos/chef/ohai/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chef/ohai/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chef/ohai/git/refs{/sha}","trees_url":"https://api.github.com/repos/chef/ohai/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chef/ohai/statuses/{sha}","languages_url":"https://api.github.com/repos/chef/ohai/languages","stargazers_url":"https://api.github.com/repos/chef/ohai/stargazers","contributors_url":"https://api.github.com/repos/chef/ohai/contributors","subscribers_url":"https://api.github.com/repos/chef/ohai/subscribers","subscription_url":"https://api.github.com/repos/chef/ohai/subscription","commits_url":"https://api.github.com/repos/chef/ohai/commits{/sha}","git_commits_url":"https://api.github.com/repos/chef/ohai/git/commits{/sha}","comments_url":"https://api.github.com/repos/chef/ohai/comments{/number}","issue_comment_url":"https://api.github.com/repos/chef/ohai/issues/comments{/number}","contents_url":"https://api.github.com/repos/chef/ohai/contents/{+path}","compare_url":"https://api.github.com/repos/chef/ohai/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chef/ohai/merges","archive_url":"https://api.github.com/repos/chef/ohai/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chef/ohai/downloads","issues_url":"https://api.github.com/repos/chef/ohai/issues{/number}","pulls_url":"https://api.github.com/repos/chef/ohai/pulls{/number}","milestones_url":"https://api.github.com/repos/chef/ohai/milestones{/number}","notifications_url":"https://api.github.com/repos/chef/ohai/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chef/ohai/labels{/name}","releases_url":"https://api.github.com/repos/chef/ohai/releases{/id}","deployments_url":"https://api.github.com/repos/chef/ohai/deployments","created_at":"2009-01-15T20:50:43Z","updated_at":"2016-05-05T19:51:08Z","pushed_at":"2016-05-10T22:15:28Z","git_url":"git://github.com/chef/ohai.git","ssh_url":"git@github.com:chef/ohai.git","clone_url":"https://github.com/chef/ohai.git","svn_url":"https://github.com/chef/ohai","homepage":"https://docs.chef.io/ohai.html","size":6434,"stargazers_count":507,"watchers_count":507,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":368,"mirror_url":null,"open_issues_count":41,"forks":368,"open_issues":41,"watchers":507,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chef/ohai/pulls/818"},"html":{"href":"https://github.com/chef/ohai/pull/818"},"issue":{"href":"https://api.github.com/repos/chef/ohai/issues/818"},"comments":{"href":"https://api.github.com/repos/chef/ohai/issues/818/comments"},"review_comments":{"href":"https://api.github.com/repos/chef/ohai/pulls/818/comments"},"review_comment":{"href":"https://api.github.com/repos/chef/ohai/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chef/ohai/pulls/818/commits"},"statuses":{"href":"https://api.github.com/repos/chef/ohai/statuses/7809966803e987241a03652411fb4b0c5ee1a09f"}}}}