lib/rudy/command/base.rb in rudy-0.3.0 vs lib/rudy/command/base.rb in rudy-0.3.2

- old
+ new

@@ -29,10 +29,12 @@ attr_reader :rscripts attr_reader :domains attr_reader :machine_images + attr_reader :config + def init @access_key = ENV['AWS_ACCESS_KEY'] unless @access_key @secret_key = ENV['AWS_SECRET_KEY'] unless @secret_key @account_num = ENV['AWS_ACCOUNT_NUMBER'] unless @account_num @@ -40,19 +42,21 @@ @ec2_private_key = ENV['EC2_PRIVATE_KEY'] unless @ec2_private_key if ENV['RUDY_SVN_BASE'] @scm = Rudy::SCM::SVN.new(ENV['RUDY_SVN_BASE']) end + + @config = File.exists?(RUDY_CONFIG) ? Rudy::Config.from_file(RUDY_CONFIG) : Rudy::Config.new - @user ||= 'rudy' - @environment ||= 'stage' - @role ||= 'app' - @position ||= '01' - - @zone ||= DEFAULT_ZONE @region ||= DEFAULT_REGION + @zone ||= DEFAULT_ZONE + @environment ||= DEFAULT_ENVIRONMENT + @role ||= DEFAULT_ROLE + @position ||= DEFAULT_POSITION + @user ||= DEFAULT_USER + @keypairs = {} ENV.keys.select { |key| key.match /EC2_KEYPAIR/i }.each do |key| ec2, keypair, env, role, user = key.split '_' # EC2_KEYPAIR_STAGE_APP_RUDY raise "#{key} is malformed." unless env && role && user new_key = "#{env}-#{role}-#{user}".downcase @@ -79,16 +83,19 @@ instance_variables.each do |var| puts "#{var}: #{instance_variable_get(var)}" end end - @ec2 = Rudy::AWS::EC2.new(@access_key, @secret_key) - # RightAws::SdbInterface is on thin ice. No select support! Or sort! - @sdb = Rudy::AWS::SimpleDB.new(@access_key, @secret_key) - #@s3 = Rudy::AWS::SimpleDB.new(@access_key, @secret_key) + if @access_key && @secret_key + @ec2 = Rudy::AWS::EC2.new(@access_key, @secret_key) + # RightAws::SdbInterface is on thin ice. No select support! Or sort! + @sdb = Rudy::AWS::SimpleDB.new(@access_key, @secret_key) + #@s3 = Rudy::AWS::SimpleDB.new(@access_key, @secret_key) + end end + # Raises exceptions if the requested user does # not have a valid keypair configured. (See: EC2_KEYPAIR_*) def check_keys raise "No SSH key provided for #{keypairname}!" unless has_keypair?(keypairname) raise "SSH key provided but cannot be found! (#{keypairname}: #{keypairpath})" unless File.exists?(keypairpath) @@ -117,12 +124,13 @@ def machine_image @machine_images[machine_group] end + # TODO: fix machine_group to include zone def machine_name - [machine_group, @position].join(RUDY_DELIM) + [@zone, machine_group, @position].join(RUDY_DELIM) end def keypairname [machine_group, user].join(RUDY_DELIM) end @@ -211,11 +219,16 @@ msg = %q(======================================================= ======================================================= !!!!!!!!! YOU ARE PLAYING WITH PRODUCTION !!!!!!!!! ======================================================= =======================================================) - puts msg.color(:bright, :red, :bg_white) - puts + puts msg.color(:bright, :red, :bg_white), $/ unless @quiet + + end + + if Rudy.in_situ? + msg = %q(============ THIS IS EC2 ============) + puts msg.color(:bright, :blue, :bg_white), $/ unless @quiet end end def print_footer \ No newline at end of file