Permalink
Browse files

supported the same cloud node keys as ohai's cloud plugin

  • Loading branch information...
1 parent 09713a3 commit 0eeeed07aaaee05f45f718d27c1a3f25b8cb0a0c @smessier smessier committed May 25, 2012
Showing with 41 additions and 7 deletions.
  1. +13 −3 lib/chef/plugins/cloud.rb
  2. +28 −4 spec/chef/plugins/cloud_spec.rb
@@ -30,6 +30,8 @@
begin
# create the default cloud using ohai for detection, if necessary.
cloud Mash.new
+ cloud[:public_ips] = Array.new
+ cloud[:private_ips] = Array.new
options = {:ohai_node => self}
# ensure metadata tree(s) are built using Mash.
@@ -64,11 +66,19 @@
named_cloud_node.update(cloud_instance.update_details)
# expecting public/private IPs to come from all clouds.
- cloud[:public_ips] = [ named_cloud_node[:"public-ipv4"] || named_cloud_node[:"public_ipv4"] || named_cloud_node[:public_ip] ]
- cloud[:private_ips] = [ named_cloud_node[:"local-ipv4"] || named_cloud_node[:"local_ipv4"] || named_cloud_node[:private_ip] ]
+ public_ip4 = named_cloud_node[:"public-ipv4"] || named_cloud_node[:public_ipv4] || named_cloud_node[:public_ip]
+ private_ip4 = named_cloud_node[:"local-ipv4"] || named_cloud_node[:local_ipv4] || named_cloud_node[:private_ip]
+
+ # support the various cloud node keys found in ohai's cloud plugin.
+ cloud[:public_ipv4] = public_ip4
+ cloud[:public_ips] << public_ip4
+ cloud[:local_ipv4] = private_ip4
+ cloud[:private_ips] << private_ip4
+ cloud[:public_hostname] = named_cloud_node['public_hostname']
+ cloud[:local_hostname] = named_cloud_node['local_hostname']
rescue Exception => e
# cloud was unresolvable, but not all ohai use cases are cloud instances.
- ::RightScale::Log.info(::RightScale::Log.format("Cloud was unresolvable", e, :trace))
+ ::RightScale::Log.info(::RightScale::Log.format("Cloud was unresolvable", e, :caller))
cloud nil
end
@@ -35,6 +35,8 @@
@expected_public_ip = "1.1.1.1"
@expected_private_ip = "10.252.252.10"
+ @expected_public_hostname = 'my_public_hostname'
+ @expected_local_hostname = 'my_local_hostname'
end
shared_examples_for 'generic cloud' do
@@ -64,12 +66,22 @@
end
it 'should populate cloud public ip' do
+ @ohai[:cloud][:public_ipv4].should == @expected_public_ip
@ohai[:cloud][:public_ips].first.should == @expected_public_ip
end
it 'should populate cloud private ip' do
+ @ohai[:cloud][:local_ipv4].should == @expected_private_ip
@ohai[:cloud][:private_ips].first.should == @expected_private_ip
end
+
+ it 'should populate cloud public hostname' do
+ @ohai[:cloud][:public_hostname].should == @expected_public_hostname
+ end
+
+ it 'should populate cloud local hostname' do
+ @ohai[:cloud][:local_hostname].should == @expected_local_hostname
+ end
end
end
@@ -92,7 +104,10 @@
context 'on EC2' do
before(:each) do
@expected_cloud = 'ec2'
- @metadata = {:"public-ipv4" => @expected_public_ip, :"local-ipv4" => @expected_private_ip}
+ @metadata = {:"public-ipv4" => @expected_public_ip,
+ :"local-ipv4" => @expected_private_ip,
+ 'public_hostname' => @expected_public_hostname,
+ 'local_hostname' => @expected_local_hostname}
@userdata = {}
@additionaldata = {}
end
@@ -105,7 +120,10 @@
@expected_cloud = "rackspace"
@metadata = ""
@userdata = ""
- @additionaldata = {:public_ip => @expected_public_ip, :private_ip => @expected_private_ip}
+ @additionaldata = {:public_ip => @expected_public_ip,
+ :private_ip => @expected_private_ip,
+ :public_hostname => @expected_public_hostname,
+ :local_hostname => @expected_local_hostname}
end
it_should_behave_like 'generic cloud'
@@ -114,7 +132,10 @@
context 'on Eucalyptus' do
before(:each) do
@expected_cloud = "eucalyptus"
- @metadata = {:"public-ipv4" => @expected_public_ip, :"local-ipv4" => @expected_private_ip}
+ @metadata = {:public_ipv4 => @expected_public_ip,
+ :local_ipv4 => @expected_private_ip,
+ 'public_hostname' => @expected_public_hostname,
+ 'local_hostname' => @expected_local_hostname}
@userdata = {}
@additionaldata = {}
end
@@ -125,7 +146,10 @@
context 'on cloudstack' do
before(:each) do
@expected_cloud = "cloudstack"
- @metadata = {:"public-ipv4" => @expected_public_ip, :"local-ipv4" => @expected_private_ip}
+ @metadata = {:"public-ipv4" => @expected_public_ip,
+ :"local-ipv4" => @expected_private_ip,
+ :public_hostname => @expected_public_hostname,
+ :local_hostname => @expected_local_hostname}
@userdata = {}
@additionaldata = {}
end

0 comments on commit 0eeeed0

Please sign in to comment.