ec2-instance-manager 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,13 +2,22 @@
2
2
 
3
3
  Simple EC2 Instance Manager that is able to work with multiple AWS accounts (in config.yml). See config.yml.sample.
4
4
 
5
- Create a "config.yml" in the current directory and run "ec2_instance_manager". You can launch & terminate instances, assign public IP's and
6
- attach volumes.
5
+ Create a "config.yml" in the current directory and run "ec2_instance_manager". You can launch & terminate instances, create whole launch plans, start all launch plan groups or start an individual launch plan group, assign public IP's and attach volumes.
7
6
 
8
7
  Run ec2-instance-manager --help for options and commands.
9
8
 
10
9
  This gem should be considered ALPHA! More features to come...
11
10
 
11
+ == Installation
12
+
13
+ sudo gem install amazon-ec2
14
+
15
+ sudo gem install ec2-instance-manager (Gemcutter)
16
+
17
+ or
18
+
19
+ sudo gem install okiess-ec2-instance-manager (Github)
20
+
12
21
  == Note on Patches/Pull Requests
13
22
 
14
23
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ec2-instance-manager}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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-10-16}
12
+ s.date = %q{2009-10-17}
13
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}
@@ -51,11 +51,14 @@ Gem::Specification.new do |s|
51
51
  s.specification_version = 3
52
52
 
53
53
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<amazon-ec2>, [">= 0"])
54
55
  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
56
  else
57
+ s.add_dependency(%q<amazon-ec2>, [">= 0"])
56
58
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
59
  end
58
60
  else
61
+ s.add_dependency(%q<amazon-ec2>, [">= 0"])
59
62
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
63
  end
61
64
  end
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/output'
4
4
 
5
5
  class Ec2InstanceManager
6
6
  include Status, Launch, Output
7
- VERSION = '0.3'
7
+ VERSION = '0.3.1'
8
8
 
9
9
  attr_reader :config, :customer_key, :options
10
10
 
@@ -30,6 +30,11 @@ class Ec2InstanceManager
30
30
  opts.on( '-l', '--start-launch-plan', 'Starts a launch plan under a config key' ) do
31
31
  options[:start_launch_plan] = true
32
32
  end
33
+
34
+ options[:group] = nil
35
+ opts.on( '-g', '--group LAUNCH_GROUP_NAME', 'Starts a launch plan group under a config key' ) do |group|
36
+ options[:group] = group
37
+ end
33
38
 
34
39
  options[:config] = nil
35
40
  opts.on( '-c', '--config CONFIG_KEY', 'Sets the config key' ) do |key|
@@ -67,7 +72,7 @@ class Ec2InstanceManager
67
72
  end
68
73
 
69
74
  def run
70
- puts "EC2 Instance Manager #{VERSION}"
75
+ puts white("EC2 Instance Manager #{VERSION}")
71
76
  puts
72
77
  unless options[:config]
73
78
  puts "Which customer config do you want to use? (#{config.keys.join(", ")})"
@@ -14,8 +14,8 @@ module Launch
14
14
  instance_state = nil
15
15
  while(instance_state != 'running')
16
16
  instance_state, dns_name = get_instance_state(instance_id)
17
- puts "=> Checking for running state... #{instance_state}"
18
- puts "=> Public DNS: #{dns_name}" if instance_state == 'running'
17
+ puts "=> Checking for running state... #{output_running_state(instance_state)}"
18
+ puts "=> Public DNS: #{white(dns_name)}" if instance_state == 'running'
19
19
  sleep 10 unless instance_state == 'running'
20
20
  end
21
21
 
@@ -49,15 +49,14 @@ module Launch
49
49
  instances = get_running_instances_list
50
50
  if instances and instances.any?
51
51
  puts
52
- puts red("Warning: Terminating all instances: #{instances.join(", ")}")
53
- puts red("Please cancel within the next 5 seconds...")
52
+ cancel_message(instances)
54
53
  sleep 5
55
54
  ec2.terminate_instances(:instance_id => instances)
56
55
  puts
57
- puts "All instances are going to terminate now."
56
+ puts white("All instances are going to terminate now.")
58
57
  else
59
58
  puts
60
- puts "No running instances."
59
+ puts white("No running instances.")
61
60
  end
62
61
  end
63
62
 
@@ -66,22 +65,39 @@ module Launch
66
65
  puts
67
66
  puts "Your Launch Plan:"
68
67
  if config[@customer_key]["launch_plan"] and config[@customer_key]["launch_plan"].any?
69
- config[@customer_key]["launch_plan"].keys.sort.each do |launch_plan_group|
70
- puts
71
- puts "Group: #{launch_plan_group}"
72
- if config[@customer_key]["launch_plan"][launch_plan_group] and config[@customer_key]["launch_plan"][launch_plan_group].any?
73
- config[@customer_key]["launch_plan"][launch_plan_group].keys.each do |ami_id|
74
- puts "#{ami_id} => #{config[@customer_key]["launch_plan"][launch_plan_group][ami_id]} Instances to launch"
75
- ami_ids_to_launch << [ami_id, config[@customer_key]["launch_plan"][launch_plan_group][ami_id]]
68
+
69
+ launch_plan_groups = config[@customer_key]["launch_plan"].keys.sort
70
+
71
+ if self.options[:group]
72
+ puts
73
+ puts "Existing groups: #{launch_plan_groups.join(", ")}"
74
+ if launch_plan_groups.include?(self.options[:group])
75
+ puts "Targeted Group: #{self.options[:group]}"
76
+ config[@customer_key]["launch_plan"][self.options[:group]].each do |ami_id|
77
+ puts "#{ami_id[0]} => #{ami_id[1]} Instances to launch"
78
+ ami_ids_to_launch << [ami_id[0], ami_id[1]]
76
79
  end
77
80
  else
78
- puts "No Ami Id's to launch defined."
81
+ puts white("Targeted Launch plan group '#{self.options[:group]}' not found.")
82
+ end
83
+ else
84
+ launch_plan_groups.each do |launch_plan_group|
85
+ puts
86
+ puts "Group: #{launch_plan_group}"
87
+ if config[@customer_key]["launch_plan"][launch_plan_group] and config[@customer_key]["launch_plan"][launch_plan_group].any?
88
+ config[@customer_key]["launch_plan"][launch_plan_group].keys.each do |ami_id|
89
+ puts "#{ami_id} => #{config[@customer_key]["launch_plan"][launch_plan_group][ami_id]} Instances to launch"
90
+ ami_ids_to_launch << [ami_id, config[@customer_key]["launch_plan"][launch_plan_group][ami_id]]
91
+ end
92
+ else
93
+ puts white("No Ami Id's to launch defined.")
94
+ end
79
95
  end
80
96
  end
81
97
 
82
98
  puts
83
99
  puts red("Warning: Now launching your plan...")
84
- puts red("Please cancel within the next 5 seconds...")
100
+ puts red("Please cancel within the next 5 seconds if this isn't want you want...")
85
101
  puts
86
102
  sleep 5
87
103
 
@@ -92,9 +108,9 @@ module Launch
92
108
  }
93
109
  end
94
110
 
95
- puts "All instances are launching now..."
111
+ puts white("All instances are launching now...")
96
112
  else
97
- puts "No launch groups defined."
113
+ puts white("No launch plan groups defined.")
98
114
  end
99
115
  end
100
116
 
@@ -2,7 +2,7 @@ module Output
2
2
  def output_running_state(running_state)
3
3
  if running_state == 'running'
4
4
  green(running_state)
5
- elsif running_state == 'terminated'
5
+ elsif running_state == 'terminated' or running_state == 'shutting-down'
6
6
  red(running_state)
7
7
  elsif running_state == 'pending'
8
8
  yellow(running_state)
@@ -11,6 +11,11 @@ module Output
11
11
  end
12
12
  end
13
13
 
14
+ def cancel_message(instances)
15
+ puts red("Warning: Terminating all instances: #{instances.join(", ")}")
16
+ puts red("Please cancel within the next 5 seconds if this isn't want you want...")
17
+ end
18
+
14
19
  def green(str)
15
20
  "\033[32m#{str}\033[0m"
16
21
  end
@@ -22,4 +27,8 @@ module Output
22
27
  def yellow(str)
23
28
  "\033[33m#{str}\033[0m"
24
29
  end
30
+
31
+ def white(str)
32
+ "\033[1m#{str}\033[0m"
33
+ end
25
34
  end
@@ -9,9 +9,9 @@ module Status
9
9
  def display_ami_ids(owner_id = nil)
10
10
  result = ec2.describe_images(:owner_id => owner_id || config[@customer_key]['amazon_account_number'])
11
11
  if result and result["imagesSet"]
12
- result["imagesSet"]["item"].each {|image| puts "#{image["imageId"]} - #{image["imageLocation"]}"}
12
+ result["imagesSet"]["item"].each {|image| puts "#{white(image["imageId"])} - #{image["imageLocation"]}"}
13
13
  else
14
- puts "No images."
14
+ puts white("No images.")
15
15
  end
16
16
  end
17
17
 
@@ -23,10 +23,10 @@ module Status
23
23
  ami_id = item["instancesSet"]["item"].first["imageId"]
24
24
  running_state = item["instancesSet"]["item"].first["instanceState"]["name"]
25
25
  dns_name = item["instancesSet"]["item"].first["dnsName"]
26
- puts "Instance Id: #{instance_id} - #{output_running_state(running_state)} (AMI Id: #{ami_id}) #{dns_name}"
26
+ puts "Instance Id: #{white(instance_id)} - #{output_running_state(running_state)} (AMI Id: #{white(ami_id)}) #{dns_name}"
27
27
  end
28
28
  else
29
- puts "No instances."
29
+ puts white("No instances.")
30
30
  end
31
31
  end
32
32
 
@@ -34,10 +34,10 @@ module Status
34
34
  result = ec2.describe_addresses
35
35
  if result and result["addressesSet"]
36
36
  result["addressesSet"]["item"].each do |ip|
37
- puts "#{ip["publicIp"]} => #{ip["instanceId"].nil? ? 'unassigned' : ip["instanceId"]}"
37
+ puts "#{white(ip["publicIp"])} => #{ip["instanceId"].nil? ? 'unassigned' : ip["instanceId"]}"
38
38
  end
39
39
  else
40
- puts "No addresses."
40
+ puts white("No addresses.")
41
41
  end
42
42
  end
43
43
 
@@ -49,10 +49,10 @@ module Status
49
49
  if vol["attachmentSet"]
50
50
  instance_id = vol["attachmentSet"]["item"].first["instanceId"]
51
51
  end
52
- puts "#{vol["volumeId"]} (Size: #{vol["size"]} / Zone: #{vol["availabilityZone"]}) - #{vol["status"]} => #{instance_id.nil? ? 'unassigned' : instance_id}"
52
+ puts "#{white(vol["volumeId"])} (Size: #{vol["size"]} / Zone: #{vol["availabilityZone"]}) - #{vol["status"]} => #{instance_id.nil? ? 'unassigned' : instance_id}"
53
53
  end
54
54
  else
55
- puts "No volumes."
55
+ puts white("No volumes.")
56
56
  end
57
57
  end
58
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-instance-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Kiessler
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 +02:00
12
+ date: 2009-10-17 00:00:00 +02:00
13
13
  default_executable: ec2-instance-manager
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: amazon-ec2
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: thoughtbot-shoulda
17
27
  type: :development