# # Author:: Cary Penniman () # 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 'json' provides "rightscale" class RightScale MetaDataFile = "/var/spool/rackspace/user-data.txt" end # this is a hack to convert the RS_ tokens into something more # intuative. Hopefully this will be removed when we stop using EC2 # userdata. def add_server(key, data) rightscale[:server] = Mash.new unless rightscale.has_key?(:server) server_names = { "RS_sketchy" => "sketchy", "RS_syslog" => "syslog", "RS_lumberjack" => "lumberjack", "RS_server" => "core" } rightscale[:server][server_names[key]] = data unless (server_names[key] == nil) end # # EC2 # require_plugin "ec2" def on_rightscale_ec2_platform? return false if (ec2 == nil || ec2[:userdata].match(/RS_/) == nil) # only ec2 supported true end # add all 'RS_' tokens in userdata, but perform translation for server names def get_data_from_ec2_user_date data_array = ec2[:userdata].split('&') data_array.each do |d| key, data = d.split('=') rightscale[key.sub(/RS_/,'')] = data unless add_server(key,data) end end if on_rightscale_ec2_platform? rightscale Mash.new get_data_from_ec2_user_date end # # Generic cloud # def on_rightscale_platform? File.exists?(RightScale::MetaDataFile) end # TODO: future # def get_data_json # file = File.open(RightScale::MetaDataFile) # json = "" # file.each { |line| json << line } # data = JSON.parse(json) # data["rightscale"].each { |key, data| rightscale[key] = data } # end def get_data data_array = File.open(RightScale::MetaDataFile) data_array.each do |d| key, data = d.split('=') key.strip! data.strip! rightscale[key.sub(/RS_/,'')] = data unless add_server(key,data) end end if on_rightscale_platform? rightscale Mash.new get_data end