Sha256: e19073aa4b9a993036a5e52257cba173dc202a8f3b767bbb1205c8a2f55f18e1

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

require 'trollop'

module SimplePerf
  module CLI
    class Chaos
      include Shared

      def execute
        opts = Trollop::options do
          version SimplePerf::VERSION
          banner <<-EOS

Randomly terminates an instance in the specified stack

Usage:
      simple_perf chaos -e ENVIRONMENT -n STACK_NAME
EOS
          opt :help, "Display Help"
          opt :environment, "Set the target environment", :type => :string
          opt :name, "Stack name to manage", :type => :string
        end
        Trollop::die :environment, "is required but not specified" unless opts[:environment]
        Trollop::die :name, "is required but not specified" unless opts[:name]

        config = Config.new.environment opts[:environment]

        command = 'simple_deploy instances' +
                   ' -e ' + opts[:environment] +
                   ' -n ' + opts[:name]

        output = `#{command}`
        output.gsub!(/\r\n?/, "\n")
        list = output.split("\n")
        target = list.sample

        puts "Target locked: " + target

        AWS.config(
            :access_key_id => config['access_key'],
            :secret_access_key => config['secret_key'])

        ec2 = AWS::EC2.new(:region => config['region'])
        ec2.instances.each do |i|
          if(i.ip_address == target)
            puts "Terminating instance: " + target
            i.terminate
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
simple_perf-0.0.8 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.7 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.6 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.5 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.4 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.3 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.2 lib/simple_perf/cli/chaos.rb
simple_perf-0.0.1 lib/simple_perf/cli/chaos.rb