diff options
author | Paul Rossman <paul@factory9.com> | 2013-08-19 18:11:36 -0500 |
---|---|---|
committer | adamedx <adamed@opscode.com> | 2013-10-10 10:45:10 -0700 |
commit | 7101ea3d3c7aef8ba57d9c9313c62c72211561ae (patch) | |
tree | 4e99c80bc520e54c92f6501cfc051ea056b945e9 | |
parent | ede12159bfbfbb85b943b786a0557a04c949c365 (diff) | |
download | ohai-7101ea3d3c7aef8ba57d9c9313c62c72211561ae.tar.gz |
new metadata server url
-rw-r--r-- | lib/ohai/mixin/gce_metadata.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/cloud.rb | 17 | ||||
-rw-r--r-- | spec/unit/plugins/gce_spec.rb | 35 |
3 files changed, 16 insertions, 38 deletions
diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb index 5188b381..109b25a6 100644 --- a/lib/ohai/mixin/gce_metadata.rb +++ b/lib/ohai/mixin/gce_metadata.rb @@ -24,7 +24,7 @@ module Ohai extend self GCE_METADATA_ADDR = "metadata.google.internal" unless defined?(GCE_METADATA_ADDR) - GCE_METADATA_URL = "/0.1/meta-data" unless defined?(GCE_METADATA_URL) + GCE_METADATA_URL = "/computeMetadata/v1beta1/?recursive=true" unless defined?(GCE_METADATA_URL) def can_metadata_connect?(addr, port, timeout=2) t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb index 9d0001af..77834bfc 100644 --- a/lib/ohai/plugins/cloud.rb +++ b/lib/ohai/plugins/cloud.rb @@ -35,20 +35,27 @@ end # Google Compute Engine (gce) #-------------------------------------- +# Is current cloud gce? +# +# === Return +# true:: If gce Hash is defined +# false:: Otherwise def on_gce? gce != nil end + +# Fill cloud hash with gce values def get_gce_values cloud[:public_ipv4] = [] cloud[:local_ipv4] = [] - public_ips = gce['network']["networkInterface"].collect do |interface| - if interface.has_key?('accessConfiguration') - interface['accessConfiguration'].collect{|ac| ac['externalIp']} + public_ips = gce['instance']["networkInterface"].collect do |interface| + if interface.has_key?('accessConfigs') + interface['accessConfigs'].collect{|ac| ac['externalIp']} end end.flatten.compact - private_ips = gce['network']["networkInterface"].collect do |interface| + private_ips = gce['instance']["networkInterface"].collect do |interface| interface['ip'] end.compact @@ -244,4 +251,4 @@ end if on_azure? create_objects get_azure_values -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/gce_spec.rb b/spec/unit/plugins/gce_spec.rb index 090d24ae..72699963 100644 --- a/spec/unit/plugins/gce_spec.rb +++ b/spec/unit/plugins/gce_spec.rb @@ -42,44 +42,15 @@ describe Ohai::System, "plugin gce" do Socket.stub!(:pack_sockaddr_in).and_return(nil) end - it "should recursively fetch metadata" do - @http_client.should_receive(:get). - with("/0.1/meta-data/"). - and_return(mock("Net::HTTPOK", - :body => "domain\nhostname\ndescription", :code=>"200")) - @http_client.should_receive(:get). - with("/0.1/meta-data/domain"). - and_return(mock("Net::HTTPOK", :body => "test-domain", :code=>"200")) - @http_client.should_receive(:get). - with("/0.1/meta-data/hostname"). - and_return(mock("Net::HTTPOK", :body => "test-host", :code=>"200")) - @http_client.should_receive(:get). - with("/0.1/meta-data/description"). - and_return(mock("Net::HTTPOK", :body => "test-description", :code=>"200")) - - @ohai._require_plugin("gce") - - @ohai[:gce].should_not be_nil - @ohai[:gce]['hostname'].should == "test-host" - @ohai[:gce]['domain'].should == "test-domain" - @ohai[:gce]['description'].should == "test-description" - end - it "should properly parse json metadata" do @http_client.should_receive(:get). - with("/0.1/meta-data/"). - and_return(mock("Net::HTTP Response", :body => "attached-disks\n", :code=>"200")) - @http_client.should_receive(:get). - with("/0.1/meta-data/attached-disks"). - and_return(mock("Net::HTTP Response", :body => '{"disks":[{"deviceName":"boot", - "index":0,"mode":"READ_WRITE","type":"EPHEMERAL"}]}', :code=>"200")) + with("/computeMetadata/v1beta1/?recursive=true/"). + and_return(double("Net::HTTP Response", :body => '{"instance":{"hostname":"test-host"}}', :code=>"200")) @ohai._require_plugin("gce") @ohai[:gce].should_not be_nil - @ohai[:gce]['attached_disks'].should eq({"disks"=>[{"deviceName"=>"boot", - "index"=>0,"mode"=>"READ_WRITE", - "type"=>"EPHEMERAL"}]}) + @ohai[:gce]['instance'].should eq("hostname"=>"test-host") end end |