blob: b7ac8973e81569ca86ea7678657ef2ea96f3416d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#
# Author:: Matt Ray (<matt@chef.io>)
# Copyright:: Copyright (c) 2012-2016 Chef Software, 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 "ohai/mixin/ec2_metadata"
Ohai.plugin(:Openstack) do
provides "openstack"
include Ohai::Mixin::Ec2Metadata
def collect_openstack_metadata(addr = Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, api_version = "2013-04-04")
path = "/openstack/#{api_version}/meta_data.json"
uri = "http://#{addr}#{path}"
begin
response = http_client.get_response(URI.parse(uri), nil, nil)
case response.code
when "200"
FFI_Yajl::Parser.parse(response.body)
when "404"
Ohai::Log.debug("Encountered 404 response retreiving OpenStack specific metadata path: #{path} ; continuing.")
nil
else
raise "Encountered error retrieving OpenStack specific metadata (#{path} returned #{response.code} response)"
end
rescue => e
Ohai::Log.debug("Encountered error retrieving OpenStack specific metadata (#{uri}), due to #{e.class}")
nil
end
end
collect_data do
# Adds openstack Mash
if hint?("openstack") || hint?("hp")
Ohai::Log.debug("ohai openstack")
if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
openstack Mash.new
Ohai::Log.debug("connecting to the OpenStack metadata service")
fetch_metadata.each { |k, v| openstack[k] = v }
if hint?("hp")
openstack["provider"] = "hp"
else
openstack["provider"] = "openstack"
Ohai::Log.debug("connecting to the OpenStack specific metadata service")
openstack["metadata"] = collect_openstack_metadata
end
else
Ohai::Log.debug("unable to connect to the OpenStack metadata service")
end
else
Ohai::Log.debug("NOT ohai openstack")
end
end
end
|