some 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/some +10 -0
  3. data/lib/some.rb +50 -0
  4. metadata +5 -5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/bin/some CHANGED
@@ -61,6 +61,7 @@ class CLI < Thor
61
61
  end
62
62
  end
63
63
  some.terminate(inst[:instance_id])
64
+ some.wait_to_terminate(inst[:instance_id])
64
65
  puts "#{inst[:hostname] || inst[:instance_id]} scheduled for termination"
65
66
  end
66
67
 
@@ -78,6 +79,15 @@ class CLI < Thor
78
79
  puts "port #{port} scheduled for open"
79
80
  end
80
81
 
82
+ desc "reset", "delete all the resources created by some (instances, security group, key pair)"
83
+ def reset
84
+ some.list.each do |inst|
85
+ terminate(inst[:instance_id])
86
+ end
87
+ task("Delete security group") { some.delete_security_group }
88
+ task("Delete key pair") { some.delete_keypair }
89
+ end
90
+
81
91
  no_tasks do
82
92
  def some
83
93
  @some ||= Some.new
data/lib/some.rb CHANGED
@@ -11,6 +11,7 @@ class Some
11
11
  create_keypair unless File.exists? keypair_file
12
12
 
13
13
  create_security_group
14
+ wait_for_security_group
14
15
  open_firewall(22)
15
16
 
16
17
  result = api.run_instances(
@@ -89,6 +90,7 @@ class Some
89
90
 
90
91
  instances = []
91
92
  result.reservationSet.item.each do |r|
93
+ next unless r.groupSet.nil? || r.groupSet.item.first.groupId == 'something'
92
94
  r.instancesSet.item.each do |item|
93
95
  instances << {
94
96
  :instance_id => item.instanceId,
@@ -161,6 +163,16 @@ class Some
161
163
  end
162
164
  end
163
165
 
166
+ def wait_to_terminate(instance_id)
167
+ raise ArgumentError unless instance_id
168
+ loop do
169
+ unless inst = instance_info(instance_id)
170
+ break
171
+ end
172
+ sleep 5
173
+ end
174
+ end
175
+
164
176
  def wait_for_ssh(hostname)
165
177
  raise ArgumentError unless hostname
166
178
  loop do
@@ -240,6 +252,16 @@ class Some
240
252
  File.chmod 0600, keypair_file
241
253
  end
242
254
 
255
+ def delete_keypair
256
+ api.delete_key_pair(:key_name => "something") if find_keypair
257
+ File.unlink(keypair_file) if File.exists? keypair_file
258
+ "done"
259
+ end
260
+
261
+ def find_keypair
262
+ api.describe_key_pairs.keySet.item.find {|keypair| keypair.keyName == 'something' }
263
+ end
264
+
243
265
  def create_security_group
244
266
  api.create_security_group(:group_name => 'something', :group_description => 'Something')
245
267
  rescue NIFTY::ResponseError => e
@@ -248,6 +270,34 @@ class Some
248
270
  end
249
271
  end
250
272
 
273
+ def wait_for_security_group
274
+ loop do
275
+ if security_group = find_security_group
276
+ if security_group.groupStatus == 'applied'
277
+ break
278
+ end
279
+ end
280
+ sleep 5
281
+ end
282
+ end
283
+
284
+ def delete_security_group
285
+ return unless find_security_group
286
+ api.delete_security_group(:group_name => 'something')
287
+ "done"
288
+ end
289
+
290
+ def find_security_group
291
+ group_info = api.describe_security_groups(:group_name => 'something').securityGroupInfo
292
+ if group_info
293
+ group_info.item.find {|group| group.groupName }
294
+ else
295
+ nil
296
+ end
297
+ rescue NIFTY::ResponseError => e
298
+ nil
299
+ end
300
+
251
301
  def open_firewall(port)
252
302
  target = {
253
303
  :group_name => 'something',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: some
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nifty-cloud-sdk
16
- requirement: &75338600 !ruby/object:Gem::Requirement
16
+ requirement: &197055520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.11.beta1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75338600
24
+ version_requirements: *197055520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &75337980 !ruby/object:Gem::Requirement
27
+ requirement: &197055000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *75337980
35
+ version_requirements: *197055000
36
36
  description: sumo clone for NIFTY Cloud
37
37
  email: tidnlyam@gmail.com
38
38
  executables: