sproutr 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,7 +37,7 @@ class Sproutr < Thor
37
37
  end
38
38
  new_config = clone_ami_config(@ec2.call("DescribeInstances", "InstanceId" => ami_to_clone)["reservationSet"][0]["instancesSet"][0], ami_id)
39
39
  until ami_done?(ami_id) do
40
- say "Ami has not completed so this clone can not yet be started. Sleeping 30 seconds", :red
40
+ say "Ami creation has not completed so this clone can not yet be started. Sleeping 30 seconds", :red
41
41
  sleep 30
42
42
  end
43
43
  new_instance = invoke_launch(new_config)
@@ -99,6 +99,18 @@ into a singluar raid array (Required): "
99
99
  end
100
100
  end
101
101
 
102
+ desc "grow", "Grow a machine's 'hardware' resources"
103
+ method_option :ami, :type => :array, :required => true
104
+ method_option :size, :type => :string, :required => true
105
+
106
+ def grow
107
+ options[:ami].each do |ami|
108
+ Instance::call_on(@ec2, "StopInstances", ami)
109
+ @ec2.call "ModifyInstanceAttribute", "InstanceId" => ami, "InstanceType" => options[:size]
110
+ Instance::call_on(@ec2, "StartInstances", ami)
111
+ end
112
+ end
113
+
102
114
  desc "launch", "launch an instance from the specified config directory"
103
115
  method_option :config_file, :type => :string, :required => true
104
116
 
@@ -122,7 +134,12 @@ into a singluar raid array (Required): "
122
134
  ami_table = table do |a|
123
135
  a.headings = 'Name', 'AMI Id', 'Type', 'State', 'Size', 'Architecture', 'Public?', 'Description'
124
136
  @ami_images.each do |ami|
125
- a << [ami.name, ami.imageId, ami.rootDeviceType, ami.imageState, ami.blockDeviceMapping[0]["ebs"]["volumeSize"],
137
+ begin
138
+ ami_size = ami.blockDeviceMapping.first["ebs"]["volumeSize"]
139
+ rescue
140
+ ami_size = "unknown"
141
+ end
142
+ a << [ami.name, ami.imageId, ami.rootDeviceType, ami.imageState, ami_size,
126
143
  ami.architecture, ami.isPublic, ami.description]
127
144
  end
128
145
  end
@@ -136,6 +153,7 @@ into a singluar raid array (Required): "
136
153
  instance_table = table do |i|
137
154
  i.headings = 'Name', 'Instance Id', 'Status', 'ip Address', 'Instance Type', 'AMI Image', 'Availablity Zone', 'DNS Cname'
138
155
  instances.each do |instance|
156
+ p instance.inspect
139
157
  i << [((instance.tagSet.nil?) ? "Name Not Set" : instance.tagSet[0]["value"]),
140
158
  instance.instanceId, instance.instanceState["name"], instance.ipAddress,
141
159
  instance.instanceType, instance.imageId, instance.placement["availabilityZone"], instance.dnsName]
@@ -157,11 +175,31 @@ into a singluar raid array (Required): "
157
175
  puts snapshots_table
158
176
  end
159
177
 
178
+ desc "migrate", "Migrate from one Availability Zone to another, requires --ami= [multiple apis supported separated by space] and --target="
179
+ method_option :ami, :type => :array, :require => true
180
+ method_option :target, :type => :string, :require => true
181
+
182
+ def migrate
183
+ ami_id = @ec2.call("CreateImage", "InstanceId" => ami_to_clone, "Name" => "AMI-#{options["ami"]}-#{Time.now.to_i}",
184
+ "Description" => "AMI created from #{options["ami"]} at #{Time.now}", "NoReboot" => "true")["imageId"]
185
+
186
+ current_config = @ec2.call("DescribeInstances", "InstanceId" => options["ami"])["reservationSet"][0]["instancesSet"][0]
187
+ new_config = clone_ami_config(current_config, ami_id)
188
+
189
+ until ami_done?(ami_id) do
190
+ say "Ami creation has not completed so the new instance can not yet be started. Sleeping 30 seconds", :red
191
+ sleep 30
192
+ end
193
+ new_instance = invoke_launch(validate_launch_config(new_config, options[:target]))
194
+ say "Created and started #{new_instance}", :green
195
+ tag_instance(new_instance, options[:tags]) if options[:tags]
196
+ end
197
+
160
198
  desc "restart", "Restart the specified instance(s), requires --ami="
161
199
  method_option :ami, :type => :array, :required => true
162
200
 
163
201
  def restart
164
- options[:ami].each { |ami| Instance::call_on("RebootInstances", ami) }
202
+ options[:ami].each { |ami| Instance::call_on(@ec2, "RebootInstances", ami) }
165
203
  end
166
204
 
167
205
  desc "snapshot", "Create snapshot"
@@ -180,14 +218,14 @@ into a singluar raid array (Required): "
180
218
  method_option :ami, :type => :array, :required => true
181
219
 
182
220
  def start
183
- options[:ami].each { |ami| Instance::call_on("StartInstances", ami) }
221
+ options[:ami].each { |ami| Instance::call_on(@ec2, "StartInstances", ami) }
184
222
  end
185
223
 
186
224
  desc "stop", "Stop the specified instance(s), requires --ami="
187
225
  method_option :ami, :type => :array, :required => true
188
226
 
189
227
  def stop
190
- options[:ami].each { |ami| Instance::call_on("StopInstances", ami) if yes? "Do you really want to stop the #{instance} instance? ", :red }
228
+ options[:ami].each { |ami| Instance::call_on(@ec2, "StopInstances", ami) if yes? "Do you really want to stop the #{ami} instance? ", :red }
191
229
  end
192
230
 
193
231
 
@@ -197,7 +235,7 @@ into a singluar raid array (Required): "
197
235
  def terminate
198
236
  options[:ami].each do |ami|
199
237
  verify = ask "Do you really want to terminate the #{ami} instance? ", :red
200
- Instance::call_on("TerminateInstances", ami) if verify.downcase == "y" || verify.downcase == "yes"
238
+ Instance::call_on(@ec2, "TerminateInstances", ami) if verify.downcase == "y" || verify.downcase == "yes"
201
239
  end
202
240
  end
203
241
 
@@ -205,6 +243,10 @@ into a singluar raid array (Required): "
205
243
  method_option :ami, :type => :array, :required => true
206
244
  alias :destroy :terminate
207
245
 
246
+ desc "shrink", "Alias to grow"
247
+ method_option :ami, :type => :array, :required => true
248
+ method_option :size, :type => :string, :require => true
249
+ alias :shrink :terminate
208
250
 
209
251
  desc "list_snapshots", "Alias to list_snapshots"
210
252
  alias :list_snapshot :list_snapshots
@@ -8,8 +8,9 @@ class Instance
8
8
  end
9
9
  end
10
10
 
11
- def self.call_on(action, ami)
12
- @ec2.call action, "InstanceId" => ami
11
+ def self.call_on(ec2, action, ami)
12
+
13
+ ec2.call action, "InstanceId" => ami
13
14
  end
14
15
 
15
16
  def method_missing(sym, *args, &block)
@@ -21,14 +21,15 @@ def invoke_launch(config)
21
21
  response["instancesSet"].first["instanceId"]
22
22
  end
23
23
 
24
- def validate_launch_config(config)
24
+ def validate_launch_config(config, availability_zone = nil)
25
25
  instance_options = {
26
26
  "SecurityGroup.#" => config["groups"] || [],
27
27
  "MinCount" => "1",
28
28
  "MaxCount" => "1",
29
29
  "KeyName" => config["key_name"] || "Production",
30
30
  "InstanceType" => config["instance_type"] || "m1.small",
31
- "ImageId" => config["ami"]
31
+ "ImageId" => config["ami"],
32
+ "AvailabilityZone" => availability_zone || config["placement"]["availabilityZone"]
32
33
  }
33
34
 
34
35
  if config["volumes"]
metadata CHANGED
@@ -1,149 +1,146 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sproutr
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
4
5
  prerelease:
5
- version: 0.2.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Kevin Poorman
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-24 00:00:00 -04:00
12
+ date: 2011-11-04 00:00:00.000000000 -04:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: swirl
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70273739915900 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
19
+ requirements:
22
20
  - - ~>
23
- - !ruby/object:Gem::Version
21
+ - !ruby/object:Gem::Version
24
22
  version: 1.7.5
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: thor
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70273739915900
26
+ - !ruby/object:Gem::Dependency
27
+ name: thor
28
+ requirement: &70273739915440 !ruby/object:Gem::Requirement
31
29
  none: false
32
- requirements:
30
+ requirements:
33
31
  - - ~>
34
- - !ruby/object:Gem::Version
32
+ - !ruby/object:Gem::Version
35
33
  version: 0.14.6
36
34
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: terminal-table
40
35
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70273739915440
37
+ - !ruby/object:Gem::Dependency
38
+ name: terminal-table
39
+ requirement: &70273739914960 !ruby/object:Gem::Requirement
42
40
  none: false
43
- requirements:
41
+ requirements:
44
42
  - - ~>
45
- - !ruby/object:Gem::Version
43
+ - !ruby/object:Gem::Version
46
44
  version: 1.4.2
47
45
  type: :runtime
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: awesome_print
51
46
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70273739914960
48
+ - !ruby/object:Gem::Dependency
49
+ name: awesome_print
50
+ requirement: &70273739914460 !ruby/object:Gem::Requirement
53
51
  none: false
54
- requirements:
52
+ requirements:
55
53
  - - ~>
56
- - !ruby/object:Gem::Version
54
+ - !ruby/object:Gem::Version
57
55
  version: 0.3.2
58
56
  type: :runtime
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
61
- name: json
62
57
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *70273739914460
59
+ - !ruby/object:Gem::Dependency
60
+ name: json
61
+ requirement: &70273739914060 !ruby/object:Gem::Requirement
64
62
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
69
67
  type: :runtime
70
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
72
- name: rspec
73
68
  prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *70273739914060
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &70273739913500 !ruby/object:Gem::Requirement
75
73
  none: false
76
- requirements:
74
+ requirements:
77
75
  - - ~>
78
- - !ruby/object:Gem::Version
76
+ - !ruby/object:Gem::Version
79
77
  version: 2.5.0
80
78
  type: :development
81
- version_requirements: *id006
82
- - !ruby/object:Gem::Dependency
83
- name: rspec-core
84
79
  prerelease: false
85
- requirement: &id007 !ruby/object:Gem::Requirement
80
+ version_requirements: *70273739913500
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec-core
83
+ requirement: &70273739912940 !ruby/object:Gem::Requirement
86
84
  none: false
87
- requirements:
85
+ requirements:
88
86
  - - ~>
89
- - !ruby/object:Gem::Version
87
+ - !ruby/object:Gem::Version
90
88
  version: 2.5.0
91
89
  type: :development
92
- version_requirements: *id007
93
- - !ruby/object:Gem::Dependency
94
- name: rspec-expectations
95
90
  prerelease: false
96
- requirement: &id008 !ruby/object:Gem::Requirement
91
+ version_requirements: *70273739912940
92
+ - !ruby/object:Gem::Dependency
93
+ name: rspec-expectations
94
+ requirement: &70273739912440 !ruby/object:Gem::Requirement
97
95
  none: false
98
- requirements:
96
+ requirements:
99
97
  - - ~>
100
- - !ruby/object:Gem::Version
98
+ - !ruby/object:Gem::Version
101
99
  version: 2.5.0
102
100
  type: :development
103
- version_requirements: *id008
104
- - !ruby/object:Gem::Dependency
105
- name: rspec-mocks
106
101
  prerelease: false
107
- requirement: &id009 !ruby/object:Gem::Requirement
102
+ version_requirements: *70273739912440
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec-mocks
105
+ requirement: &70273739911900 !ruby/object:Gem::Requirement
108
106
  none: false
109
- requirements:
107
+ requirements:
110
108
  - - ~>
111
- - !ruby/object:Gem::Version
109
+ - !ruby/object:Gem::Version
112
110
  version: 2.5.0
113
111
  type: :development
114
- version_requirements: *id009
115
- - !ruby/object:Gem::Dependency
116
- name: vcr
117
112
  prerelease: false
118
- requirement: &id010 !ruby/object:Gem::Requirement
113
+ version_requirements: *70273739911900
114
+ - !ruby/object:Gem::Dependency
115
+ name: vcr
116
+ requirement: &70273739911360 !ruby/object:Gem::Requirement
119
117
  none: false
120
- requirements:
118
+ requirements:
121
119
  - - ~>
122
- - !ruby/object:Gem::Version
120
+ - !ruby/object:Gem::Version
123
121
  version: 1.6.0
124
122
  type: :development
125
- version_requirements: *id010
126
- - !ruby/object:Gem::Dependency
127
- name: webmock
128
123
  prerelease: false
129
- requirement: &id011 !ruby/object:Gem::Requirement
124
+ version_requirements: *70273739911360
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: &70273739910780 !ruby/object:Gem::Requirement
130
128
  none: false
131
- requirements:
129
+ requirements:
132
130
  - - ~>
133
- - !ruby/object:Gem::Version
131
+ - !ruby/object:Gem::Version
134
132
  version: 1.6.2
135
133
  type: :development
136
- version_requirements: *id011
134
+ prerelease: false
135
+ version_requirements: *70273739910780
137
136
  description: Elegant, interactive EC2 Management
138
- email:
137
+ email:
139
138
  - kjp@brightleafsoftware.com
140
- executables:
139
+ executables:
141
140
  - sproutr
142
141
  extensions: []
143
-
144
142
  extra_rdoc_files: []
145
-
146
- files:
143
+ files:
147
144
  - LICENSE
148
145
  - README.md
149
146
  - lib/sproutr/ami.rb
@@ -156,30 +153,27 @@ files:
156
153
  has_rdoc: true
157
154
  homepage: https://github.com/noeticpenguin/sproutr
158
155
  licenses: []
159
-
160
156
  post_install_message:
161
157
  rdoc_options: []
162
-
163
- require_paths:
158
+ require_paths:
164
159
  - lib
165
- required_ruby_version: !ruby/object:Gem::Requirement
160
+ required_ruby_version: !ruby/object:Gem::Requirement
166
161
  none: false
167
- requirements:
168
- - - ">="
169
- - !ruby/object:Gem::Version
170
- version: "0"
171
- required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
167
  none: false
173
- requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- version: "0"
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
177
172
  requirements: []
178
-
179
173
  rubyforge_project:
180
174
  rubygems_version: 1.6.2
181
175
  signing_key:
182
176
  specification_version: 2
183
- summary: An Ec2 management system designed to help you quickly define a new instance, create N clones of said instance and start/stop them
177
+ summary: An Ec2 management system designed to help you quickly define a new instance,
178
+ create N clones of said instance and start/stop them
184
179
  test_files: []
185
-