Class: Ec2InstanceManager
- Inherits:
-
Object
- Object
- Ec2InstanceManager
- Defined in:
- lib/ec2-instance-manager/ec2_instance_manager.rb
Constant Summary collapse
- VERSION =
'0.4.0'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#customer_key ⇒ Object
readonly
Returns the value of attribute customer_key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #ec2 ⇒ Object
-
#initialize(arguments, stdin) ⇒ Ec2InstanceManager
constructor
A new instance of Ec2InstanceManager.
- #read_config ⇒ Object
- #run ⇒ Object
Methods included from Status
#display_addresses, #display_ami_ids, #display_instances, #display_volumes, #get_instance_state, #status_info
Methods included from Launch
#launch, #launch_ami, #start_launch_plan, #terminate
Methods included from Output
#cancel_message, #green, #output_running_state, #red, #white, #yellow
Constructor Details
#initialize(arguments, stdin) ⇒ Ec2InstanceManager
Returns a new instance of Ec2InstanceManager.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 11 def initialize(arguments, stdin) @arguments = arguments @stdin = stdin = {} optparse = OptionParser.new do |opts| opts. = "Usage: ec2-instance-manager #{VERSION} [options]" [:status] = false opts.on( '-s', '--status', 'Status only' ) do [:status] = true end [:terminate] = false opts.on( '-t', '--terminate-all', 'Terminates all instances running under a customer config key' ) do [:terminate] = true end [:start_launch_plan] = false opts.on( '-l', '--start-launch-plan', 'Starts a launch plan under a customer config key' ) do [:start_launch_plan] = true end [:group] = nil opts.on( '-g', '--group LAUNCH_GROUP_NAME', 'Starts a launch plan group under a customer config key' ) do |group| [:group] = group end [:config] = nil opts.on( '-c', '--config CONFIG_KEY', 'Sets the customer config key' ) do |key| [:config] = key end opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end end optparse.parse! @options = end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 9 def config @config end |
#customer_key ⇒ Object (readonly)
Returns the value of attribute customer_key.
9 10 11 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 9 def customer_key @customer_key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 9 def @options end |
Instance Method Details
#ec2 ⇒ Object
69 70 71 72 73 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 69 def ec2 @ec2 = AWS::EC2::Base.new(:access_key_id => config[@customer_key]['amazon_access_key_id'], :secret_access_key => config[@customer_key]['amazon_secret_access_key'], :server => config[@customer_key]['ec2_server_region']) end |
#read_config ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 55 def read_config if File.exists?("config.yml") puts "Using config in this directory" @config = YAML.load(File.read("config.yml")) else begin puts "Using config in your home directory" @config = YAML.load(File.read("#{ENV['HOME']}/.ec2_instance_manager_config.yml")) rescue Errno::ENOENT raise "config.yml expected in current directory or ~/.ec2_instance_manager_config.yml" end end end |
#run ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 75 def run puts white("EC2 Instance Manager #{VERSION}") puts unless [:config] puts "Which customer config do you want to use? (#{config.keys.join(", ")})" @customer_key = gets @customer_key = @customer_key.rstrip.lstrip @customer_key = 'default' if @customer_key.empty? else @customer_key = [:config] end puts "Configuration Key: #{@customer_key}" puts "AMAZON_ACCESS_KEY_ID: #{config[@customer_key]['amazon_access_key_id']}" puts "KEY: #{config[@customer_key]['key']}" puts "ZONE: #{config[@customer_key]['availability_zone']}" puts status_info if [:terminate] terminate elsif [:start_launch_plan] start_launch_plan else launch unless [:status] end end |