MovableInkAWS 0.3.5 → 0.3.6

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: f85b7a7cacd3d56c98e276a780730187b57d96beea4197e972858e093ff8b5b6
4
- data.tar.gz: 0edf31bf91bbc3498f2336df122eaa70631b2e4d62c4b3dbc373365dea9b4209
3
+ metadata.gz: ac88eb29fbafb05b27ad196f6308d5184b38d9220f6213d38965915b22505c76
4
+ data.tar.gz: 36df30eeaeb57db6f742d95819266d902b9ea118f14ca56c685ffba62a4172b5
5
5
  SHA512:
6
- metadata.gz: 5834796db467a574a0ce7f9cb88c6bb1f6995ebb54292d543881c23884de2733ff41a1729fa49e0d40056e89959e49e84e6347bb1ecaaea1ee718f54ad039f3e
7
- data.tar.gz: 8ced1573db88a51ded5905888e01bac2a606dbffb1811e2dbd9ea5c230872711febc0867f5ba4380c8fd45d7c51dc9f87c4e5064c9d1c5c10532e38b89e6642c
6
+ metadata.gz: 6d1df5299ea1db3985f1747779ac4b626605880062286c8b97872485cd8d1c848b18c06d2f09ec223c670c6c6ec674a60c93951c6299f0495ed5b919ec849cf4
7
+ data.tar.gz: 509c3fe4f8257378bf70a816b3c9631141aa8d7b36ece74ee5dcafbb5006f1b76b7b2b9465331017ab1836f19a0f2c0231686bc37216bb99940a538b75953ab5
@@ -91,11 +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)
94
+ def instances(role:, 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
- roles.include?(role) && !roles.include?('decommissioned')
98
+ if exact_match
99
+ roles == [role]
100
+ else
101
+ roles.include?(role) && !roles.include?('decommissioned')
102
+ end
99
103
  }
100
104
  }
101
105
 
@@ -120,12 +124,12 @@ module MovableInk
120
124
  instances.map(&:private_ip_address)
121
125
  end
122
126
 
123
- def instance_ip_addresses_by_role(role:, region: my_region, availability_zone: nil)
124
- private_ip_addresses(instances(role: role, region: region, availability_zone: availability_zone))
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))
125
129
  end
126
130
 
127
- def instance_ip_addresses_by_role_ordered(role:, region: my_region)
128
- instances = instances(role: role, region: region)
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)
129
133
  instances_in_my_az = instances.select { |instance| instance.placement.availability_zone == availability_zone }
130
134
  ordered_instances = instances_in_my_az.shuffle + (instances - instances_in_my_az).shuffle
131
135
  private_ip_addresses(ordered_instances)
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '0.3.5'
3
+ VERSION = '0.3.6'
4
4
  end
5
5
  end
data/spec/ec2_spec.rb CHANGED
@@ -202,7 +202,23 @@ describe MovableInk::AWS::EC2 do
202
202
  value: 'app_db, db'
203
203
  }
204
204
  ],
205
- private_ip_address: '10.0.0.2',
205
+ private_ip_address: '10.0.0.3',
206
+ placement: {
207
+ availability_zone: other_availability_zone
208
+ }
209
+ },
210
+ {
211
+ tags: [
212
+ {
213
+ key: 'mi:name',
214
+ value: 'instance4'
215
+ },
216
+ {
217
+ key: 'mi:roles',
218
+ value: 'app_db_replica'
219
+ }
220
+ ],
221
+ private_ip_address: '10.0.0.4',
206
222
  placement: {
207
223
  availability_zone: other_availability_zone
208
224
  }
@@ -218,11 +234,22 @@ describe MovableInk::AWS::EC2 do
218
234
  allow(aws).to receive(:ec2).and_return(ec2)
219
235
 
220
236
  instances = aws.instances(role: 'app_db_replica')
221
- expect(instances.map{|i| i.tags.first.value }).to eq(['instance1', 'instance2'])
237
+ expect(instances.map{|i| i.tags.first.value }).to eq(['instance1', 'instance2', 'instance4'])
222
238
 
223
239
  instances = aws.instances(role: 'db')
224
240
  expect(instances.map{|i| i.tags.first.value }).to eq(['instance2', 'instance3'])
225
241
  end
242
+
243
+ it "returns roles with exactly the specified role" do
244
+ ec2.stub_responses(:describe_instances, instance_data)
245
+ allow(aws).to receive(:mi_env).and_return('test')
246
+ allow(aws).to receive(:availability_zone).and_return(my_availability_zone)
247
+ allow(aws).to receive(:my_region).and_return('us-east-1')
248
+ allow(aws).to receive(:ec2).and_return(ec2)
249
+
250
+ instances = aws.instances(role: 'app_db_replica', exact_match: true)
251
+ expect(instances.map{|i| i.tags.first.value }).to eq(['instance4'])
252
+ end
226
253
  end
227
254
 
228
255
  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.3.5
4
+ version: 0.3.6
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-01 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk