train-awsssm 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: ef5a20eca471f5a767da71380b22425fd4676d3a435b0da83077cd3d14fc2c2f
4
- data.tar.gz: 97f8b4e0d98b1a20f23b58df148696dceda51843da9fdacd51b274fbf3c94af1
3
+ metadata.gz: 84b93f6b8c8e42c234b406aaeede3112f9eb8a5d2bb8f25973ca6bac555ebe91
4
+ data.tar.gz: fb7af1a14b231cffdd3de53b52912fc06cd820c683783f4ed2c45415eef157fb
5
5
  SHA512:
6
- metadata.gz: 19cb91506eb8d0b5db6eeb49f6e94ab071616dca46ebeeac187065958a954d8ef9c2e7a80c2e3b72de3d914f252132e25f75e6b2b43e08467fe9eddb2c230b54
7
- data.tar.gz: c81a2c12459fc95e44c451cf7be89f1c1723ce9820c2790e7963b2676384a8623234f84657d4ddbce8316a03926ee73402bc5640bb5b01cd2d33dfcd3c15060e
6
+ metadata.gz: 39739ed9e732f26a55ac2a748b932e35c74f94aaa3de0a026d25563ef11b376277ed261bfe1a3bb7e2da3fc0260bf3e8f37b619b530a78ee0ba630f5d7149d29
7
+ data.tar.gz: fe0b339242ef4ee3ca7f88d43eba25bd148d8a080db8530cf7a4e96c94ea7db1d4bb6c2878c989b848e426b6b1c46878619aff6c429bdeac60523cacaaff99eb
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Version 0.2.1
6
+
7
+ - Fix EC2 instance enumeration to use paging
8
+
5
9
  ## Version 0.2.0
6
10
 
7
11
  - Add more parameter and status checks
data/README.md CHANGED
@@ -25,6 +25,7 @@ You can build and install this gem on your local system as well via a Rake task:
25
25
  | `execution_timeout` | Maximum time until timeout | 60 |
26
26
  | `recheck_invocation` | Interval of rechecking AWS command invocation | 1.0 |
27
27
  | `recheck_execution` | Interval of rechecking completion of command | 1.0 |
28
+ | `instance_pagesize` | Paging size for EC2 instance retrieval | 100 |
28
29
 
29
30
  ## Limitations
30
31
 
@@ -7,7 +7,7 @@ module TrainPlugins
7
7
  module AWSSSM
8
8
  class Connection < Train::Plugins::Transport::BaseConnection
9
9
  attr_reader :instance_id, :options
10
- attr_writer :ssm, :ec2
10
+ attr_writer :ssm, :ec2, :instances
11
11
 
12
12
  def initialize(options)
13
13
  super(options)
@@ -85,8 +85,6 @@ module TrainPlugins
85
85
  def resolve_instance_id(address)
86
86
  logger.debug format("[AWS-SSM] Trying to resolve address %s", address)
87
87
 
88
- instances = ec2.describe_instances.reservations.collect { |r| r.instances.first }
89
-
90
88
  # Resolve, if DNS name and not Amazon default
91
89
  if dns_name?(address) && !amazon_dns?(address)
92
90
  address = Resolv.getaddress(address)
@@ -112,6 +110,28 @@ module TrainPlugins
112
110
  raise ArgumentError, format("Error looking up Instance ID for %s: %s", address, e.message)
113
111
  end
114
112
 
113
+ # List up EC2 instances in the account.
114
+ #
115
+ # @param [Boolean] cache Cache results
116
+ # @return [Array] List of instances
117
+ # @todo Implement paging
118
+ def instances(caching: true)
119
+ return @instances unless @instances.nil? || !caching
120
+
121
+ results = []
122
+
123
+ ec2_instances = ec2.describe_instances(max_results: options[:instance_pagesize])
124
+ loop do
125
+ results.concat ec2_instances.reservations.map(&:instances).flatten
126
+
127
+ break unless ec2_instances.next_token
128
+
129
+ ec2_instances = ec2.describe_instances(max_results: options[:instance_pagesize], next_token: ec2_instances.next_token)
130
+ end
131
+
132
+ @instances = results
133
+ end
134
+
115
135
  # Check if this is an IP address
116
136
  #
117
137
  # @param [String] address Host, IP address or other input
@@ -11,6 +11,7 @@ module TrainPlugins
11
11
  option :execution_timeout, default: 60.0
12
12
  option :recheck_invocation, default: 1.0
13
13
  option :recheck_execution, default: 1.0
14
+ option :instance_pagesize, default: 100
14
15
 
15
16
  def connection(_instance_opts = nil)
16
17
  @connection ||= TrainPlugins::AWSSSM::Connection.new(@options)
@@ -1,5 +1,5 @@
1
1
  module TrainPlugins
2
2
  module AWSSSM
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "0.2.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train-awsssm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Heinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2020-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump