MovableInkAWS 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 4a003b444c6b5e150a6420624b2a52de2484738d4cce518081435bce1051dabe
4
- data.tar.gz: 5fd9b8e1f6954aa4b3031c7a7fe808bfa158c698e0f16f5c23f6a00e64f9cfb0
3
+ metadata.gz: 1563396dc437243706adf250a3ab303f3e089c20d37b96f2e46e84389a099513
4
+ data.tar.gz: f59d9ad7bbea43ac3b2b18b1bf2fc6524aa0088bdfbe97e673dcfdb2bb548676
5
5
  SHA512:
6
- metadata.gz: baa941aa3b93e8fefe7fd7be692551e85b8de4f58c3d3b5e720305066ed34f7d867481f5e82ed42b60b5a611f78fae5c80496825683c528de641c9594f3c3c91
7
- data.tar.gz: 43e9683d74acebb93296b42f8bc83c208d805a39ba4e4b87182ad0c25d669687589380d81219bd90a9a0620abbfb77979e4fa7def095768fc2c5cca7d8a14ac4
6
+ metadata.gz: fa44c9970ef0d0522c38c4af1824545f812ea0c2d5f796ae43d328539afe4e4a2ecdc3074925d6a68637a19c9162e600b9b2896e8812a806e0ef85e9f96d515a
7
+ data.tar.gz: 2f54162fa8a88a9293cacd11281d999e9f36e885f34389fe90349de5ddb173d4ff6f052e3f940878d98eb30a62c0f469ca54339908b0583555ae4c530262ffcf
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- MovableInkAWS (0.3.5)
4
+ MovableInkAWS (0.5.0)
5
5
  aws-sdk (= 2.11.240)
6
+ aws-sigv4 (~> 1.1)
7
+ httparty (= 0.16.3)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
@@ -18,7 +20,14 @@ GEM
18
20
  aws-sigv4 (1.1.0)
19
21
  aws-eventstream (~> 1.0, >= 1.0.2)
20
22
  diff-lcs (1.3)
23
+ httparty (0.16.3)
24
+ mime-types (~> 3.0)
25
+ multi_xml (>= 0.5.2)
21
26
  jmespath (1.4.0)
27
+ mime-types (3.2.2)
28
+ mime-types-data (~> 3.2015)
29
+ mime-types-data (3.2019.0331)
30
+ multi_xml (0.6.0)
22
31
  rspec (3.6.0)
23
32
  rspec-core (~> 3.6.0)
24
33
  rspec-expectations (~> 3.6.0)
@@ -41,4 +50,4 @@ DEPENDENCIES
41
50
  rspec (~> 3.6)
42
51
 
43
52
  BUNDLED WITH
44
- 1.16.6
53
+ 1.17.1
@@ -91,14 +91,15 @@ module MovableInk
91
91
  @me ||= all_instances.select{|instance| instance.instance_id == instance_id}
92
92
  end
93
93
 
94
- def instances(role:, region: my_region, availability_zone: nil, exact_match: false)
94
+ def instances(role:, exclude_roles: [], region: my_region, availability_zone: nil, exact_match: false)
95
95
  instances = all_instances(region: region).select { |instance|
96
96
  instance.tags.select{ |tag| tag.key == 'mi:roles' }.detect { |tag|
97
97
  roles = tag.value.split(/\s*,\s*/)
98
98
  if exact_match
99
99
  roles == [role]
100
100
  else
101
- roles.include?(role) && !roles.include?('decommissioned')
101
+ exclude_roles.push('decommissioned')
102
+ roles.include?(role) && !roles.any? { |role| exclude_roles.include?(role) }
102
103
  end
103
104
  }
104
105
  }
@@ -124,12 +125,12 @@ module MovableInk
124
125
  instances.map(&:private_ip_address)
125
126
  end
126
127
 
127
- def instance_ip_addresses_by_role(role:, region: my_region, availability_zone: nil, exact_match: false)
128
- private_ip_addresses(instances(role: role, region: region, availability_zone: availability_zone, exact_match: exact_match))
128
+ def instance_ip_addresses_by_role(role:, exclude_roles: [], region: my_region, availability_zone: nil, exact_match: false)
129
+ private_ip_addresses(instances(role: role, exclude_roles: exclude_roles, region: region, availability_zone: availability_zone, exact_match: exact_match))
129
130
  end
130
131
 
131
- def instance_ip_addresses_by_role_ordered(role:, region: my_region, exact_match: false)
132
- instances = instances(role: role, region: region, exact_match: exact_match)
132
+ def instance_ip_addresses_by_role_ordered(role:, exclude_roles: [], region: my_region, exact_match: false)
133
+ instances = instances(role: role, exclude_roles: exclude_roles, region: region, exact_match: exact_match)
133
134
  instances_in_my_az = instances.select { |instance| instance.placement.availability_zone == availability_zone }
134
135
  ordered_instances = instances_in_my_az.shuffle + (instances - instances_in_my_az).shuffle
135
136
  private_ip_addresses(ordered_instances)
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
data/spec/ec2_spec.rb CHANGED
@@ -250,6 +250,17 @@ describe MovableInk::AWS::EC2 do
250
250
  instances = aws.instances(role: 'app_db_replica', exact_match: true)
251
251
  expect(instances.map{|i| i.tags.first.value }).to eq(['instance4'])
252
252
  end
253
+
254
+ it "excludes requested roles" do
255
+ ec2.stub_responses(:describe_instances, instance_data)
256
+ allow(aws).to receive(:mi_env).and_return('test')
257
+ allow(aws).to receive(:availability_zone).and_return(my_availability_zone)
258
+ allow(aws).to receive(:my_region).and_return('us-east-1')
259
+ allow(aws).to receive(:ec2).and_return(ec2)
260
+
261
+ instances = aws.instances(role: 'app_db_replica', exclude_roles: ['db'])
262
+ expect(instances.map{|i| i.tags.first.value }).to eq(['instance1', 'instance4'])
263
+ end
253
264
  end
254
265
 
255
266
  context "ordered roles" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MovableInkAWS
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Chesler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-17 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk