summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-03-18 09:09:05 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-03-18 09:11:35 -0700
commitbca3f793912b6785739ae1aa78f2d6578a5d30ea (patch)
treec8458fef25cbf9b2ff1956cf4765316a52e01e80
parentf8b54f9f1c630ffe55a137f93c84a274abd93305 (diff)
downloadohai-jdm/354.tar.gz
Reverting #354 because change bring in GPLv3 dependencyjdm/354
Revert "Merge pull request #354 from lndbrg/cloudstack-support" This reverts commit ca805e6952eae39bc53113d2da798b1dcd0d51de, reversing changes made to 0779baf28aa230c134877122dbafa8eacb7b29bd.
-rw-r--r--lib/ohai/mixin/cloudstack_metadata.rb88
-rw-r--r--lib/ohai/plugins/cloud.rb46
-rw-r--r--lib/ohai/plugins/cloudstack.rb50
-rw-r--r--ohai.gemspec1
-rw-r--r--spec/unit/mixin/cloudstack_metadata_spec.rb33
-rw-r--r--spec/unit/plugins/cloud_spec.rb31
-rw-r--r--spec/unit/plugins/cloudstack_spec.rb155
7 files changed, 0 insertions, 404 deletions
diff --git a/lib/ohai/mixin/cloudstack_metadata.rb b/lib/ohai/mixin/cloudstack_metadata.rb
deleted file mode 100644
index 8ecb9daf..00000000
--- a/lib/ohai/mixin/cloudstack_metadata.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# Author:: Olle Lundberg (<geek@nerd.sh>)
-# Copyright:: Copyright (c) 2014 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 'ohai/mixin/ec2_metadata'
-require 'ohai/hints'
-require 'net/dhcp'
-require 'socket'
-
-
-module Ohai
- module Mixin
- module CloudstackMetadata
- include Ohai::Mixin::Ec2Metadata
-
- def self.discover_dhcp_server
- response = ''
- if Ohai::Hints.hint?('cloudstack')
- begin
- request = DHCP::Discover.new
-
- listensock = UDPSocket.new
- sendsock = UDPSocket.new
-
- listensock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
- sendsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
-
- sendsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
- sendaddr = "<broadcast>"
- listenport = 68
-
- listensock.bind('', listenport)
- sendsock.connect(sendaddr, 67)
-
- sendsock.send(request.pack, 0)
-
- data = listensock.recvfrom_nonblock(1500)
- rescue Exception => e
- if (defined?(IO::WaitReadable) && e.instance_of?(IO::WaitReadable)) ||
- (e.instance_of?(Errno::EAGAIN) || e.instance_of?(Errno::EWOULDBLOCK)) # This OR branch can be removed when ruby > 1.8.7
- unless IO.select([listensock], nil, nil, 10)
- # timeout reached
- Ohai::Log.debug("Timeout reached awaiting response from DHCP server")
- else
- # try to read from the socket again
- data = listensock.recvfrom_nonblock(1500)
- end
- else
- Ohai::Log.debug("Exceptions encountered when trying to connect to dhcp server. #{e.message}")
- end
- ensure
- sendsock.close
- listensock.close
- if data
- response = [DHCP::Message.from_udp_payload(data[0]).siaddr].pack('N').unpack('C4').join('.')
- end
- end
- end
- response
- end
-
- CLOUDSTACK_METADATA_ADDR = self.discover_dhcp_server unless defined?(CLOUDSTACK_METADATA_ADDR)
-
- def http_client
- Net::HTTP.start(CLOUDSTACK_METADATA_ADDR).tap { |h| h.read_timeout = 600 }
- end
-
- def best_api_version
- 'latest'
- end
-
- end
- end
-end
-
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index 8145cc0a..aee17b7b 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -24,7 +24,6 @@ Ohai.plugin(:Cloud) do
depends "linode"
depends "openstack"
depends "azure"
- depends "cloudstack"
depends "digital_ocean"
# Make top-level cloud hashes
@@ -218,45 +217,6 @@ Ohai.plugin(:Cloud) do
end
# ----------------------------------------
- # cloudstack
- # ----------------------------------------
-
- # Is current cloud cloudstack-based?
- #
- # === Return
- # true:: If cloudstack Hash is defined
- # false:: Otherwise
- def on_cloudstack?
- cloudstack != nil
- end
-
- # Fill cloud hash with cloudstack values. Cloudstack is a bit different in that
- # the local interface can be a public or private ip is using basic networking.
- # When using advanced networking, the public_ipv4 passed in the metadata isn't
- # usually going to be the public ip of the interface, so don't use that value. As
- # per the Cloudstack documentation its actually the NAT router IP.
- def get_cloudstack_values
- cloud[:local_ipv4] = cloudstack['local_ipv4']
-
- if cloudstack['local_ipv4']
- # Private IPv4 address
- if cloudstack['local_ipv4'] =~ /\A(10\.|192\.168\.|172\.1[6789]\.|172\.2.\.|172\.3[01]\.)/
- cloud[:private_ips] << cloudstack['local_ipv4']
- cloud[:public_ipv4] = nil
- else
- cloud[:public_ips] << cloudstack['local_ipv4']
- # Yes, not a mistake, for basic networking this may be true
- cloud[:public_ipv4] = cloudstack['local_ipv4']
- end
- end
- cloud[:public_hostname] = cloudstack['public_hostname']
- cloud[:local_hostname] = cloudstack['local_hostname']
- cloud[:vm_id] = cloudstack['vm_id']
- cloud[:local_hostname] = cloudstack['local_hostname']
- cloud[:provider] = 'cloudstack'
- end
-
- # ----------------------------------------
# digital_ocean
# ----------------------------------------
@@ -327,12 +287,6 @@ Ohai.plugin(:Cloud) do
get_azure_values
end
- # setup cloudstack cloud
- if on_cloudstack?
- create_objects
- get_cloudstack_values
- end
-
# setup digital_ocean cloud data
if on_digital_ocean?
create_objects
diff --git a/lib/ohai/plugins/cloudstack.rb b/lib/ohai/plugins/cloudstack.rb
deleted file mode 100644
index 1f460538..00000000
--- a/lib/ohai/plugins/cloudstack.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# Author:: Peter Schroeter <peter.schroeter@rightscale.com>
-# Author:: Olle Lundberg (<geek@nerd.sh>)
-# Copyright:: Copyright (c) 2010-2014 RightScale Inc
-# Copyright:: Copyright (c) 2014 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 'ohai/mixin/cloudstack_metadata'
-
-Ohai.plugin(:Cloudstack) do
- provides "cloudstack"
-
- include Ohai::Mixin::CloudstackMetadata
-
- collect_data do
- # Adds cloudstack Mash
- if hint?('cloudstack')
- Ohai::Log.debug("found 'cloudstack' hint. Will try to connect to the metadata server")
-
- if can_metadata_connect?(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR, 80)
- cloudstack Mash.new
- Ohai::Log.debug("connecting to the 'cloudstack' metadata service")
- fetch_metadata.each { |k, v| cloudstack[k] = v }
- # Note: the cloudstack public_ipv4 is the value of the NAT router (as per cloudstack documentation)
- # and not necessarily the publicly available IP. cloustack semi-supports floating
- # ips in that the public ip for an instance can be an IP different from the NAT router
- cloudstack['router_ipv4'] = cloudstack.delete('public_ipv4')
- cloudstack['dhcp_lease_provider_ip'] = dhcp_ip
- else
- Ohai::Log.debug("unable to connect to the 'cloudstack' metadata service")
- end
- else
- Ohai::Log.debug("unable to find 'cloudstack' hint. Won't connect to the metadata server.")
- end
- end
-end
-
-
diff --git a/ohai.gemspec b/ohai.gemspec
index a094ef09..1f85f7b6 100644
--- a/ohai.gemspec
+++ b/ohai.gemspec
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
s.add_dependency "mixlib-config", "~> 2.0"
s.add_dependency "mixlib-log"
s.add_dependency "mixlib-shellout", "~> 2.0"
- s.add_dependency "net-dhcp"
s.add_dependency "ipaddress"
s.add_dependency "wmi-lite", "~> 1.0"
s.add_dependency "ffi", "~> 1.9"
diff --git a/spec/unit/mixin/cloudstack_metadata_spec.rb b/spec/unit/mixin/cloudstack_metadata_spec.rb
deleted file mode 100644
index 693926c5..00000000
--- a/spec/unit/mixin/cloudstack_metadata_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Author:: Olle Lundberg (<geek@nerd.sh>)
-# Copyright:: Copyright (c) 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 CONDIT"Net::HTTP Response"NS 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 'ohai/mixin/cloudstack_metadata'
-
-describe Ohai::Mixin::CloudstackMetadata do
- let(:mixin) {
- metadata_object = Object.new.extend(Ohai::Mixin::CloudstackMetadata)
- metadata_object
- }
-
- context "#best_api_version" do
- it "returns the string latest" do
- expect(mixin.best_api_version).to eq("latest")
- end
- end
-end
diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb
index 0c7ac434..e64eb655 100644
--- a/spec/unit/plugins/cloud_spec.rb
+++ b/spec/unit/plugins/cloud_spec.rb
@@ -29,7 +29,6 @@ describe Ohai::System, "plugin cloud" do
@plugin[:eucalyptus] = nil
@plugin[:linode] = nil
@plugin[:azure] = nil
- @plugin[:cloudstack] = nil
@plugin[:digital_ocean] = nil
@plugin.run
expect(@plugin[:cloud]).to be_nil
@@ -207,35 +206,6 @@ describe Ohai::System, "plugin cloud" do
end
end
- describe "with cloudstack mash" do
- before do
- @plugin[:cloudstack] = Mash.new()
- end
-
- it "populates cloud public ip" do
- @plugin[:cloudstack]['local_ipv4'] = "174.129.150.8"
- @plugin.run
- expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:cloudstack]['local_ipv4'])
- end
-
- it "populates cloud private ip" do
- @plugin[:cloudstack]['local_ipv4'] = "10.252.42.149"
- @plugin.run
- expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:cloudstack]['local_ipv4'])
- end
-
- it "populates cloud provider" do
- @plugin.run
- expect(@plugin[:cloud][:provider]).to eq("cloudstack")
- end
-
- it "populates vm id" do
- @plugin[:cloudstack]['vm_id'] = "8983fb85-fb7f-46d6-8af1-c1b6666fec39"
- @plugin.run
- expect(@plugin[:cloud][:vm_id]).to eq(@plugin[:cloudstack]['vm_id'])
- end
- end
-
describe "with digital_ocean mash" do
before do
@plugin[:digital_ocean] = Mash.new
@@ -289,5 +259,4 @@ describe Ohai::System, "plugin cloud" do
expect(@plugin[:cloud][:provider]).to eq("digital_ocean")
end
end
-
end
diff --git a/spec/unit/plugins/cloudstack_spec.rb b/spec/unit/plugins/cloudstack_spec.rb
deleted file mode 100644
index 04d65a22..00000000
--- a/spec/unit/plugins/cloudstack_spec.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-#
-# Author:: Olle Lundberg (<geek@nerd.sh>)
-# Copyright:: Copyright (c) 2014 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 CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'spec_helper'
-require 'ohai/plugins/cloudstack'
-
-describe "Cloudstack Plugin" do
-
- let(:cloudstack_hint) { false }
-
- let(:ohai_system) { Ohai::System.new }
- let(:ohai_data) { ohai_system.data }
-
- let(:cloudstack_plugin) do
- plugin = get_plugin("cloudstack", ohai_system)
- allow(plugin).to receive(:hint?).with("cloudstack").and_return(cloudstack_hint)
- plugin
- end
-
- before do
- stub_const("Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR", '10.10.10.10')
- end
-
- context "when there is no relevant hint" do
-
- it "does not set any cloudstack data" do
- cloudstack_plugin.run
- expect(ohai_data).to_not have_key("cloudstack")
- end
-
- end
-
- context "when there is a `cloudstack` hint" do
- let(:cloudstack_hint) { true }
-
- context "and the metadata service is not available" do
-
- before do
- expect(cloudstack_plugin).to receive(:can_metadata_connect?).
- with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR,80).
- and_return(false)
- end
-
- it "does not set any cloudstack data" do
- cloudstack_plugin.run
- expect(ohai_data).to_not have_key("cloudstack")
- end
- end
-
- context "and the metadata service is available" do
-
- let(:metadata_version) { "latest" }
-
- let(:metadata_root) do
- <<EOM
-availability-zone
-cloud-identifier
-instance-id
-local-hostname
-local-ipv4
-public-hostname
-public-ipv4
-service-offering
-vm-id
-EOM
- end
-
- let(:metadata_values) do
- {
- "local-ipv4" =>"10.235.34.23",
- "local-hostname" =>"VM-8983fb85-fb7f-46d6-8af1-c1b6666fec39",
- "public-hostname" =>"awesome-doge",
- "availability-zone" =>"TCS7",
- "service-offering" =>"2vCPU, 1GHz, 2GB RAM",
- "public-ipv4" =>"10.235.34.23",
- "vm-id"=>"8983fb85-fb7f-46d6-8af1-c1b6666fec39",
- "cloud-identifier"=>"CloudStack-{e84ff39d-ef64-4812-a8a9-7932f7b67f17}",
- "instance-id"=>"8983fb85-fb7f-46d6-8af1-c1b6666fec39"
- }
- end
-
- let(:http_client) { double("Net::HTTP", :read_timeout= => nil) }
-
- def expect_get(url, response_body)
- expect(http_client).to receive(:get).
- with(url).
- and_return(double("HTTP Response", :code => "200", :body => response_body))
- end
-
- before do
- expect(cloudstack_plugin).to receive(:can_metadata_connect?).
- with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR,80).
- and_return(true)
-
- allow(Net::HTTP).to receive(:start).
- with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR).
- and_return(http_client)
-
- allow(cloudstack_plugin).to receive(:best_api_version).and_return(metadata_version)
-
- expect_get("/#{metadata_version}/meta-data/", metadata_root)
-
- metadata_values.each do |md_id, md_value|
- expect_get("/#{metadata_version}/meta-data/#{md_id}", md_value)
- end
-
- cloudstack_plugin.run
- end
-
- it "reads the local ipv4 from the metadata service" do
- expect(ohai_data['cloudstack']['local_ipv4']).to eq("10.235.34.23")
- end
- it "reads the local hostname from the metadata service" do
- expect(ohai_data['cloudstack']['local_hostname']).to eq("VM-8983fb85-fb7f-46d6-8af1-c1b6666fec39")
- end
- it "reads the public hostname from the metadata service" do
- expect(ohai_data['cloudstack']['public_hostname']).to eq("awesome-doge")
- end
- it "reads the availability zone from the metadata service" do
- expect(ohai_data['cloudstack']['availability_zone']).to eq("TCS7")
- end
- it "reads the service offering from the metadata service" do
- expect(ohai_data['cloudstack']['service_offering']).to eq("2vCPU, 1GHz, 2GB RAM")
- end
- it "reads the public ipv4 from the metadata service" do
- expect(ohai_data['cloudstack']['router_ipv4']).to eq("10.235.34.23")
- end
- it "reads the vm id from the metadata service" do
- expect(ohai_data['cloudstack']['vm_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
- end
- it "reads the cloud identifier from the metadata service" do
- expect(ohai_data['cloudstack']['cloud_identifier']).to eq("CloudStack-{e84ff39d-ef64-4812-a8a9-7932f7b67f17}")
- end
- it "reads the instance id from the metadata service" do
- expect(ohai_data['cloudstack']['instance_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
- end
- end
- end
-end
-