summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Karpik <alexey.karpik@rightscale.com>2014-12-09 10:47:12 +0300
committerBryan McLellan <btm@opscode.com>2015-02-17 12:45:13 -0500
commit8eaf8f492e021dbadc848db8441c658ca06528a1 (patch)
tree246bbca82814712b86c729632e6eee7356d3e893
parent97dab698de6e000365b40b3732fbe7f8c571b27a (diff)
downloadohai-8eaf8f492e021dbadc848db8441c658ca06528a1.tar.gz
Fix up incorrect cloudstack metadata
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/ohai/plugins/cloud.rb26
-rw-r--r--lib/ohai/plugins/cloudstack.rb7
-rw-r--r--spec/unit/plugins/cloud_spec.rb18
-rw-r--r--spec/unit/plugins/cloudstack_spec.rb2
5 files changed, 39 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6bda4f0..3afe30dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,8 @@
Fix network.rb for XenServer Creedence
* [**Shuo Zhang**](https://github.com/zshuo)
Update linux plugin cpu.rb and spec_cpu.rb to support S390
+* [**Alexey Karpik**](https://github.com/akarpik)
+ Fix up incorrect cloudstack metadata:
* Update mime-types dependency
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index c7cdfbf3..8145cc0a 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -230,16 +230,30 @@ Ohai.plugin(:Cloud) do
cloudstack != nil
end
- # Fill cloud hash with cloudstack values
+ # Fill cloud hash with cloudstack values. Cloudstack is a bit different in that
+ # the local interface can be a public or private ip is using basic networking.
+ # When using advanced networking, the public_ipv4 passed in the metadata isn't
+ # usually going to be the public ip of the interface, so don't use that value. As
+ # per the Cloudstack documentation its actually the NAT router IP.
def get_cloudstack_values
- cloud[:public_ips] << cloudstack['public_ipv4']
- cloud[:private_ips] << cloudstack['local_ipv4']
- cloud[:public_ipv4] = cloudstack['public_ipv4']
- cloud[:public_hostname] = cloudstack['public_hostname']
cloud[:local_ipv4] = cloudstack['local_ipv4']
+
+ if cloudstack['local_ipv4']
+ # Private IPv4 address
+ if cloudstack['local_ipv4'] =~ /\A(10\.|192\.168\.|172\.1[6789]\.|172\.2.\.|172\.3[01]\.)/
+ cloud[:private_ips] << cloudstack['local_ipv4']
+ cloud[:public_ipv4] = nil
+ else
+ cloud[:public_ips] << cloudstack['local_ipv4']
+ # Yes, not a mistake, for basic networking this may be true
+ cloud[:public_ipv4] = cloudstack['local_ipv4']
+ end
+ end
+ cloud[:public_hostname] = cloudstack['public_hostname']
cloud[:local_hostname] = cloudstack['local_hostname']
cloud[:vm_id] = cloudstack['vm_id']
- cloud[:provider] = "cloudstack"
+ cloud[:local_hostname] = cloudstack['local_hostname']
+ cloud[:provider] = 'cloudstack'
end
# ----------------------------------------
diff --git a/lib/ohai/plugins/cloudstack.rb b/lib/ohai/plugins/cloudstack.rb
index cecd36c8..1f460538 100644
--- a/lib/ohai/plugins/cloudstack.rb
+++ b/lib/ohai/plugins/cloudstack.rb
@@ -1,5 +1,7 @@
#
+# Author:: Peter Schroeter <peter.schroeter@rightscale.com>
# Author:: Olle Lundberg (<geek@nerd.sh>)
+# Copyright:: Copyright (c) 2010-2014 RightScale Inc
# Copyright:: Copyright (c) 2014 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -31,6 +33,11 @@ Ohai.plugin(:Cloudstack) do
cloudstack Mash.new
Ohai::Log.debug("connecting to the 'cloudstack' metadata service")
fetch_metadata.each { |k, v| cloudstack[k] = v }
+ # Note: the cloudstack public_ipv4 is the value of the NAT router (as per cloudstack documentation)
+ # and not necessarily the publicly available IP. cloustack semi-supports floating
+ # ips in that the public ip for an instance can be an IP different from the NAT router
+ cloudstack['router_ipv4'] = cloudstack.delete('public_ipv4')
+ cloudstack['dhcp_lease_provider_ip'] = dhcp_ip
else
Ohai::Log.debug("unable to connect to the 'cloudstack' metadata service")
end
diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb
index 31a9332b..0c7ac434 100644
--- a/spec/unit/plugins/cloud_spec.rb
+++ b/spec/unit/plugins/cloud_spec.rb
@@ -62,38 +62,38 @@ describe Ohai::System, "plugin cloud" do
describe "with rackspace" do
before do
@plugin[:rackspace] = Mash.new()
- end
-
+ end
+
it "populates cloud public ip" do
@plugin[:rackspace][:public_ipv4] = "174.129.150.8"
@plugin.run
expect(@plugin[:cloud][:public_ipv4]).to eq(@plugin[:rackspace][:public_ipv4])
end
-
+
it "populates cloud public ipv6" do
@plugin[:rackspace][:public_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
@plugin.run
expect(@plugin[:cloud][:public_ipv6]).to eq(@plugin[:rackspace][:public_ipv6])
end
-
+
it "populates cloud private ip" do
@plugin[:rackspace][:local_ipv4] = "10.252.42.149"
@plugin.run
expect(@plugin[:cloud][:local_ipv4]).to eq(@plugin[:rackspace][:local_ipv4])
end
-
+
it "populates cloud private ipv6" do
@plugin[:rackspace][:local_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
@plugin.run
expect(@plugin[:cloud][:local_ipv6]).to eq(@plugin[:rackspace][:local_ipv6])
end
-
+
it "populates first cloud public ip" do
@plugin[:rackspace][:public_ipv4] = "174.129.150.8"
@plugin.run
expect(@plugin[:cloud][:public_ips].first).to eq(@plugin[:rackspace][:public_ipv4])
end
-
+
it "populates first cloud public ip" do
@plugin[:rackspace][:local_ipv4] = "174.129.150.8"
@plugin.run
@@ -213,9 +213,9 @@ describe Ohai::System, "plugin cloud" do
end
it "populates cloud public ip" do
- @plugin[:cloudstack]['public_ipv4'] = "174.129.150.8"
+ @plugin[:cloudstack]['local_ipv4'] = "174.129.150.8"
@plugin.run
- expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:cloudstack]['public_ipv4'])
+ expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:cloudstack]['local_ipv4'])
end
it "populates cloud private ip" do
diff --git a/spec/unit/plugins/cloudstack_spec.rb b/spec/unit/plugins/cloudstack_spec.rb
index d2ae76dd..04d65a22 100644
--- a/spec/unit/plugins/cloudstack_spec.rb
+++ b/spec/unit/plugins/cloudstack_spec.rb
@@ -138,7 +138,7 @@ EOM
expect(ohai_data['cloudstack']['service_offering']).to eq("2vCPU, 1GHz, 2GB RAM")
end
it "reads the public ipv4 from the metadata service" do
- expect(ohai_data['cloudstack']['public_ipv4']).to eq("10.235.34.23")
+ expect(ohai_data['cloudstack']['router_ipv4']).to eq("10.235.34.23")
end
it "reads the vm id from the metadata service" do
expect(ohai_data['cloudstack']['vm_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")