ec2-host 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95a203a17576914b64c580faffb3176c5c9b10f0
4
- data.tar.gz: 6b1ebbdc7be878c17b227900e1a1192c21206d1b
3
+ metadata.gz: 0dc25b078ef99bec51f8d6d3d34c847c12482dab
4
+ data.tar.gz: 942cbde8877b6f20681cd3d098bf0ae04133ea3e
5
5
  SHA512:
6
- metadata.gz: 420df457c6431cfe2f50992f8d541e80d6e4b20a32614917b5ce2f582b13c7e255d3f7f08c9fe74e6bae3c17fd7b5d735da72de3d97d2e1e72fcddedd8b5ac99
7
- data.tar.gz: 84b5ae13c7cec35dfb04b59858722252f261afe58a36b8b743092385109ba4197051066d762a1dabc089b735329e42e9b89f7d2f544372a5409df2f840fb2719
6
+ metadata.gz: 0c5e37497cbc0b41c888ed077542a1b5659631152f0de62678ad2ed5db6df45cfd77d7ab54efa093d603ab3fb638ed2cbacb626e60753d0af3c077e66b11135e
7
+ data.tar.gz: 8bb986e56f4508a652942a16e28ee0ba9f0f110d40e6640d064d866e76c0d983873b9336f4a2d581a81b156849e446e0056aafc2d2f561cee544618b04fa1529
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.0.9 (2015/08/10)
2
+
3
+ Enhancements:
4
+
5
+ * Add --state and --monitoring option
6
+ * Remove terminated instances from list as default
7
+ * Support nested key such as instance.instance_id (as library)
8
+
1
9
  # 0.0.8 (2015/08/10)
2
10
 
3
11
  Enhancements:
data/ec2-host.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "ec2-host"
3
- gem.version = '0.0.8'
3
+ gem.version = '0.0.9'
4
4
  gem.author = ['Naotoshi Seo']
5
5
  gem.email = ['sonots@gmail.com']
6
6
  gem.homepage = 'https://github.com/sonots/ec2-host'
data/lib/ec2/host/cli.rb CHANGED
@@ -30,6 +30,12 @@ class EC2
30
30
  option :instance_id,
31
31
  :type => :array,
32
32
  :desc => "instance_id"
33
+ option :state,
34
+ :type => :array,
35
+ :desc => "state"
36
+ option :monitoring,
37
+ :type => :array,
38
+ :desc => "monitoring"
33
39
  Config.optional_options.each do |opt, tag|
34
40
  option opt, :type => :array, :desc => opt
35
41
  end
@@ -18,9 +18,9 @@ class EC2
18
18
  :instance_id,
19
19
  :private_ip_address,
20
20
  :public_ip_address,
21
- :launch_time,
22
- :state,
23
- :monitoring
21
+ :launch_time
22
+ def state; instance.state.name; end
23
+ def monitoring; instance.monitoring.state; end
24
24
 
25
25
  alias_method :ip, :private_ip_address
26
26
  alias_method :start_date, :launch_time
@@ -41,16 +41,18 @@ class EC2
41
41
  #
42
42
  # @param [Hash] condition search parameters
43
43
  def match?(condition)
44
+ return false if !condition[:state] and terminated? # remove terminated host from lists as default
44
45
  return false unless role_match?(condition)
45
46
  condition = HashUtil.except(condition,
46
47
  :role, :role1, :role2, :role3,
47
48
  :usage, :usage1, :usage2, :usage3
48
49
  )
49
50
  condition.each do |key, values|
50
- if self.send(key).is_a?(Array)
51
- return false unless self.send(key).find {|v| values.include?(v) }
51
+ v = get_value(key)
52
+ if v.is_a?(Array)
53
+ return false unless v.find {|_| values.include?(_) }
52
54
  else
53
- return false unless values.include?(self.send(key))
55
+ return false unless values.include?(v)
54
56
  end
55
57
  end
56
58
  true
@@ -79,13 +81,24 @@ class EC2
79
81
  private_ip_address: private_ip_address,
80
82
  public_ip_address: public_ip_address,
81
83
  launch_time: launch_time,
82
- state: state.name,
83
- monitoring: monitoring.state,
84
+ state: state,
85
+ monitoring: monitoring,
84
86
  ).to_json
85
87
  end
86
88
 
87
89
  # private
88
90
 
91
+ # "instance.instance_id" => self.send("instance").send("instance_id")
92
+ def get_value(key)
93
+ v = self
94
+ key.to_s.split('.').each {|k| v = v.send(k) }
95
+ v
96
+ end
97
+
98
+ def terminated?
99
+ state == "terminated"
100
+ end
101
+
89
102
  def role_match?(condition)
90
103
  # usage is an alias of role
91
104
  if role = (condition[:role] || condition[:usage])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo