sortinghat 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 +4 -4
- data/README.md +3 -3
- data/lib/sortinghat/aws.rb +20 -12
- data/lib/sortinghat/banquet.rb +9 -2
- data/lib/sortinghat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59892d22cedf8e98be4abe64b1eaad223777806a
|
4
|
+
data.tar.gz: c66c95ed0098a384a0e5797e6a914354e7431c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bef5473f37c0d14c36ab6290340c9d1764ac70c72b3c39bbcea12455da3ae871a88ad5288aa700cec18eddf96c961b93b1d2989090362d0d8bc2017ba3d2e2d
|
7
|
+
data.tar.gz: 8ae5477f8b4b6fdec97b50193147601353f546fbf2543c44bed0cc0c326bc63cd3504a56e6f742e9f1d4d1cd4484b2d3408f9ec3ab505858dff589a92e570ca4
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ It follows a specific pattern for hostnames/fqdn:
|
|
14
14
|
For example:
|
15
15
|
|
16
16
|
```
|
17
|
-
nike-prod-nginx09.prod-
|
17
|
+
nike-prod-nginx09.prod-nike.com
|
18
18
|
```
|
19
19
|
|
20
20
|
## Installation:
|
@@ -32,7 +32,8 @@ It requires the following gems:
|
|
32
32
|
* pure_json
|
33
33
|
|
34
34
|
During actually usage, the gem requires that the instance have the following IAM actions allowed via policy:
|
35
|
-
* autoscaling:
|
35
|
+
* autoscaling:DescribeAutoScalingInstances
|
36
|
+
* autoscaling:DescribeAutoScalingGroups
|
36
37
|
* ec2:DescribeInstances
|
37
38
|
* ec2:CreateTags
|
38
39
|
* route53:ListHostedZones
|
@@ -73,7 +74,6 @@ Run:
|
|
73
74
|
|
74
75
|
Bug reports and pull requests are welcome on GitHub at https://github.com/praymann/sortinghat.
|
75
76
|
|
76
|
-
|
77
77
|
## License
|
78
78
|
|
79
79
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/sortinghat/aws.rb
CHANGED
@@ -16,7 +16,7 @@ module Sortinghat
|
|
16
16
|
@log = Syslog::Logger.new 'sortinghat'
|
17
17
|
end
|
18
18
|
|
19
|
-
# Method to discover
|
19
|
+
# Method to discover what auto-scaling group the current instance is in, then the instances in that group
|
20
20
|
# Returns array of the Name tag values of the instances
|
21
21
|
def discover()
|
22
22
|
# Temporay array for use
|
@@ -25,14 +25,25 @@ module Sortinghat
|
|
25
25
|
# Start a new client
|
26
26
|
autoscale = Aws::AutoScaling::Client.new( region: @region )
|
27
27
|
|
28
|
-
# Use the client to
|
29
|
-
|
30
|
-
|
28
|
+
# Use the client to describe this instance
|
29
|
+
current = autoscale.describe_auto_scaling_instances({
|
30
|
+
instance_ids: [grabinstanceid()],
|
31
|
+
max_records: 1
|
32
|
+
})
|
33
|
+
@log.info("Grabbed current AutoScaling instance via aws-sdk")
|
34
|
+
|
35
|
+
# Use the client to grab all instances in this auto-scaling group
|
36
|
+
all = autoscale.describe_auto_scaling_groups({
|
37
|
+
auto_scaling_group_names: [current.auto_scaling_instances[0].auto_scaling_group_name],
|
38
|
+
max_records: 1
|
39
|
+
})
|
40
|
+
@log.info("Grabbed the instances of our AutoScaling group via aws-sdk")
|
31
41
|
|
32
42
|
# Grab their instanceId(s)
|
33
|
-
|
34
|
-
|
43
|
+
all.auto_scaling_groups[0].instances.each do |instance|
|
44
|
+
ids << idtoname(instance.instance_id)
|
35
45
|
end
|
46
|
+
@log.info("Returning instances '#{ids.join("','")}'")
|
36
47
|
|
37
48
|
# Return the ids
|
38
49
|
ids
|
@@ -51,7 +62,7 @@ module Sortinghat
|
|
51
62
|
key: 'Name',
|
52
63
|
value: hostname,
|
53
64
|
},
|
54
|
-
|
65
|
+
]
|
55
66
|
})
|
56
67
|
@log.info("Set Name tag to #{hostname} via aws-sdk")
|
57
68
|
end
|
@@ -110,11 +121,8 @@ module Sortinghat
|
|
110
121
|
|
111
122
|
def idtoname(instance_id)
|
112
123
|
resource = Aws::EC2::Resource.new(client: @client)
|
113
|
-
resource.instance(instance_id).tags.
|
114
|
-
|
115
|
-
return tag.value
|
116
|
-
end
|
117
|
-
end
|
124
|
+
name = resource.instance(instance_id).tags.find { |tag| tag.key == 'Name' }
|
125
|
+
return name.value unless name.nil?
|
118
126
|
end
|
119
127
|
|
120
128
|
def zonetoid(hostedzone)
|
data/lib/sortinghat/banquet.rb
CHANGED
@@ -29,17 +29,19 @@ module Sortinghat
|
|
29
29
|
# Check for sentinel file
|
30
30
|
if File.exists?('/etc/.sorted')
|
31
31
|
# We found it, log error and exit successfully
|
32
|
-
@log.
|
33
|
-
|
32
|
+
@log.info('Found /etc/.sorted, refusing to sort.')
|
33
|
+
exit 0
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
# Main method of Sortinghat
|
38
38
|
def start!
|
39
39
|
# Find out who is who, instances alive
|
40
|
+
# If discover() returns a nil Array, alive will be nil
|
40
41
|
alive = cleanup(@aws.discover())
|
41
42
|
|
42
43
|
# Given the alive instances, find our prefix
|
44
|
+
# If alive is nil, selection will return the number '1'
|
43
45
|
@prefix = ensurezero(selection(alive))
|
44
46
|
|
45
47
|
# Put together hostname/fqdn
|
@@ -48,6 +50,7 @@ module Sortinghat
|
|
48
50
|
@aws.settag!(@hostname)
|
49
51
|
|
50
52
|
# Find out who is who, instances alive
|
53
|
+
# If discover() returns a nil Array, alive will be nil
|
51
54
|
alive = cleanup(@aws.discover())
|
52
55
|
|
53
56
|
unless alive.uniq.length == alive.length
|
@@ -90,10 +93,14 @@ module Sortinghat
|
|
90
93
|
end
|
91
94
|
|
92
95
|
def cleanup(array)
|
96
|
+
return [] if array.any? { |item| item.nil? }
|
93
97
|
array.select! { |name| name.include?(@options[:env]) and name.include?(@options[:client]) and name.include?(@options[:type]) }
|
94
98
|
end
|
95
99
|
|
96
100
|
def selection(array)
|
101
|
+
# If array is nil, just return 01
|
102
|
+
return 1 if array.nil?
|
103
|
+
|
97
104
|
# Array to store the numbers already taken
|
98
105
|
taken = Array.new
|
99
106
|
|
data/lib/sortinghat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortinghat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- D. Pramann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|