summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-05-10 14:31:33 -0700
committerTim Smith <tsmith84@gmail.com>2016-05-10 14:31:33 -0700
commitcbca3e0138445ad5478cb72a442dfb57d6977ffb (patch)
tree1889879441d11607555a81c14e595cf436e50937
parent4c9a5b008fb07c859bb84959b048dbd0f7803c2b (diff)
downloadohai-cbca3e0138445ad5478cb72a442dfb57d6977ffb.tar.gz
Move metadata attributes back to openstack namespace
This reverts nesting the attributes in openstack['metadata']. This matches what we do in other clouds
-rw-r--r--lib/ohai/plugins/cloud.rb12
-rw-r--r--lib/ohai/plugins/cloud_v2.rb8
-rw-r--r--lib/ohai/plugins/openstack.rb25
-rw-r--r--spec/unit/plugins/openstack_spec.rb46
4 files changed, 43 insertions, 48 deletions
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index bb2b531a..b1b2b469 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -183,12 +183,12 @@ Ohai.plugin(:Cloud) do
# Fill cloud hash with openstack values
def get_openstack_values
- cloud[:public_ips] << openstack["metadata"]["public_ipv4"]
- cloud[:private_ips] << openstack["metadata"]["local_ipv4"]
- cloud[:public_ipv4] = openstack["metadata"]["public_ipv4"]
- cloud[:public_hostname] = openstack["metadata"]["public_hostname"]
- cloud[:local_ipv4] = openstack["metadata"]["local_ipv4"]
- cloud[:local_hostname] = openstack["metadata"]["local_hostname"]
+ cloud[:public_ips] << openstack["public_ipv4"]
+ cloud[:private_ips] << openstack["local_ipv4"]
+ cloud[:public_ipv4] = openstack["public_ipv4"]
+ cloud[:public_hostname] = openstack["public_hostname"]
+ cloud[:local_ipv4] = openstack["local_ipv4"]
+ cloud[:local_hostname] = openstack["local_hostname"]
cloud[:provider] = "openstack"
end
diff --git a/lib/ohai/plugins/cloud_v2.rb b/lib/ohai/plugins/cloud_v2.rb
index 19a491ff..7c3f3b1a 100644
--- a/lib/ohai/plugins/cloud_v2.rb
+++ b/lib/ohai/plugins/cloud_v2.rb
@@ -242,10 +242,10 @@ Ohai.plugin(:CloudV2) do
# Fill cloud hash with openstack values
def get_openstack_values
- @cloud_attr_obj.add_ipv4_addr(openstack["metadata"]["public_ipv4"], :public)
- @cloud_attr_obj.add_ipv4_addr(openstack["metadata"]["local_ipv4"], :private)
- @cloud_attr_obj.public_hostname = openstack["metadata"]["public_hostname"]
- @cloud_attr_obj.local_hostname = openstack["metadata"]["local_hostname"]
+ @cloud_attr_obj.add_ipv4_addr(openstack["public_ipv4"], :public)
+ @cloud_attr_obj.add_ipv4_addr(openstack["local_ipv4"], :private)
+ @cloud_attr_obj.public_hostname = openstack["public_hostname"]
+ @cloud_attr_obj.local_hostname = openstack["local_hostname"]
@cloud_attr_obj.provider = "openstack"
end
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb
index c2d18d2a..76317fa6 100644
--- a/lib/ohai/plugins/openstack.rb
+++ b/lib/ohai/plugins/openstack.rb
@@ -58,26 +58,21 @@ Ohai.plugin(:Openstack) do
return "openstack"
end
- # grab metadata and return a mash. if we can't connect return nil
- def openstack_metadata
- metadata = Mash.new
- if can_metadata_connect?("169.254.169.254", 80)
- fetch_metadata.each do |k, v|
- metadata[k] = v
- end
- Ohai::Log.debug("Plugin Openstack: Successfully fetched Openstack metadata from the metadata endpoint")
- else
- Ohai::Log.debug("Plugin Openstack: Timed out connecting to Openstack metadata endpoint. Skipping metadata.")
- end
- metadata
- end
-
collect_data do
# fetch data if we look like openstack
if openstack_hint? || openstack_dmi?
openstack Mash.new
openstack[:provider] = openstack_provider
- openstack[:metadata] = openstack_metadata # fetch metadata or set this to nil
+
+ # fetch the metadata if we can do a simple socket connect first
+ if can_metadata_connect?("169.254.169.254", 80)
+ fetch_metadata.each do |k, v|
+ openstack[k] = v
+ end
+ Ohai::Log.debug("Plugin Openstack: Successfully fetched Openstack metadata from the metadata endpoint")
+ else
+ Ohai::Log.debug("Plugin Openstack: Timed out connecting to Openstack metadata endpoint. Skipping metadata.")
+ end
else
Ohai::Log.debug("Plugin Openstack: Node does not appear to be an Openstack node")
end
diff --git a/spec/unit/plugins/openstack_spec.rb b/spec/unit/plugins/openstack_spec.rb
index 9b8397fb..fcca9a33 100644
--- a/spec/unit/plugins/openstack_spec.rb
+++ b/spec/unit/plugins/openstack_spec.rb
@@ -49,8 +49,8 @@ describe "OpenStack Plugin" do
expect(plugin[:openstack][:provider]).to eq("openstack")
end
- it "sets the metadata attribute to {}" do
- expect(plugin[:openstack][:metadata]).to be_empty
+ it "doesn't set metadata attributes" do
+ expect(plugin[:openstack][:instance_id]).to be_nil
end
end
end
@@ -81,8 +81,8 @@ describe "OpenStack Plugin" do
expect(plugin[:openstack][:provider]).to eq("openstack")
end
- it "sets the metadata attribute to {}" do
- expect(plugin[:openstack][:metadata]).to be_empty
+ it "doesn't set metadata attributes" do
+ expect(plugin[:openstack][:instance_id]).to be_nil
end
end
@@ -201,61 +201,61 @@ EOM
end
it "reads the reservation_id from the metadata service" do
- expect(plugin["openstack"]["metadata"]["reservation_id"]).to eq("r-4tjvl99h")
+ expect(plugin["openstack"]["reservation_id"]).to eq("r-4tjvl99h")
end
it "reads the public_keys_0_openssh_key from the metadata service" do
- expect(plugin["openstack"]["metadata"]["public_keys_0_openssh_key"]).to eq("SSH KEY DATA")
+ expect(plugin["openstack"]["public_keys_0_openssh_key"]).to eq("SSH KEY DATA")
end
it "reads the security_groups from the metadata service" do
- expect(plugin["openstack"]["metadata"]["security_groups"]).to eq(["default"])
+ expect(plugin["openstack"]["security_groups"]).to eq(["default"])
end
it "reads the public_ipv4 from the metadata service" do
- expect(plugin["openstack"]["metadata"]["public_ipv4"]).to eq("")
+ expect(plugin["openstack"]["public_ipv4"]).to eq("")
end
it "reads the ami_manifest_path from the metadata service" do
- expect(plugin["openstack"]["metadata"]["ami_manifest_path"]).to eq("FIXME")
+ expect(plugin["openstack"]["ami_manifest_path"]).to eq("FIXME")
end
it "reads the instance_type from the metadata service" do
- expect(plugin["openstack"]["metadata"]["instance_type"]).to eq("opc-tester")
+ expect(plugin["openstack"]["instance_type"]).to eq("opc-tester")
end
it "reads the instance_id from the metadata service" do
- expect(plugin["openstack"]["metadata"]["instance_id"]).to eq("i-0000162a")
+ expect(plugin["openstack"]["instance_id"]).to eq("i-0000162a")
end
it "reads the local_ipv4 from the metadata service" do
- expect(plugin["openstack"]["metadata"]["local_ipv4"]).to eq("172.31.7.23")
+ expect(plugin["openstack"]["local_ipv4"]).to eq("172.31.7.23")
end
it "reads the ari_id from the metadata service" do
- expect(plugin["openstack"]["metadata"]["ari_id"]).to eq("ari-00000037")
+ expect(plugin["openstack"]["ari_id"]).to eq("ari-00000037")
end
it "reads the local_hostname from the metadata service" do
- expect(plugin["openstack"]["metadata"]["local_hostname"]).to eq("ohai-7-system-test.opscode.us")
+ expect(plugin["openstack"]["local_hostname"]).to eq("ohai-7-system-test.opscode.us")
end
it "reads the placement_availability_zone from the metadata service" do
- expect(plugin["openstack"]["metadata"]["placement_availability_zone"]).to eq("nova")
+ expect(plugin["openstack"]["placement_availability_zone"]).to eq("nova")
end
it "reads the ami_launch_index from the metadata service" do
- expect(plugin["openstack"]["metadata"]["ami_launch_index"]).to eq("0")
+ expect(plugin["openstack"]["ami_launch_index"]).to eq("0")
end
it "reads the public_hostname from the metadata service" do
- expect(plugin["openstack"]["metadata"]["public_hostname"]).to eq("ohai-7-system-test.opscode.us")
+ expect(plugin["openstack"]["public_hostname"]).to eq("ohai-7-system-test.opscode.us")
end
it "reads the hostname from the metadata service" do
- expect(plugin["openstack"]["metadata"]["hostname"]).to eq("ohai-7-system-test.opscode.us")
+ expect(plugin["openstack"]["hostname"]).to eq("ohai-7-system-test.opscode.us")
end
it "reads the ami_id from the metadata service" do
- expect(plugin["openstack"]["metadata"]["ami_id"]).to eq("ami-00000035")
+ expect(plugin["openstack"]["ami_id"]).to eq("ami-00000035")
end
it "reads the instance_action from the metadata service" do
- expect(plugin["openstack"]["metadata"]["instance_action"]).to eq("none")
+ expect(plugin["openstack"]["instance_action"]).to eq("none")
end
it "reads the aki_id from the metadata service" do
- expect(plugin["openstack"]["metadata"]["aki_id"]).to eq("aki-00000036")
+ expect(plugin["openstack"]["aki_id"]).to eq("aki-00000036")
end
it "reads the block_device_mapping_ami from the metadata service" do
- expect(plugin["openstack"]["metadata"]["block_device_mapping_ami"]).to eq("vda")
+ expect(plugin["openstack"]["block_device_mapping_ami"]).to eq("vda")
end
it "reads the block_device_mapping_root from the metadata service" do
- expect(plugin["openstack"]["metadata"]["block_device_mapping_root"]).to eq("/dev/vda")
+ expect(plugin["openstack"]["block_device_mapping_root"]).to eq("/dev/vda")
end
it "sets the provider to openstack" do
expect(plugin["openstack"]["provider"]).to eq("openstack")