Skip to content

Instantly share code, notes, and snippets.

@mindjiver
Created July 3, 2014 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindjiver/ec2a27dae2db807a13ff to your computer and use it in GitHub Desktop.
Save mindjiver/ec2a27dae2db807a13ff to your computer and use it in GitHub Desktop.
ohai_cloudstack.rb
#
# Author:: Peter Joensson (<peter.jonsson@klarna.com>)
# Copyright:: Copyright (c) 2014 Peter Joensson
# 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(:Cloudstack) do
provides "cloudstack"
include Ohai::Mixin::Ec2Metadata
# Checks for rackspace provider attribute
#
# === Return
# true:: If rackspace provider attribute found
# false:: Otherwise
def has_cloudstack_metadata?
# find DHCP server and curl out to it
end
def find_dhcp_server
for %"/var/lib/dhclient/* /var/lib/dhcp3/*"
so = shell_out("grep dhcp-server /var/lib/dhclient/*.leases")
if so.exitstatus == 0
else
end
collect_data do
# Adds cloudstack Mash
if hint?('cloudstack')
Ohai::Log.debug("ohai cloudstack")
if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80)
cloudstack Mash.new
Ohai::Log.debug("connecting to the Cloudstack metadata service")
fetch_metadata.each {|k, v| cloudstack[k] = v }
cloudstack['provider'] = 'cloudstack'
else
Ohai::Log.debug("unable to connect to the Cloudstack metadata service")
end
else
Ohai::Log.debug("NOT ohai cloudstack")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment