ec2-instance 0.0.4 → 0.0.5

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 (3) hide show
  1. data/lib/ec2-instance.rb +23 -11
  2. data/lib/instance.rb +18 -0
  3. metadata +5 -4
data/lib/ec2-instance.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # All methods added to AWS::EC2::Base return values and initiate actions for the machine
3
3
  # on which the process is running.
4
4
  #
5
+ Dir[File.join(File.dirname(__FILE__), '*.rb')].each { |lib| require lib }
5
6
 
6
7
  module AWS
7
8
  module EC2
@@ -10,14 +11,12 @@ module AWS
10
11
  #
11
12
  # Returns an array of instance ids which have a running or pending status
12
13
  #
13
- def active_instance_id_list
14
+ def active_instances
14
15
  instances = []
15
16
 
16
17
  parse_instance_set(self.describe_instances).each do |instance|
17
- status = instance["instancesSet"]["item"].first["instanceState"]["name"]
18
-
19
- if status == "running" || status == "pending"
20
- instances.push instance["instancesSet"]["item"].first["instanceId"]
18
+ if instance.status == "running" || instance.status == "pending"
19
+ instances.push instance
21
20
  end
22
21
  end
23
22
 
@@ -28,24 +27,37 @@ module AWS
28
27
  # Return the launch time of this machine.
29
28
  #
30
29
  def launch_time
31
- instance_data = parse_instance_set(self.describe_instances).detect do |inst|
32
- inst.to_s.include? AWS::EC2::Instance.local_instance_id
30
+ local_instance = parse_instance_set(self.describe_instances).detect do |inst|
31
+ inst.instance_id.eql? AWS::EC2::Instance.local_instance_id
33
32
  end
34
33
 
35
- launched_time = Time.parse(parse_launch_time(instance_data)).localtime
36
- return launched_time
34
+ return local_instance.launch_time
37
35
  end
38
36
 
39
37
  private
40
38
 
41
39
  def parse_instance_set(ec2_response_hash)
42
- ec2_response_hash["reservationSet"]["item"]
40
+ instances = []
41
+ ec2_response_hash["reservationSet"]["item"].each do |res|
42
+ res["instancesSet"]["item"].each do |i|
43
+ instances.push AWS::EC2::Instancex.new({:instance_id => parse_instance_id(i), :status => parse_status(i), :launch_time => parse_launch_time(i)})
44
+ end
45
+ end
46
+ return instances
43
47
  end
44
48
 
45
49
  def parse_launch_time(instance_hash)
46
- instance_hash["instancesSet"]["item"].first["launchTime"]
50
+ instance_hash["launchTime"]
47
51
  end
48
52
 
53
+ def parse_instance_id(instance_hash)
54
+ instance_hash["instanceId"]
55
+ end
56
+
57
+ def parse_status(instance_hash)
58
+ instance_hash["instanceState"]["name"]
59
+ end
60
+
49
61
  end
50
62
  end
51
63
  end
data/lib/instance.rb ADDED
@@ -0,0 +1,18 @@
1
+ module AWS
2
+ module EC2
3
+ # TODO change to instance once upstream namespace resolved
4
+ class Instancex
5
+
6
+ attr_accessor :instance_id, :launch_time, :status
7
+
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
13
+
14
+ end
15
+
16
+ end
17
+ end
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Berry
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-11 00:00:00 -07:00
18
+ date: 2010-10-12 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,6 +42,7 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - lib/ec2-instance.rb
45
+ - lib/instance.rb
45
46
  - README
46
47
  has_rdoc: true
47
48
  homepage: http://github.com/bdigital/ec2-instance