summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Edwards <adamed@opscode.com>2013-06-21 21:02:12 -0700
committerAdam Edwards <adamed@opscode.com>2013-06-21 21:02:12 -0700
commit21b05a071399b5aa72805529cd949777f6cb91e2 (patch)
tree39f7bfe9addbf4db3887455e0022dddcd2a8022b
parent7247abbb00dfccaf29ec50712852882d6b347557 (diff)
parentddc2c9bdb44c1fc2c1d93c347cd7a25dcc0142f7 (diff)
downloadohai-21b05a071399b5aa72805529cd949777f6cb91e2.tar.gz
Merge pull request #151 from opscode/adamed-OC-5329-azure
OHAI-419: OC-5329: Azure public ip address unavailable for knife ssh
-rw-r--r--lib/ohai/plugins/azure.rb13
-rw-r--r--lib/ohai/plugins/cloud.rb30
-rw-r--r--spec/unit/plugins/azure_spec.rb73
-rw-r--r--spec/unit/plugins/cloud_spec.rb48
4 files changed, 164 insertions, 0 deletions
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
new file mode 100644
index 00000000..d13a388f
--- /dev/null
+++ b/lib/ohai/plugins/azure.rb
@@ -0,0 +1,13 @@
+
+provides "azure"
+
+
+azure_metadata_from_hints = hint?('azure')
+if azure_metadata_from_hints
+ Ohai::Log.debug("azure_metadata_from_hints is present.")
+ azure Mash.new
+ azure_metadata_from_hints.each {|k, v| azure[k] = v }
+else
+ Ohai::Log.debug("No hints present for azure.")
+ false
+end \ No newline at end of file
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index 68852d04..9d0001af 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -22,6 +22,7 @@ require_plugin "rackspace"
require_plugin "eucalyptus"
require_plugin "linode"
require_plugin "openstack"
+require_plugin "azure"
# Make top-level cloud hashes
#
@@ -215,3 +216,32 @@ if on_openstack?
create_objects
get_openstack_values
end
+
+# ----------------------------------------
+# azure
+# ----------------------------------------
+
+# Is current cloud azure?
+#
+# === Return
+# true:: If azure Hash is defined
+# false:: Otherwise
+def on_azure?
+ azure != nil
+end
+
+# Fill cloud hash with azure values
+def get_azure_values
+ cloud[:vm_name] = azure["vm_name"]
+ cloud[:public_ips] << azure['public_ip']
+ cloud[:public_fqdn] = azure['public_fqdn']
+ cloud[:public_ssh_port] = azure['public_ssh_port'] if azure['public_ssh_port']
+ cloud[:public_winrm_port] = azure['public_winrm_port'] if azure['public_winrm_port']
+ cloud[:provider] = "azure"
+end
+
+# setup azure cloud data
+if on_azure?
+ create_objects
+ get_azure_values
+end \ No newline at end of file
diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb
new file mode 100644
index 00000000..31879546
--- /dev/null
+++ b/spec/unit/plugins/azure_spec.rb
@@ -0,0 +1,73 @@
+#
+# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
+# Copyright:: Copyright (c) 2011-2013 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'open-uri'
+
+describe Ohai::System, "plugin azure" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ end
+
+ describe "with azure cloud file" do
+ before(:each) do
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/azure.json').and_return('{"public_ip":"137.135.46.202","vm_name":"test-vm","public_fqdn":"service.cloudapp.net","public_ssh_port":"22", "public_winrm_port":"5985"}')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/azure.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/azure.json').and_return('{"public_ip":"137.135.46.202","vm_name":"test-vm","public_fqdn":"service.cloudapp.net","public_ssh_port":"22", "public_winrm_port":"5985"}')
+ @ohai._require_plugin("azure")
+ end
+
+ it 'should set the azure cloud attributes' do
+ @ohai[:azure].should_not be_nil
+ @ohai[:azure]['public_ip'].should == "137.135.46.202"
+ @ohai[:azure]['vm_name'].should == "test-vm"
+ @ohai[:azure]['public_fqdn'].should == "service.cloudapp.net"
+ @ohai[:azure]['public_ssh_port'].should == "22"
+ @ohai[:azure]['public_winrm_port'].should == "5985"
+ end
+
+ end
+
+ describe "without azure cloud file" do
+ before(:each) do
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(false)
+ File.stub!(:exist?).with('C:\chef\ohai\hints/azure.json').and_return(false)
+ end
+
+ it 'should not behave like azure' do
+ @ohai[:azure].should be_nil
+ end
+ end
+
+ describe "with rackspace cloud file" do
+ before(:each) do
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
+ end
+
+ it 'should not behave like azure' do
+ @ohai[:azure].should be_nil
+ end
+ end
+
+end
diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb
index 599935bb..00e0c179 100644
--- a/spec/unit/plugins/cloud_spec.rb
+++ b/spec/unit/plugins/cloud_spec.rb
@@ -29,6 +29,7 @@ describe Ohai::System, "plugin cloud" do
@ohai[:rackspace] = nil
@ohai[:eucalyptus] = nil
@ohai[:linode] = nil
+ @ohai[:azure] = nil
@ohai._require_plugin("cloud")
@ohai[:cloud].should be_nil
end
@@ -156,4 +157,51 @@ describe Ohai::System, "plugin cloud" do
end
end
+ describe "with Azure mash" do
+ before do
+ @ohai[:azure] = Mash.new()
+ end
+
+ it "populates cloud public ip" do
+ @ohai[:azure]['public_ip'] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips][0].should == @ohai[:azure]['public_ip']
+ end
+
+ it "populates cloud vm_name" do
+ @ohai[:azure]['vm_name'] = "linux-vm"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:vm_name].should == @ohai[:azure]['vm_name']
+ end
+
+ it "populates cloud public_fqdn" do
+ @ohai[:azure]['public_fqdn'] = "linux-vm-svc.cloudapp.net"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_fqdn].should == @ohai[:azure]['public_fqdn']
+ end
+
+ it "populates cloud public_ssh_port" do
+ @ohai[:azure]['public_ssh_port'] = "22"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ssh_port].should == @ohai[:azure]['public_ssh_port']
+ end
+
+ it "should not populate cloud public_ssh_port when winrm is used" do
+ @ohai[:azure]['public_winrm_port'] = "5985"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ssh_port].should be_nil
+ end
+
+ it "populates cloud public_winrm_port" do
+ @ohai[:azure]['public_winrm_port'] = "5985"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_winrm_port].should == @ohai[:azure]['public_winrm_port']
+ end
+
+ it "populates cloud provider" do
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:provider].should == "azure"
+ end
+ end
+
end