Huxtable gives access to instances for config, global, and logger to any class that includes it.
class Rudy::Hello include Rudy::Huxtable def print_config p @@config.defaults # {:nocolor => true, ...} p @@global.verbose # => 1 p @@logger.class # => StringIO end end
# File lib/rudy/huxtable.rb, line 49 def self.create_domain @sdb = Rudy::AWS::SDB.new(@@global.accesskey, @@global.secretkey, @@global.region) @sdb.create_domain Rudy::DOMAIN end
# File lib/rudy/huxtable.rb, line 59 def self.domain Rudy::DOMAIN end
# File lib/rudy/huxtable.rb, line 54 def self.domain_exists? @sdb = Rudy::AWS::SDB.new(@@global.accesskey, @@global.secretkey, @@global.region) (@sdb.list_domains || []).member? Rudy::DOMAIN end
# File lib/rudy/huxtable.rb, line 223 def self.keypair_path_to_name(kp) return nil unless kp name = File.basename kp #name.gsub(/key-/, '') # We keep the key- now end
Puts msg to +@@logger+ if Rudy.debug? returns true
# File lib/rudy/huxtable.rb, line 68 def self.ld(*msg) return unless Rudy.debug? @@logger.puts "D: " << msg.join("#{$/}D: ") end
Puts msg to +@@logger+ with "ERROR: " prepended
# File lib/rudy/huxtable.rb, line 66 def self.le(*msg); @@logger.puts " " << msg.join("#{$/} "); end
Puts msg to +@@logger+
# File lib/rudy/huxtable.rb, line 64 def self.li(*msg); msg.each { |m| @@logger.puts m } if !@@global.quiet; end
# File lib/rudy/huxtable.rb, line 46 def self.reset_config; @@config = Rudy::Config.new; end
# File lib/rudy/huxtable.rb, line 47 def self.reset_global; @@global = Rudy::Global.new; end
# File lib/rudy/huxtable.rb, line 33 def self.update_config(path=nil) @@config.verbose = (@@global.verbose >= 3) # -vvv # nil and bad paths sent to look_and_load are ignored @@config.look_and_load(path || @@global.config) @@global.apply_config(@@config) end
# File lib/rudy/huxtable.rb, line 77 def config_dirname raise "No config paths defined" unless @@config.is_a?(Rudy::Config) && @@config.paths.is_a?(Array) base_dir = File.dirname @@config.paths.first raise "Config directory doesn't exist #{base_dir}" unless File.exists?(base_dir) base_dir end
# File lib/rudy/huxtable.rb, line 173 def current_group_name "grp-#{@@global.zone}-#{current_machine_group}" end
# File lib/rudy/huxtable.rb, line 206 def current_machine_address(position='01') #raise NoConfig unless @@config #raise NoMachinesConfig unless @@config.machines raise "Position cannot be nil" if position.nil? addresses = [fetch_machine_param(:addresses)].flatten.compact addresses[position.to_i-1] end
# File lib/rudy/huxtable.rb, line 219 def current_machine_bucket @@global.bucket || fetch_machine_param(:bucket) || nil end
# File lib/rudy/huxtable.rb, line 177 def current_machine_count fetch_machine_param(:positions) || 1 end
# File lib/rudy/huxtable.rb, line 169 def current_machine_group [@@global.environment, @@global.role].join(Rudy::DELIM) end
# File lib/rudy/huxtable.rb, line 181 def current_machine_hostname # NOTE: There is an issue with Caesars that a keyword that has been # defined as forced_array (or forced_hash, etc...) is like that for # all subclasses of Caesars. There is a conflict between "hostname" # in the machines config and routines config. The routines config # parses hostname with forced_array because it's a shell command # in Rye::Cmd. Machines config expects just a symbol. The issue # is with Caesars so this is a workaround to return a symbol. hn = fetch_machine_param(:hostname) || :rudy hn = hn.flatten.compact.first if hn.is_a?(Array) hn end
# File lib/rudy/huxtable.rb, line 194 def current_machine_image fetch_machine_param(:ami) end
TODO: fix machine_group to include zone
# File lib/rudy/huxtable.rb, line 215 def current_machine_name [@@global.zone, current_machine_group, @@global.position].join(Rudy::DELIM) end
# File lib/rudy/huxtable.rb, line 198 def current_machine_os fetch_machine_param(:os) || 'linux' end
# File lib/rudy/huxtable.rb, line 92 def current_machine_root (fetch_machine_param(:root) || default_root).to_s end
# File lib/rudy/huxtable.rb, line 202 def current_machine_size fetch_machine_param(:size) || 'm1.small' end
# File lib/rudy/huxtable.rb, line 96 def current_machine_user (@@global.user || fetch_machine_param(:user) || default_user || Rudy.sysinfo.user).to_s end
# File lib/rudy/huxtable.rb, line 124 def current_user_is_root?(user=nil) user ||= current_machine_user user.to_s == current_machine_root end
# File lib/rudy/huxtable.rb, line 120 def current_user_keypairname user_keypairname current_machine_user end
# File lib/rudy/huxtable.rb, line 146 def current_user_keypairpath user_keypairpath current_machine_user end
# File lib/rudy/huxtable.rb, line 84 def default_root (@@config.defaults.root || 'root').to_s end
# File lib/rudy/huxtable.rb, line 88 def default_user (@@config.defaults.user || current_machine_root).to_s end
# File lib/rudy/huxtable.rb, line 150 def defined_keypairpath(name=nil) name ||= current_machine_user raise Rudy::Error, "No user provided" unless name ## NOTE: I think it is more appropriate to return nil here ## than raise errors. This stuff should be checked already ##raise NoConfig unless @@config ##raise NoMachinesConfig unless @@config.machines ##raise NoGlobal unless @@global return unless @@global && @@config && @@config.machines zon, env, rol = @@global.zone, @@global.environment, @@global.role path = @@global.identity path ||= @@config.machines.find_deferred(zon, env, rol, [:users, name, :keypair]) path ||= @@config.machines.find_deferred(env, rol, [:users, name, :keypair]) path ||= @@config.machines.find_deferred(rol, [:users, name, :keypair]) path ||= @@config.machines.find_deferred(@@global.region, [:users, name, :keypair]) path end
Looks for ENV-ROLE configuration in machines. There must be at least one definition in the config for this to return true That's how Rudy knows the current group is defined.
# File lib/rudy/huxtable.rb, line 233 def known_machine_group? raise NoConfig unless @@config return true if default_machine_group? raise NoMachinesConfig unless @@config.machines return false if !@@config && !@@global zon, env, rol = @@global.zone, @@global.environment, @@global.role conf = @@config.machines.find_deferred(@@global.region, zon, [env, rol]) conf ||= @@config.machines.find_deferred(zon, [env, rol]) !conf.nil? end
# File lib/rudy/huxtable.rb, line 75 def ld(*msg); Rudy::Huxtable.ld *msg; end
# File lib/rudy/huxtable.rb, line 74 def le(*msg); Rudy::Huxtable.le *msg; end
# File lib/rudy/huxtable.rb, line 73 def li(*msg); Rudy::Huxtable.li *msg; end
# File lib/rudy/huxtable.rb, line 117 def root_keypairname user_keypairname current_machine_root end
# File lib/rudy/huxtable.rb, line 143 def root_keypairpath user_keypairpath current_machine_root end
Returns the name of the current keypair for the given user. If there's a private key path in the config this will return the basename (it's assumed the Amazon Keypair has the same name as the file). Otherwise this returns the Rudy style name: key-ZONE-ENV-ROLE-USER. Or if this the user is root: key-ZONE-ENV-ROLE
# File lib/rudy/huxtable.rb, line 107 def user_keypairname(user=nil) user ||= current_machine_user path = defined_keypairpath user if path Huxtable.keypair_path_to_name(path) else n = current_user_is_root?(user) ? '' : "-#{user}" "key-%s-%s%s" % [@@global.zone, current_machine_group, n] end end
# File lib/rudy/huxtable.rb, line 129 def user_keypairpath(name=nil) name ||= current_machine_user path = defined_keypairpath name # If we can't find a user defined key, we'll # check the config path for a generated one. if path raise "Private key file not found (#{path})" unless File.exists?(path) path = File.expand_path(path) else ssh_key_dir = @@config.defaults.keydir || Rudy::SSH_KEY_DIR path = File.join(ssh_key_dir, user_keypairname(name)) end path end
Generated with the Darkfish Rdoc Generator 2.