Created
November 4, 2011 04:26
-
-
Save bbhoss/1338655 to your computer and use it in GitHub Desktop.
Linode Ohai Plugin
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:: Preston Marshall (<preston@ideamarshal.com>) | |
# 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. | |
provides "linode" | |
provides "cloud" | |
require_plugin "kernel" | |
require_plugin "network" | |
# Checks for matching linode kernel name | |
# | |
# === Return | |
# true:: If kernel name matches | |
# false:: Otherwise | |
def has_linode_kernel? | |
kernel[:release].split('-').last =~ /linode/ | |
end | |
# Identifies the linode cloud | |
# | |
# === Return | |
# true:: If the linode cloud can be identified | |
# false:: Otherwise | |
def looks_like_linode? | |
has_linode_kernel? | |
end | |
# Names linode ip address | |
# | |
# === Parameters | |
# name<Symbol>:: Use :public_ip or :private_ip | |
# eth<Symbol>:: Interface name of public or private ip | |
def get_ip_address(name, eth) | |
network[:interfaces][eth][:addresses].each do |key, info| | |
linode[name] = key if info['family'] == 'inet' | |
end | |
end | |
# Adds linode Mash | |
if looks_like_linode? | |
linode Mash.new | |
cloud Mash.new | |
cloud[:public_ips] = [] | |
cloud[:private_ips] = [] | |
get_ip_address(:public_ip, :eth0) | |
get_ip_address(:private_ip, 'eth0:0') | |
linode[:public_ipv4] = linode[:public_ip] | |
linode[:local_ipv4] = linode[:private_ip] | |
linode[:local_hostname] = hostname | |
# Can't get it to integrate with the existing cloud plugin for some reason, so build the cloud hash here manually. It looks like this would work if they imported this file into their repo and added require_plugin "linode" like they do for rackspace and ec2. | |
cloud[:public_ips] << linode['public_ip'] | |
cloud[:private_ips] << linode['private_ip'] | |
cloud[:public_ipv4] = linode['public_ipv4'] | |
cloud[:public_hostname] = linode['public_hostname'] | |
cloud[:local_ipv4] = linode['local_ipv4'] | |
cloud[:local_hostname] = linode['local_hostname'] | |
cloud[:provider] = "linode" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This expects your private network to already be setup on eth0:0. Do it manually or use a stackscript.