okiess-ec2-instance-manager 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../lib/ec2_instance_manager'
3
+ require File.dirname(__FILE__) + '/../lib/ec2-instance-manager'
4
4
 
5
5
  # Create and run the application
6
6
  app = Ec2InstanceManager.new(ARGV, STDIN)
@@ -5,15 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ec2-instance-manager}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oliver Kiessler"]
12
- s.date = %q{2009-09-11}
13
- s.default_executable = %q{ec2_instance_manager}
12
+ s.date = %q{2009-09-14}
13
+ s.default_executable = %q{ec2-instance-manager}
14
14
  s.description = %q{Launches EC2 instances for multiple AWS accounts}
15
15
  s.email = %q{kiessler@inceedo.com}
16
- s.executables = ["ec2_instance_manager"]
16
+ s.executables = ["ec2-instance-manager"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
19
  "README.rdoc"
@@ -25,11 +25,12 @@ Gem::Specification.new do |s|
25
25
  "README.rdoc",
26
26
  "Rakefile",
27
27
  "VERSION",
28
- "bin/ec2_instance_manager",
28
+ "bin/ec2-instance-manager",
29
29
  "config.yml.sample",
30
30
  "ec2-instance-manager.gemspec",
31
- "lib/ec2_instance_manager.rb",
32
- "lib/ec2_methods.rb",
31
+ "lib/ec2-instance-manager.rb",
32
+ "lib/ec2-instance-manager/ec2_instance_manager.rb",
33
+ "lib/ec2-instance-manager/status.rb",
33
34
  "test/ec2-instance-manager_test.rb",
34
35
  "test/test_helper.rb"
35
36
  ]
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ gem 'amazon-ec2'
5
+ require 'AWS'
6
+
7
+ require File.dirname(__FILE__) + '/ec2-instance-manager/ec2_instance_manager'
@@ -1,38 +1,46 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rubygems"
4
- gem 'amazon-ec2'
5
- require 'AWS'
6
-
7
- require File.dirname(__FILE__) + '/ec2_methods'
1
+ require File.dirname(__FILE__) + '/status'
8
2
 
9
3
  class Ec2InstanceManager
10
- include Ec2Methods
11
- VERSION = '0.1'
4
+ include Status
5
+ VERSION = '0.1.2'
12
6
 
13
- attr_reader :options, :config, :customer_key
7
+ attr_reader :config, :customer_key
14
8
 
15
9
  def initialize(arguments, stdin)
16
10
  @arguments = arguments
17
11
  @stdin = stdin
18
- @config = YAML.load(File.read("config.yml"))
12
+ end
13
+
14
+ def config; @config ||= read_config; end
15
+ def read_config
16
+ if File.exists?("config.yml")
17
+ @config = YAML.load(File.read("config.yml"))
18
+ else
19
+ begin
20
+ @config = YAML.load(File.read("#{ENV['HOME']}/.ec2_instance_manager_config.yml"))
21
+ rescue Errno::ENOENT
22
+ raise "config.yml expected in current directory or ~/.ec2_instance_manager_config.yml"
23
+ end
24
+ end
25
+ end
26
+
27
+ def ec2
28
+ @ec2 ||= AWS::EC2::Base.new(:access_key_id => config[@customer_key]['amazon_access_key_id'],
29
+ :secret_access_key => config[@customer_key]['amazon_secret_access_key'])
19
30
  end
20
31
 
21
32
  def run
22
33
  puts "EC2 Instance Manager"
23
34
  puts
24
- puts "Which customer config do you want to use? (#{@config.keys.join(", ")})"
35
+ puts "Which customer config do you want to use? (#{config.keys.join(", ")})"
25
36
  @customer_key = gets
26
37
  @customer_key = @customer_key.rstrip.lstrip
27
38
  @customer_key = 'default' if @customer_key.empty?
28
39
 
29
- @ec2 = AWS::EC2::Base.new(:access_key_id => @config[@customer_key]['amazon_access_key_id'],
30
- :secret_access_key => @config[@customer_key]['amazon_secret_access_key'])
31
-
32
40
  puts "Configuration: #{@customer_key}"
33
- puts "AMAZON_ACCESS_KEY_ID: #{@config[@customer_key]['amazon_access_key_id']}"
34
- puts "KEY: #{@config[@customer_key]['key']}"
35
- puts "ZONE: #{@config[@customer_key]['availability_zone']}"
41
+ puts "AMAZON_ACCESS_KEY_ID: #{config[@customer_key]['amazon_access_key_id']}"
42
+ puts "KEY: #{config[@customer_key]['key']}"
43
+ puts "ZONE: #{config[@customer_key]['availability_zone']}"
36
44
  puts
37
45
 
38
46
  status_info
@@ -42,11 +50,11 @@ class Ec2InstanceManager
42
50
  ami_id = gets
43
51
  ami_id = ami_id.lstrip.rstrip
44
52
 
45
- result = @ec2.run_instances(
53
+ result = ec2.run_instances(
46
54
  :image_id => ami_id,
47
- :instance_type => @config[@customer_key]['instance_type'],
48
- :key_name => @config[@customer_key]['key'],
49
- :availability_zone => @config[@customer_key]['availability_zone']
55
+ :instance_type => config[@customer_key]['instance_type'],
56
+ :key_name => config[@customer_key]['key'],
57
+ :availability_zone => config[@customer_key]['availability_zone']
50
58
  )
51
59
 
52
60
  instance_id = result.instancesSet.item[0].instanceId
@@ -68,7 +76,7 @@ class Ec2InstanceManager
68
76
 
69
77
  if not public_ip.empty? and public_ip.size > 1
70
78
  puts "Associating public IP address... #{public_ip}"
71
- result = @ec2.associate_address(:instance_id => instance_id, :public_ip => public_ip.lstrip.rstrip)
79
+ result = ec2.associate_address(:instance_id => instance_id, :public_ip => public_ip.lstrip.rstrip)
72
80
  if result["return"] == "true"
73
81
  puts "=> Success."
74
82
  end
@@ -80,7 +88,7 @@ class Ec2InstanceManager
80
88
 
81
89
  if not volume_id.empty? and volume_id.size > 1
82
90
  puts "Attaching volume... #{volume_id}"
83
- result = @ec2.attach_volume(:volume_id => volume_id.lstrip.rstrip, :instance_id => instance_id, :device => '/dev/sdf')
91
+ result = ec2.attach_volume(:volume_id => volume_id.lstrip.rstrip, :instance_id => instance_id, :device => '/dev/sdf')
84
92
  if result["return"] == "true"
85
93
  puts "=> Success."
86
94
  end
@@ -1,13 +1,13 @@
1
- module Ec2Methods
1
+ module Status
2
2
  def get_instance_state(instance_id)
3
- result = @ec2.describe_instances(:instance_id => instance_id)
3
+ result = ec2.describe_instances(:instance_id => instance_id)
4
4
  instance_state = result["reservationSet"]["item"].first["instancesSet"]["item"].first["instanceState"]["name"]
5
5
  dns_name = result["reservationSet"]["item"].first["instancesSet"]["item"].first["dnsName"]
6
6
  return instance_state, dns_name
7
7
  end
8
8
 
9
9
  def display_ami_ids(owner_id = nil)
10
- result = @ec2.describe_images(:owner_id => owner_id || @config[@customer_key]['amazon_account_number'])
10
+ result = ec2.describe_images(:owner_id => owner_id || config[@customer_key]['amazon_account_number'])
11
11
  if result and result["imagesSet"]
12
12
  result["imagesSet"]["item"].each {|image| puts "#{image["imageId"]} - #{image["imageLocation"]}"}
13
13
  else
@@ -16,7 +16,7 @@ module Ec2Methods
16
16
  end
17
17
 
18
18
  def display_instances
19
- result = @ec2.describe_instances
19
+ result = ec2.describe_instances
20
20
  if result and result["reservationSet"]
21
21
  result["reservationSet"]["item"].each do |item|
22
22
  instance_id = item["instancesSet"]["item"].first["instanceId"]
@@ -31,7 +31,7 @@ module Ec2Methods
31
31
  end
32
32
 
33
33
  def display_addresses
34
- result = @ec2.describe_addresses
34
+ result = ec2.describe_addresses
35
35
  if result and result["addressesSet"]
36
36
  result["addressesSet"]["item"].each do |ip|
37
37
  puts "#{ip["publicIp"]} => #{ip["instanceId"].nil? ? 'unassigned' : ip["instanceId"]}"
@@ -42,7 +42,7 @@ module Ec2Methods
42
42
  end
43
43
 
44
44
  def display_volumes
45
- result = @ec2.describe_volumes
45
+ result = ec2.describe_volumes
46
46
  if result and result["volumeSet"]
47
47
  result["volumeSet"]["item"].each do |vol|
48
48
  instance_id = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okiess-ec2-instance-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Kiessler
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-11 00:00:00 -07:00
13
- default_executable: ec2_instance_manager
12
+ date: 2009-09-14 00:00:00 -07:00
13
+ default_executable: ec2-instance-manager
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thoughtbot-shoulda
@@ -25,7 +25,7 @@ dependencies:
25
25
  description: Launches EC2 instances for multiple AWS accounts
26
26
  email: kiessler@inceedo.com
27
27
  executables:
28
- - ec2_instance_manager
28
+ - ec2-instance-manager
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
@@ -38,15 +38,17 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
- - bin/ec2_instance_manager
41
+ - bin/ec2-instance-manager
42
42
  - config.yml.sample
43
43
  - ec2-instance-manager.gemspec
44
- - lib/ec2_instance_manager.rb
45
- - lib/ec2_methods.rb
44
+ - lib/ec2-instance-manager.rb
45
+ - lib/ec2-instance-manager/ec2_instance_manager.rb
46
+ - lib/ec2-instance-manager/status.rb
46
47
  - test/ec2-instance-manager_test.rb
47
48
  - test/test_helper.rb
48
49
  has_rdoc: false
49
50
  homepage: http://github.com/okiess/ec2-instance-manager
51
+ licenses:
50
52
  post_install_message:
51
53
  rdoc_options:
52
54
  - --charset=UTF-8
@@ -67,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  requirements: []
68
70
 
69
71
  rubyforge_project:
70
- rubygems_version: 1.2.0
72
+ rubygems_version: 1.3.5
71
73
  signing_key:
72
74
  specification_version: 3
73
75
  summary: Simple EC2 Instance Manager