Created
July 3, 2014 09:40
-
-
Save mindjiver/ec2a27dae2db807a13ff to your computer and use it in GitHub Desktop.
ohai_cloudstack.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Author:: Peter Joensson (<[email protected]>) | |
# 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