ec2-instance 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ec2-instance.rb +17 -1
  2. data/lib/instance.rb +6 -4
  3. metadata +4 -8
data/lib/ec2-instance.rb CHANGED
@@ -23,6 +23,17 @@ module AWS
23
23
  return instances
24
24
  end
25
25
 
26
+ #
27
+ # Return a list of active instances which have a tag value which regexp matches.
28
+ #
29
+ def instances_active_with_tag(tag)
30
+ matches = []
31
+ active_instances.each do |ai|
32
+ matches.push ai unless !ai.match?(tag)
33
+ end
34
+ return matches
35
+ end
36
+
26
37
  #
27
38
  # Return the launch time of this machine.
28
39
  #
@@ -40,7 +51,7 @@ module AWS
40
51
  instances = []
41
52
  ec2_response_hash["reservationSet"]["item"].each do |res|
42
53
  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)})
54
+ instances.push AWS::EC2::Instance.new({:instance_id => parse_instance_id(i), :status => parse_status(i), :launch_time => parse_launch_time(i), :tags => parse_tags(i)})
44
55
  end
45
56
  end
46
57
  return instances
@@ -57,6 +68,11 @@ module AWS
57
68
  def parse_status(instance_hash)
58
69
  instance_hash["instanceState"]["name"]
59
70
  end
71
+
72
+ def parse_tags(instance_hash)
73
+ return [] unless !instance_hash["tagSet"].nil?
74
+ instance_hash["tagSet"]["item"]
75
+ end
60
76
 
61
77
  end
62
78
  end
data/lib/instance.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  module AWS
2
2
  module EC2
3
- # TODO change to instance once upstream namespace resolved
4
- class Instancex
3
+ class Instance
5
4
 
6
- attr_accessor :instance_id, :launch_time, :status
5
+ attr_accessor :instance_id, :launch_time, :status, :tags
7
6
 
8
7
  def initialize(init_hash = {})
9
8
  init_hash.each do |k, v|
@@ -11,8 +10,11 @@ module AWS
11
10
  end
12
11
  end
13
12
 
14
- end
13
+ def match?(tag)
14
+ self.tags.detect { |k, v| v.to_s.match /#{tag}/ }
15
+ end
15
16
 
17
+ end
16
18
  end
17
19
  end
18
20
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-instance
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 6
10
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
11
10
  platform: ruby
12
11
  authors:
13
12
  - Robert Berry
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-12 00:00:00 -07:00
17
+ date: 2011-01-08 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -44,7 +42,7 @@ files:
44
42
  - lib/ec2-instance.rb
45
43
  - lib/instance.rb
46
44
  - README
47
- has_rdoc: true
45
+ has_rdoc: false
48
46
  homepage: http://github.com/bdigital/ec2-instance
49
47
  licenses: []
50
48
 
@@ -58,7 +56,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
56
  requirements:
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
61
- hash: 3
62
59
  segments:
63
60
  - 0
64
61
  version: "0"
@@ -67,7 +64,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
64
  requirements:
68
65
  - - ">="
69
66
  - !ruby/object:Gem::Version
70
- hash: 3
71
67
  segments:
72
68
  - 0
73
69
  version: "0"