hocho-ec2 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: 0f244b10a1aa987e5c40e1c9a718ed7c8d84fe43
4
- data.tar.gz: 552b998d5da7fd6780b1033806bda568be5668ff
2
+ SHA256:
3
+ metadata.gz: 51c129620328777a9815f34fb6231b5240295d256a38e26a3f51a75821e4744f
4
+ data.tar.gz: 9518a6da4b6437293c7531d397d665162055d4e316311cc75962b08380350a5d
5
5
  SHA512:
6
- metadata.gz: e0238555988a86c2b1b985db535a9ae435cece9f877bbd4d05f90289df172cefd55125a95b3fd5714a27d6fb8ca3433441e923f4e5e167ee7410045bbace3b0c
7
- data.tar.gz: 0daa74f6c680c04f6187d950cfe4c351354222b25fb341d421c72e88687403c08da81991c17ddc4e143c4ed164e1922f18fca8b343e229ced7cbfe4b71a2d0fe
6
+ metadata.gz: f8febe9892932bfec8fc1fcbe7275e0cf32b862aa68dda935d4434ab383910156c0c4b094ad589fb191af5e02d005ef678b5a6bf110ebd78c589a9ea33536733
7
+ data.tar.gz: c6904281b1b6b611a1fbdf1aaa882f2d3989d50a299d2e096bb6ec64786239683369954557448c250e2fa7e4d922494f67e81159c5043dac177f7a6bdb67c2ff
@@ -1,3 +1,3 @@
1
1
  module HochoEc2
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -60,12 +60,19 @@ module Hocho
60
60
  [vpc.vpc_id, vpc]
61
61
  end
62
62
  end.to_h
63
+ subnets= ec2.describe_subnets().flat_map do |page|
64
+ page.subnets.map do |subnet|
65
+ [subnet.subnet_id, subnet]
66
+ end
67
+ end.to_h
63
68
  ec2.describe_instances(filters: filters).flat_map do |page|
64
69
  page.reservations.flat_map do |reservation|
65
70
  reservation.instances.map do |instance|
71
+ next if instance.state.name == 'terminated' || instance.state.name == 'terminating'
66
72
  vpc = vpcs[instance.vpc_id]
67
- fetch_instance(instance, vpc)
68
- end
73
+ subnet = subnets[instance.subnet_id]
74
+ fetch_instance(instance, vpc, subnet)
75
+ end.compact
69
76
  end
70
77
  end
71
78
  end
@@ -104,11 +111,12 @@ module Hocho
104
111
 
105
112
  private
106
113
 
107
- def fetch_instance(instance, vpc)
114
+ def fetch_instance(instance, vpc, subnet)
108
115
  tags = {
109
116
  'ec2.instance-id' => instance.instance_id,
110
117
  'ec2.iam-instance-profile' => instance.iam_instance_profile,
111
118
  'ec2.vpc-id' => instance.vpc_id,
119
+ 'ec2.subnet-id' => instance.subnet_id,
112
120
  }
113
121
  {'vpc-tags' => vpc.tags, 'tags' => instance.tags}.each do |prefix, aws_tags|
114
122
  aws_tags.each do |tag|
@@ -118,13 +126,14 @@ module Hocho
118
126
 
119
127
  ec2_attribute = instance.to_h
120
128
  vpc_attribute = vpc.to_h
121
- [ec2_attribute, vpc_attribute].each do |attrs|
129
+ subnet_attribute = subnet.to_h
130
+ [ec2_attribute, vpc_attribute, subnet_attribute].each do |attrs|
122
131
  attrs[:tags] = attrs.fetch(:tags, []).map { |_| [_.fetch(:key), _.fetch(:value)] }.to_h
123
132
  end
124
133
 
125
134
  properties = {
126
135
  run_list: runlist_template.new(instance, vpc).result(),
127
- attributes: {hocho_ec2: ec2_attribute, hocho_vpc: vpc_attribute,},
136
+ attributes: {hocho_ec2: ec2_attribute, hocho_vpc: vpc_attribute, hocho_subnet: subnet_attribute,},
128
137
  }
129
138
  {
130
139
  name: hostname_template.new(instance, vpc).result(),
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hocho-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sorah Fukumori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-07 00:00:00.000000000 Z
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ec2
@@ -105,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.6.13
108
+ rubygems_version: 3.0.3
110
109
  signing_key:
111
110
  specification_version: 4
112
111
  summary: Hocho gem plugin to discover hosts in EC2