ec2-instance 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. data/README +9 -0
  2. data/lib/ec2-instance.rb +18 -18
  3. data/lib/instance.rb +11 -11
  4. metadata +3 -3
data/README CHANGED
@@ -4,6 +4,8 @@ This is a small set of extensions for common uses of the amazon-ec2 gem.
4
4
 
5
5
  It is intended to be used in processes which are running on actual ec2 instances. It uses the Instance module and other functions in EC2::Base to extract useful information from the hashes returned and to provide useful actions.
6
6
 
7
+ It also includes the Instance class which is more convenient to work with than an elaborate hash, though perhaps not universally more convenient.
8
+
7
9
  == Example
8
10
 
9
11
  With an instance of EC2::Base:
@@ -11,6 +13,13 @@ With an instance of EC2::Base:
11
13
  @ec2.launch_time
12
14
  => Returns a Time object with a value representing the time amazon says this instance launched.
13
15
 
16
+ @ec2.active_instances
17
+ => [#<AWS::EC2::Instancex:0x7fe49d65eeb8 @launch_time="2010-08-23T19:50:35.000Z", @instance_id="i-354b215f", @status="running">, #<AWS::EC2::Instancex:0x7fe49d65ebe8 @launch_time="2010-09-12T07:42:14.000Z", @instance_id="i-3fb69355", @status="running">]
18
+
19
+ == Source
20
+
21
+ Available at http://github.com/bdigital/ec2-instance
22
+
14
23
  == License
15
24
 
16
25
  Offered under the MIT license:
data/lib/ec2-instance.rb CHANGED
@@ -11,16 +11,16 @@ module AWS
11
11
  #
12
12
  # Returns an array of instance ids which have a running or pending status
13
13
  #
14
- def active_instances
15
- instances = []
14
+ def active_instances
15
+ instances = []
16
16
 
17
- parse_instance_set(self.describe_instances).each do |instance|
18
- if instance.status == "running" || instance.status == "pending"
19
- instances.push instance
20
- end
17
+ parse_instance_set(self.describe_instances).each do |instance|
18
+ if instance.status == "running" || instance.status == "pending"
19
+ instances.push instance
20
+ end
21
21
  end
22
-
23
- return instances
22
+
23
+ return instances
24
24
  end
25
25
 
26
26
  #
@@ -39,24 +39,24 @@ module AWS
39
39
  def parse_instance_set(ec2_response_hash)
40
40
  instances = []
41
41
  ec2_response_hash["reservationSet"]["item"].each do |res|
42
- res["instancesSet"]["item"].each do |i|
42
+ res["instancesSet"]["item"].each do |i|
43
43
  instances.push AWS::EC2::Instancex.new({:instance_id => parse_instance_id(i), :status => parse_status(i), :launch_time => parse_launch_time(i)})
44
44
  end
45
- end
46
- return instances
45
+ end
46
+ return instances
47
47
  end
48
48
 
49
49
  def parse_launch_time(instance_hash)
50
- instance_hash["launchTime"]
50
+ Time.parse(instance_hash["launchTime"]).localtime
51
51
  end
52
52
 
53
- def parse_instance_id(instance_hash)
54
- instance_hash["instanceId"]
55
- end
53
+ def parse_instance_id(instance_hash)
54
+ instance_hash["instanceId"]
55
+ end
56
56
 
57
- def parse_status(instance_hash)
58
- instance_hash["instanceState"]["name"]
59
- end
57
+ def parse_status(instance_hash)
58
+ instance_hash["instanceState"]["name"]
59
+ end
60
60
 
61
61
  end
62
62
  end
data/lib/instance.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  module AWS
2
- module EC2
2
+ module EC2
3
3
  # TODO change to instance once upstream namespace resolved
4
- class Instancex
5
-
6
- attr_accessor :instance_id, :launch_time, :status
4
+ class Instancex
7
5
 
8
- def initialize(init_hash = {})
9
- init_hash.each do |k, v|
10
- self.send(k.to_s + "=", v.to_s) unless !self.respond_to?(k.to_s + "=")
11
- end
12
- end
6
+ attr_accessor :instance_id, :launch_time, :status
13
7
 
14
- end
8
+ def initialize(init_hash = {})
9
+ init_hash.each do |k, v|
10
+ self.send(k.to_s + "=", v) unless !self.respond_to?(k.to_s + "=")
11
+ end
12
+ end
15
13
 
16
- end
14
+ end
15
+
16
+ end
17
17
  end
18
18
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-instance
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Berry