ohai 8.1.1 → 8.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/ohai/plugins/cloud.rb +0 -46
- data/lib/ohai/plugins/perl.rb +1 -3
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/plugins/cloud_spec.rb +0 -31
- metadata +10 -22
- data/lib/ohai/mixin/cloudstack_metadata.rb +0 -88
- data/lib/ohai/plugins/cloudstack.rb +0 -50
- data/spec/unit/mixin/cloudstack_metadata_spec.rb +0 -33
- data/spec/unit/plugins/cloudstack_spec.rb +0 -155
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4fdcd52a082fc45f9b8290c5f9a0b235ad4ee8f
|
4
|
+
data.tar.gz: bdf90d6b5e6c9fd85d9ad4c441cf90e5d30fc3af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf65d4334c84ae6d7f0fc28348370763d9f7b2f25cc5ca95fb9dfab6bca028c66f3be0884235ce6ea14b2b696494b150ac285af8e84358ebf652c41e8224fb08
|
7
|
+
data.tar.gz: f1d9cb9f4d98062ef81d1087fb02d6a261762d096ca5cdae6d643e5817019e1148614873d8bdd564e356ec520460116c6990e426619dbbab826b2bb99f0ac43d
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# ohai
|
2
|
+
[![Build Status Master](https://travis-ci.org/chef/ohai.svg?branch=master)](https://travis-ci.org/chef/ohai)
|
3
|
+
[![Build Status Master](https://ci.appveyor.com/api/projects/status/github/chef/ohai?branch=master&svg=true&passingText=master%20-%20Ok&pendingText=master%20-%20Pending&failingText=master%20-%20Failing)](https://ci.appveyor.com/project/Chef/ohai/branch/master)
|
4
|
+
|
2
5
|
|
3
6
|
# DESCRIPTION:
|
4
7
|
|
@@ -57,7 +60,7 @@ Ohai has some Rake tasks for doing various things.
|
|
57
60
|
rake package # Build all the packages
|
58
61
|
rake repackage # Force a rebuild of the package files
|
59
62
|
rake spec # Run specs
|
60
|
-
|
63
|
+
|
61
64
|
($VERSION is the current version, from the GemSpec in Rakefile)
|
62
65
|
|
63
66
|
# LINKS:
|
data/lib/ohai/plugins/cloud.rb
CHANGED
@@ -24,7 +24,6 @@ Ohai.plugin(:Cloud) do
|
|
24
24
|
depends "linode"
|
25
25
|
depends "openstack"
|
26
26
|
depends "azure"
|
27
|
-
depends "cloudstack"
|
28
27
|
depends "digital_ocean"
|
29
28
|
|
30
29
|
# Make top-level cloud hashes
|
@@ -217,45 +216,6 @@ Ohai.plugin(:Cloud) do
|
|
217
216
|
cloud[:provider] = "azure"
|
218
217
|
end
|
219
218
|
|
220
|
-
# ----------------------------------------
|
221
|
-
# cloudstack
|
222
|
-
# ----------------------------------------
|
223
|
-
|
224
|
-
# Is current cloud cloudstack-based?
|
225
|
-
#
|
226
|
-
# === Return
|
227
|
-
# true:: If cloudstack Hash is defined
|
228
|
-
# false:: Otherwise
|
229
|
-
def on_cloudstack?
|
230
|
-
cloudstack != nil
|
231
|
-
end
|
232
|
-
|
233
|
-
# Fill cloud hash with cloudstack values. Cloudstack is a bit different in that
|
234
|
-
# the local interface can be a public or private ip is using basic networking.
|
235
|
-
# When using advanced networking, the public_ipv4 passed in the metadata isn't
|
236
|
-
# usually going to be the public ip of the interface, so don't use that value. As
|
237
|
-
# per the Cloudstack documentation its actually the NAT router IP.
|
238
|
-
def get_cloudstack_values
|
239
|
-
cloud[:local_ipv4] = cloudstack['local_ipv4']
|
240
|
-
|
241
|
-
if cloudstack['local_ipv4']
|
242
|
-
# Private IPv4 address
|
243
|
-
if cloudstack['local_ipv4'] =~ /\A(10\.|192\.168\.|172\.1[6789]\.|172\.2.\.|172\.3[01]\.)/
|
244
|
-
cloud[:private_ips] << cloudstack['local_ipv4']
|
245
|
-
cloud[:public_ipv4] = nil
|
246
|
-
else
|
247
|
-
cloud[:public_ips] << cloudstack['local_ipv4']
|
248
|
-
# Yes, not a mistake, for basic networking this may be true
|
249
|
-
cloud[:public_ipv4] = cloudstack['local_ipv4']
|
250
|
-
end
|
251
|
-
end
|
252
|
-
cloud[:public_hostname] = cloudstack['public_hostname']
|
253
|
-
cloud[:local_hostname] = cloudstack['local_hostname']
|
254
|
-
cloud[:vm_id] = cloudstack['vm_id']
|
255
|
-
cloud[:local_hostname] = cloudstack['local_hostname']
|
256
|
-
cloud[:provider] = 'cloudstack'
|
257
|
-
end
|
258
|
-
|
259
219
|
# ----------------------------------------
|
260
220
|
# digital_ocean
|
261
221
|
# ----------------------------------------
|
@@ -327,12 +287,6 @@ Ohai.plugin(:Cloud) do
|
|
327
287
|
get_azure_values
|
328
288
|
end
|
329
289
|
|
330
|
-
# setup cloudstack cloud
|
331
|
-
if on_cloudstack?
|
332
|
-
create_objects
|
333
|
-
get_cloudstack_values
|
334
|
-
end
|
335
|
-
|
336
290
|
# setup digital_ocean cloud data
|
337
291
|
if on_digital_ocean?
|
338
292
|
create_objects
|
data/lib/ohai/plugins/perl.rb
CHANGED
data/lib/ohai/version.rb
CHANGED
@@ -29,7 +29,6 @@ describe Ohai::System, "plugin cloud" do
|
|
29
29
|
@plugin[:eucalyptus] = nil
|
30
30
|
@plugin[:linode] = nil
|
31
31
|
@plugin[:azure] = nil
|
32
|
-
@plugin[:cloudstack] = nil
|
33
32
|
@plugin[:digital_ocean] = nil
|
34
33
|
@plugin.run
|
35
34
|
expect(@plugin[:cloud]).to be_nil
|
@@ -207,35 +206,6 @@ describe Ohai::System, "plugin cloud" do
|
|
207
206
|
end
|
208
207
|
end
|
209
208
|
|
210
|
-
describe "with cloudstack mash" do
|
211
|
-
before do
|
212
|
-
@plugin[:cloudstack] = Mash.new()
|
213
|
-
end
|
214
|
-
|
215
|
-
it "populates cloud public ip" do
|
216
|
-
@plugin[:cloudstack]['local_ipv4'] = "174.129.150.8"
|
217
|
-
@plugin.run
|
218
|
-
expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:cloudstack]['local_ipv4'])
|
219
|
-
end
|
220
|
-
|
221
|
-
it "populates cloud private ip" do
|
222
|
-
@plugin[:cloudstack]['local_ipv4'] = "10.252.42.149"
|
223
|
-
@plugin.run
|
224
|
-
expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:cloudstack]['local_ipv4'])
|
225
|
-
end
|
226
|
-
|
227
|
-
it "populates cloud provider" do
|
228
|
-
@plugin.run
|
229
|
-
expect(@plugin[:cloud][:provider]).to eq("cloudstack")
|
230
|
-
end
|
231
|
-
|
232
|
-
it "populates vm id" do
|
233
|
-
@plugin[:cloudstack]['vm_id'] = "8983fb85-fb7f-46d6-8af1-c1b6666fec39"
|
234
|
-
@plugin.run
|
235
|
-
expect(@plugin[:cloud][:vm_id]).to eq(@plugin[:cloudstack]['vm_id'])
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
209
|
describe "with digital_ocean mash" do
|
240
210
|
before do
|
241
211
|
@plugin[:digital_ocean] = Mash.new
|
@@ -289,5 +259,4 @@ describe Ohai::System, "plugin cloud" do
|
|
289
259
|
expect(@plugin[:cloud][:provider]).to eq("digital_ocean")
|
290
260
|
end
|
291
261
|
end
|
292
|
-
|
293
262
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|
@@ -42,16 +42,22 @@ dependencies:
|
|
42
42
|
name: ffi-yajl
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.1'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '3.0'
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- - "
|
55
|
+
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: '1.1'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: mixlib-cli
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +114,6 @@ dependencies:
|
|
108
114
|
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
116
|
version: '2.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: net-dhcp
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
117
|
- !ruby/object:Gem::Dependency
|
126
118
|
name: ipaddress
|
127
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,7 +265,6 @@ files:
|
|
273
265
|
- lib/ohai/loader.rb
|
274
266
|
- lib/ohai/log.rb
|
275
267
|
- lib/ohai/mash.rb
|
276
|
-
- lib/ohai/mixin/cloudstack_metadata.rb
|
277
268
|
- lib/ohai/mixin/command.rb
|
278
269
|
- lib/ohai/mixin/constant_helper.rb
|
279
270
|
- lib/ohai/mixin/ec2_metadata.rb
|
@@ -295,7 +286,6 @@ files:
|
|
295
286
|
- lib/ohai/plugins/chef.rb
|
296
287
|
- lib/ohai/plugins/cloud.rb
|
297
288
|
- lib/ohai/plugins/cloud_v2.rb
|
298
|
-
- lib/ohai/plugins/cloudstack.rb
|
299
289
|
- lib/ohai/plugins/command.rb
|
300
290
|
- lib/ohai/plugins/darwin/cpu.rb
|
301
291
|
- lib/ohai/plugins/darwin/filesystem.rb
|
@@ -430,7 +420,6 @@ files:
|
|
430
420
|
- spec/unit/dsl/plugin_spec.rb
|
431
421
|
- spec/unit/hints_spec.rb
|
432
422
|
- spec/unit/loader_spec.rb
|
433
|
-
- spec/unit/mixin/cloudstack_metadata_spec.rb
|
434
423
|
- spec/unit/mixin/command_spec.rb
|
435
424
|
- spec/unit/mixin/ec2_metadata_spec.rb
|
436
425
|
- spec/unit/plugins/aix/cpu_spec.rb
|
@@ -446,7 +435,6 @@ files:
|
|
446
435
|
- spec/unit/plugins/chef_spec.rb
|
447
436
|
- spec/unit/plugins/cloud_spec.rb
|
448
437
|
- spec/unit/plugins/cloud_v2_spec.rb
|
449
|
-
- spec/unit/plugins/cloudstack_spec.rb
|
450
438
|
- spec/unit/plugins/darwin/cpu_spec.rb
|
451
439
|
- spec/unit/plugins/darwin/hostname_spec.rb
|
452
440
|
- spec/unit/plugins/darwin/kernel_spec.rb
|
@@ -1,88 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Olle Lundberg (<geek@nerd.sh>)
|
3
|
-
# Copyright:: Copyright (c) 2014 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
require 'ohai/mixin/ec2_metadata'
|
19
|
-
require 'ohai/hints'
|
20
|
-
require 'net/dhcp'
|
21
|
-
require 'socket'
|
22
|
-
|
23
|
-
|
24
|
-
module Ohai
|
25
|
-
module Mixin
|
26
|
-
module CloudstackMetadata
|
27
|
-
include Ohai::Mixin::Ec2Metadata
|
28
|
-
|
29
|
-
def self.discover_dhcp_server
|
30
|
-
response = ''
|
31
|
-
if Ohai::Hints.hint?('cloudstack')
|
32
|
-
begin
|
33
|
-
request = DHCP::Discover.new
|
34
|
-
|
35
|
-
listensock = UDPSocket.new
|
36
|
-
sendsock = UDPSocket.new
|
37
|
-
|
38
|
-
listensock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
|
39
|
-
sendsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
|
40
|
-
|
41
|
-
sendsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
42
|
-
sendaddr = "<broadcast>"
|
43
|
-
listenport = 68
|
44
|
-
|
45
|
-
listensock.bind('', listenport)
|
46
|
-
sendsock.connect(sendaddr, 67)
|
47
|
-
|
48
|
-
sendsock.send(request.pack, 0)
|
49
|
-
|
50
|
-
data = listensock.recvfrom_nonblock(1500)
|
51
|
-
rescue Exception => e
|
52
|
-
if (defined?(IO::WaitReadable) && e.instance_of?(IO::WaitReadable)) ||
|
53
|
-
(e.instance_of?(Errno::EAGAIN) || e.instance_of?(Errno::EWOULDBLOCK)) # This OR branch can be removed when ruby > 1.8.7
|
54
|
-
unless IO.select([listensock], nil, nil, 10)
|
55
|
-
# timeout reached
|
56
|
-
Ohai::Log.debug("Timeout reached awaiting response from DHCP server")
|
57
|
-
else
|
58
|
-
# try to read from the socket again
|
59
|
-
data = listensock.recvfrom_nonblock(1500)
|
60
|
-
end
|
61
|
-
else
|
62
|
-
Ohai::Log.debug("Exceptions encountered when trying to connect to dhcp server. #{e.message}")
|
63
|
-
end
|
64
|
-
ensure
|
65
|
-
sendsock.close
|
66
|
-
listensock.close
|
67
|
-
if data
|
68
|
-
response = [DHCP::Message.from_udp_payload(data[0]).siaddr].pack('N').unpack('C4').join('.')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
response
|
73
|
-
end
|
74
|
-
|
75
|
-
CLOUDSTACK_METADATA_ADDR = self.discover_dhcp_server unless defined?(CLOUDSTACK_METADATA_ADDR)
|
76
|
-
|
77
|
-
def http_client
|
78
|
-
Net::HTTP.start(CLOUDSTACK_METADATA_ADDR).tap { |h| h.read_timeout = 600 }
|
79
|
-
end
|
80
|
-
|
81
|
-
def best_api_version
|
82
|
-
'latest'
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Peter Schroeter <peter.schroeter@rightscale.com>
|
3
|
-
# Author:: Olle Lundberg (<geek@nerd.sh>)
|
4
|
-
# Copyright:: Copyright (c) 2010-2014 RightScale Inc
|
5
|
-
# Copyright:: Copyright (c) 2014 Opscode, Inc.
|
6
|
-
# License:: Apache License, Version 2.0
|
7
|
-
#
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
-
# you may not use this file except in compliance with the License.
|
10
|
-
# You may obtain a copy of the License at
|
11
|
-
#
|
12
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
-
#
|
14
|
-
# Unless required by applicable law or agreed to in writing, software
|
15
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
-
# See the License for the specific language governing permissions and
|
18
|
-
# limitations under the License.
|
19
|
-
|
20
|
-
require 'ohai/mixin/cloudstack_metadata'
|
21
|
-
|
22
|
-
Ohai.plugin(:Cloudstack) do
|
23
|
-
provides "cloudstack"
|
24
|
-
|
25
|
-
include Ohai::Mixin::CloudstackMetadata
|
26
|
-
|
27
|
-
collect_data do
|
28
|
-
# Adds cloudstack Mash
|
29
|
-
if hint?('cloudstack')
|
30
|
-
Ohai::Log.debug("found 'cloudstack' hint. Will try to connect to the metadata server")
|
31
|
-
|
32
|
-
if can_metadata_connect?(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR, 80)
|
33
|
-
cloudstack Mash.new
|
34
|
-
Ohai::Log.debug("connecting to the 'cloudstack' metadata service")
|
35
|
-
fetch_metadata.each { |k, v| cloudstack[k] = v }
|
36
|
-
# Note: the cloudstack public_ipv4 is the value of the NAT router (as per cloudstack documentation)
|
37
|
-
# and not necessarily the publicly available IP. cloustack semi-supports floating
|
38
|
-
# ips in that the public ip for an instance can be an IP different from the NAT router
|
39
|
-
cloudstack['router_ipv4'] = cloudstack.delete('public_ipv4')
|
40
|
-
cloudstack['dhcp_lease_provider_ip'] = dhcp_ip
|
41
|
-
else
|
42
|
-
Ohai::Log.debug("unable to connect to the 'cloudstack' metadata service")
|
43
|
-
end
|
44
|
-
else
|
45
|
-
Ohai::Log.debug("unable to find 'cloudstack' hint. Won't connect to the metadata server.")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Olle Lundberg (<geek@nerd.sh>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
|
20
|
-
require 'ohai/mixin/cloudstack_metadata'
|
21
|
-
|
22
|
-
describe Ohai::Mixin::CloudstackMetadata do
|
23
|
-
let(:mixin) {
|
24
|
-
metadata_object = Object.new.extend(Ohai::Mixin::CloudstackMetadata)
|
25
|
-
metadata_object
|
26
|
-
}
|
27
|
-
|
28
|
-
context "#best_api_version" do
|
29
|
-
it "returns the string latest" do
|
30
|
-
expect(mixin.best_api_version).to eq("latest")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Olle Lundberg (<geek@nerd.sh>)
|
3
|
-
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'spec_helper'
|
20
|
-
require 'ohai/plugins/cloudstack'
|
21
|
-
|
22
|
-
describe "Cloudstack Plugin" do
|
23
|
-
|
24
|
-
let(:cloudstack_hint) { false }
|
25
|
-
|
26
|
-
let(:ohai_system) { Ohai::System.new }
|
27
|
-
let(:ohai_data) { ohai_system.data }
|
28
|
-
|
29
|
-
let(:cloudstack_plugin) do
|
30
|
-
plugin = get_plugin("cloudstack", ohai_system)
|
31
|
-
allow(plugin).to receive(:hint?).with("cloudstack").and_return(cloudstack_hint)
|
32
|
-
plugin
|
33
|
-
end
|
34
|
-
|
35
|
-
before do
|
36
|
-
stub_const("Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR", '10.10.10.10')
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when there is no relevant hint" do
|
40
|
-
|
41
|
-
it "does not set any cloudstack data" do
|
42
|
-
cloudstack_plugin.run
|
43
|
-
expect(ohai_data).to_not have_key("cloudstack")
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when there is a `cloudstack` hint" do
|
49
|
-
let(:cloudstack_hint) { true }
|
50
|
-
|
51
|
-
context "and the metadata service is not available" do
|
52
|
-
|
53
|
-
before do
|
54
|
-
expect(cloudstack_plugin).to receive(:can_metadata_connect?).
|
55
|
-
with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR,80).
|
56
|
-
and_return(false)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "does not set any cloudstack data" do
|
60
|
-
cloudstack_plugin.run
|
61
|
-
expect(ohai_data).to_not have_key("cloudstack")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "and the metadata service is available" do
|
66
|
-
|
67
|
-
let(:metadata_version) { "latest" }
|
68
|
-
|
69
|
-
let(:metadata_root) do
|
70
|
-
<<EOM
|
71
|
-
availability-zone
|
72
|
-
cloud-identifier
|
73
|
-
instance-id
|
74
|
-
local-hostname
|
75
|
-
local-ipv4
|
76
|
-
public-hostname
|
77
|
-
public-ipv4
|
78
|
-
service-offering
|
79
|
-
vm-id
|
80
|
-
EOM
|
81
|
-
end
|
82
|
-
|
83
|
-
let(:metadata_values) do
|
84
|
-
{
|
85
|
-
"local-ipv4" =>"10.235.34.23",
|
86
|
-
"local-hostname" =>"VM-8983fb85-fb7f-46d6-8af1-c1b6666fec39",
|
87
|
-
"public-hostname" =>"awesome-doge",
|
88
|
-
"availability-zone" =>"TCS7",
|
89
|
-
"service-offering" =>"2vCPU, 1GHz, 2GB RAM",
|
90
|
-
"public-ipv4" =>"10.235.34.23",
|
91
|
-
"vm-id"=>"8983fb85-fb7f-46d6-8af1-c1b6666fec39",
|
92
|
-
"cloud-identifier"=>"CloudStack-{e84ff39d-ef64-4812-a8a9-7932f7b67f17}",
|
93
|
-
"instance-id"=>"8983fb85-fb7f-46d6-8af1-c1b6666fec39"
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
let(:http_client) { double("Net::HTTP", :read_timeout= => nil) }
|
98
|
-
|
99
|
-
def expect_get(url, response_body)
|
100
|
-
expect(http_client).to receive(:get).
|
101
|
-
with(url).
|
102
|
-
and_return(double("HTTP Response", :code => "200", :body => response_body))
|
103
|
-
end
|
104
|
-
|
105
|
-
before do
|
106
|
-
expect(cloudstack_plugin).to receive(:can_metadata_connect?).
|
107
|
-
with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR,80).
|
108
|
-
and_return(true)
|
109
|
-
|
110
|
-
allow(Net::HTTP).to receive(:start).
|
111
|
-
with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR).
|
112
|
-
and_return(http_client)
|
113
|
-
|
114
|
-
allow(cloudstack_plugin).to receive(:best_api_version).and_return(metadata_version)
|
115
|
-
|
116
|
-
expect_get("/#{metadata_version}/meta-data/", metadata_root)
|
117
|
-
|
118
|
-
metadata_values.each do |md_id, md_value|
|
119
|
-
expect_get("/#{metadata_version}/meta-data/#{md_id}", md_value)
|
120
|
-
end
|
121
|
-
|
122
|
-
cloudstack_plugin.run
|
123
|
-
end
|
124
|
-
|
125
|
-
it "reads the local ipv4 from the metadata service" do
|
126
|
-
expect(ohai_data['cloudstack']['local_ipv4']).to eq("10.235.34.23")
|
127
|
-
end
|
128
|
-
it "reads the local hostname from the metadata service" do
|
129
|
-
expect(ohai_data['cloudstack']['local_hostname']).to eq("VM-8983fb85-fb7f-46d6-8af1-c1b6666fec39")
|
130
|
-
end
|
131
|
-
it "reads the public hostname from the metadata service" do
|
132
|
-
expect(ohai_data['cloudstack']['public_hostname']).to eq("awesome-doge")
|
133
|
-
end
|
134
|
-
it "reads the availability zone from the metadata service" do
|
135
|
-
expect(ohai_data['cloudstack']['availability_zone']).to eq("TCS7")
|
136
|
-
end
|
137
|
-
it "reads the service offering from the metadata service" do
|
138
|
-
expect(ohai_data['cloudstack']['service_offering']).to eq("2vCPU, 1GHz, 2GB RAM")
|
139
|
-
end
|
140
|
-
it "reads the public ipv4 from the metadata service" do
|
141
|
-
expect(ohai_data['cloudstack']['router_ipv4']).to eq("10.235.34.23")
|
142
|
-
end
|
143
|
-
it "reads the vm id from the metadata service" do
|
144
|
-
expect(ohai_data['cloudstack']['vm_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
|
145
|
-
end
|
146
|
-
it "reads the cloud identifier from the metadata service" do
|
147
|
-
expect(ohai_data['cloudstack']['cloud_identifier']).to eq("CloudStack-{e84ff39d-ef64-4812-a8a9-7932f7b67f17}")
|
148
|
-
end
|
149
|
-
it "reads the instance id from the metadata service" do
|
150
|
-
expect(ohai_data['cloudstack']['instance_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|