Class: Ec2InstanceManager
- Inherits:
-
Object
- Object
- Ec2InstanceManager
- Defined in:
- lib/ec2-instance-manager/ec2_instance_manager.rb
Constant Summary collapse
- VERSION =
'0.2'
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 Launch
#get_running_instances_list, #launch, #terminate
Methods included from Status
#display_addresses, #display_ami_ids, #display_instances, #display_volumes, #get_instance_state, #status_info
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 |
# 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 [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 config key' ) do [:terminate] = true end [:config] = nil opts.on( '-c', '--config CONFIG_KEY', 'Sets the config key' ) do |key| [:config] = key end opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end end optparse.parse! = 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 end |
Instance Method Details
#ec2 ⇒ Object
57 58 59 60 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 57 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']) end |
#read_config ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 45 def read_config if File.exists?("config.yml") @config = YAML.load(File.read("config.yml")) else begin @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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ec2-instance-manager/ec2_instance_manager.rb', line 62 def run puts "EC2 Instance Manager" 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: #{@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 else launch unless [:status] end end |