ec2ctl 0.8.1 → 0.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e93e145a9a46ba440c2425be62e4cc3165bf141
4
- data.tar.gz: fb692f2bf1eb7c6f7ac199bbcf0f441f4a260b03
3
+ metadata.gz: dce53ee681a100859a592b712e6d350d5b42dc37
4
+ data.tar.gz: 41ae0cdcbd3246c92d6c1c33f714fbf6b83dd9a2
5
5
  SHA512:
6
- metadata.gz: 8c0a2e966e7f14ffeabc54b5cee63c31d77aaadc78f69e1b0c7b16287a45dda5cf6fc180dd0892c8f09486d590e46f1751d803c9a81be7ddb74a68693e88898b
7
- data.tar.gz: 1a1cac4e840229b9bcaebb0a79985ba55359d7537a7f5f3a2b29f0fc15bfcc189e2c9ded055275832fbea56ec65ba887b79e8eb774255894df2cd7092d779010
6
+ metadata.gz: 9cde8643788d2e8342ec3e21b35abf81ce6ee4d159b289de11c48e9f6a9645062424fd973b17a2905994bb1c62b1879ffd573688890a4662d5fd9f745d694d16
7
+ data.tar.gz: a7f825da6dec8d0e74748accf504aa4a126aa48d47e6d5eb3a97bd12ed415a2a5d16fe50be8dc145db8988af92cc9679905e9d5c1e0efbe79f34a7ace228ac22
data/ec2ctl.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = ">= 2.1.0"
21
+ spec.required_ruby_version = ">= 2.0.0"
22
22
 
23
23
  spec.add_dependency "aws-sdk", "~> 2.3"
24
24
  spec.add_dependency "commander", "~> 4.4"
data/lib/ec2ctl/cli.rb CHANGED
@@ -30,7 +30,7 @@ module EC2Ctl
30
30
  c.option "-C", "--count", "(Optional) Display instance attribute stats."
31
31
 
32
32
  c.action do |args, options|
33
- options.default attributes: %w(instance_id tag:Name instance_type public_dns_name state.name)
33
+ options.default attributes: %w(instance_id tag:Name instance_type public_dns_name state.name ssm:ping_status)
34
34
 
35
35
  invoke options do
36
36
  @client.ec2_list
data/lib/ec2ctl/client.rb CHANGED
@@ -92,7 +92,8 @@ module EC2Ctl
92
92
  def ec2_list
93
93
  if @logger
94
94
  if @logger.debug?
95
- @logger.debug ec2_instances: ec2_instances
95
+ @logger.debug ec2_instances: ec2_instances
96
+ @logger.debug ssm_instance_states: ssm_instance_states(ec2_instances.map(&:instance_id))
96
97
  else
97
98
  ec2_instances_summary = if @count
98
99
  @attributes.each_with_object Hash.new do |attribute, attributes_memo|
@@ -116,7 +117,10 @@ module EC2Ctl
116
117
  end
117
118
  end
118
119
 
119
- {ec2_instances: ec2_instances}
120
+ {
121
+ ec2_instances: ec2_instances,
122
+ ssm_instance_states: ssm_instance_states(ec2_instances.map(&:instance_id)),
123
+ }
120
124
  end
121
125
 
122
126
  def ec2_execute
@@ -570,10 +574,22 @@ module EC2Ctl
570
574
  tag = instance.tags.find {|t| t.key == attribute.split(":")[1..-1].join(":")}
571
575
 
572
576
  tag ? tag.value : nil
573
- else
574
- attribute.split(".").map(&:intern).inject instance.data do |_acc, method|
575
- _acc.send method
577
+ when /\Assm:/i
578
+ ssm_instance_state = ssm_instance_states(ec2_instances.map(&:instance_id)).find do |i|
579
+ i.instance_id == instance.instance_id
580
+ end
581
+
582
+ if ssm_instance_state
583
+ query_struct(ssm_instance_state, attribute.split(":")[1..-1].join(":"))
576
584
  end
585
+ else
586
+ query_struct(instance.data, attribute)
587
+ end
588
+ end
589
+
590
+ def query_struct(struct, attribute)
591
+ attribute.split(".").map(&:intern).inject struct do |_acc, method|
592
+ _acc.send method
577
593
  end
578
594
  end
579
595
  end
data/lib/ec2ctl/logger.rb CHANGED
@@ -50,13 +50,17 @@ module EC2Ctl
50
50
  def to_hash(object)
51
51
  case object
52
52
  when Struct
53
- object.each_pair.to_a.map {|a|
54
- [a.first, to_hash(a.last)]
55
- }.to_h
53
+ Hash[
54
+ object.each_pair.to_a.map {|a|
55
+ [a.first, to_hash(a.last)]
56
+ }
57
+ ]
56
58
  when Hash
57
- object.to_a.map {|a|
58
- [a.first, to_hash(a.last)]
59
- }.to_h
59
+ Hash[
60
+ object.to_a.map {|a|
61
+ [a.first, to_hash(a.last)]
62
+ }
63
+ ]
60
64
  when Array, Aws::Resources::Collection
61
65
  object.map {|o| to_hash(o)}
62
66
  when Aws::Resources::Resource
@@ -1,3 +1,3 @@
1
1
  module EC2Ctl
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2ctl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoriki Yamaguchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-28 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
- version: 2.1.0
147
+ version: 2.0.0
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="