sortinghat 0.3.0 → 0.3.2
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 -1
- data/lib/sortinghat/banquet.rb +29 -19
- 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: 7796fcee5c89e9eccdf90a2cd275c921c787b8d6
|
4
|
+
data.tar.gz: f00f7b9af41f75647fba8f6bfb191fa7c8985ee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e64c35725349723129787d1548ababb0f52bb6fe792d22b8557d47189521f58f02d2bf8ab8e94d9c2d771ffb0e063f1566dff1baa4d6b79fc7beef7756cbac40
|
7
|
+
data.tar.gz: ae90d2230a8661404b43c33fe7240731dcc4317f9551b15c154fca77764b895bac994415f0d81a4a42a10fc88687c89c5f5c7a40ad385bad5cf9e7da19893855
|
data/README.md
CHANGED
@@ -28,9 +28,11 @@ Install however you please to your AMI(s) with:
|
|
28
28
|
The gem itself was developed under Ruby 2.0.0 to work with CentOS 7.
|
29
29
|
|
30
30
|
It requires the following gems:
|
31
|
-
* aws-sdk
|
31
|
+
* aws-sdk 2.1.2
|
32
32
|
* pure_json
|
33
33
|
|
34
|
+
The v2.1.2 dependency comes from the fact that as of this writting the latest codedeploy-agent (installed via .rpm) breaks if it does not have v2.1.2.
|
35
|
+
|
34
36
|
During actually usage, the gem requires that the instance have the following IAM actions allowed via policy:
|
35
37
|
* autoscaling:DescribeAutoScalingInstances
|
36
38
|
* autoscaling:DescribeAutoScalingGroups
|
data/lib/sortinghat/banquet.rb
CHANGED
@@ -38,31 +38,34 @@ module Sortinghat
|
|
38
38
|
def start!
|
39
39
|
|
40
40
|
# Best thing to avoid run conditions are to wait
|
41
|
-
sleep rand(
|
41
|
+
sleep rand(10)
|
42
42
|
|
43
43
|
# Find out who is who, instances alive
|
44
|
-
# If discover() returns an Array full of nil(s), alive will
|
45
|
-
alive = cleanup
|
44
|
+
# If discover() returns an Array full of nil(s), alive will become an empty Array
|
45
|
+
alive = cleanup(@aws.discover())
|
46
46
|
|
47
47
|
# Given the alive instances, find our prefix
|
48
|
-
# If alive
|
48
|
+
# If alive an empty array, selection will return the number '1'
|
49
49
|
@prefix = ensurezero(selection(alive))
|
50
50
|
|
51
51
|
# Put together hostname/fqdn
|
52
52
|
construction()
|
53
53
|
|
54
|
+
# Set the Name tag on this instance
|
54
55
|
@aws.settag!(@hostname)
|
55
56
|
|
56
57
|
# Find out who is who, instances alive
|
57
|
-
# If discover() returns an Array full of nil(s), alive will
|
58
|
-
alive = cleanup
|
58
|
+
# If discover() returns an Array full of nil(s), alive will become an empty Array
|
59
|
+
alive = cleanup(@aws.discover())
|
59
60
|
|
61
|
+
# Only enter recursion if the uniq() length of the alive array does not equal the actual length
|
62
|
+
# On AutoScalingGroup initalization, the cleanup() should ensure the alive array is empty not nil so uniq() works
|
60
63
|
unless alive.uniq.length == alive.length
|
61
64
|
# There are duplicates, remove tag, wait, restart
|
62
65
|
@aws.removetag!()
|
63
66
|
sleep rand(10)
|
64
67
|
start!()
|
65
|
-
end
|
68
|
+
end
|
66
69
|
|
67
70
|
# Register in DNS
|
68
71
|
@aws.setroute53(@options[:zone], @fqdn)
|
@@ -88,6 +91,7 @@ module Sortinghat
|
|
88
91
|
|
89
92
|
private
|
90
93
|
|
94
|
+
# Method to check that we have write permissions to /etc/*
|
91
95
|
def checkpermissions()
|
92
96
|
unless File.stat('/etc/hosts').writable?
|
93
97
|
# We found it, log error and exit successfully
|
@@ -96,40 +100,46 @@ module Sortinghat
|
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
array.
|
103
|
+
# Method to cleanup the array returned by aws.discover()
|
104
|
+
# Remove nil values basically
|
105
|
+
def cleanup(array)
|
106
|
+
clean = array.reject { |item| item.nil? }
|
107
|
+
return [] if clean.empty?
|
108
|
+
clean
|
103
109
|
end
|
104
110
|
|
111
|
+
# Method to consume the alive array and figure out what this instance's prefix should be
|
105
112
|
def selection(array)
|
106
|
-
# If array is
|
107
|
-
return 1 if array.
|
113
|
+
# If array is empty, just return 01
|
114
|
+
return 1 if array.empty?
|
108
115
|
|
109
|
-
# Array to store the numbers already taken
|
116
|
+
# Array to store the numbers already taken
|
110
117
|
taken = Array.new
|
111
|
-
|
118
|
+
|
112
119
|
# Filter the incoming array, find the numbers and store them in the taken Array
|
113
120
|
array.each { |string| taken << string.scan(/\d./).join('').sub(/^0+/, '').to_i }
|
114
|
-
|
121
|
+
|
115
122
|
# We have two digits, define our range of numbers
|
116
123
|
limits = (1..99).to_a
|
117
124
|
|
118
|
-
# Return the first value once we find what isn't taken in our range of numbers
|
125
|
+
# Return the first value once we find what isn't taken in our range of numbers
|
119
126
|
(limits - taken)[0]
|
120
127
|
end
|
121
128
|
|
129
|
+
# Method to ensure our prefix always has a leading 0 if < 10
|
122
130
|
def ensurezero(prefix)
|
123
131
|
if prefix < 10
|
124
132
|
prefix.to_s.rjust(2, "0")
|
125
133
|
end
|
126
134
|
end
|
127
135
|
|
136
|
+
# Method to construct our instance variables @hostname and @fqdn
|
128
137
|
def construction()
|
129
138
|
@hostname = "#{@options[:client]}-#{@options[:env]}-#{@options[:type]}#{@prefix.to_s}-#{@options[:region]}"
|
130
139
|
@fqdn = "#{@options[:client]}-#{@options[:env]}-#{@options[:type]}#{@prefix.to_s}-#{@options[:region]}.#{@options[:zone]}"
|
131
140
|
end
|
132
141
|
|
142
|
+
# Method to set the local hostname on this instance
|
133
143
|
def setlocal()
|
134
144
|
if system("hostnamectl set-hostname #{@fqdn}")
|
135
145
|
@log.info("Set the localhost hostname to #{@fqdn}.")
|
@@ -139,9 +149,9 @@ module Sortinghat
|
|
139
149
|
def sethostsfile()
|
140
150
|
# Store the ip address so we only make one metadata call here
|
141
151
|
privateip = @aws.privateip()
|
142
|
-
if File.readlines('/etc/hosts').grep(/#{@hostname}|#{privateip}/).size < 1
|
152
|
+
if File.readlines('/etc/hosts').grep(/#{@hostname}|#{privateip}/).size < 1
|
143
153
|
File.open('/etc/hosts', 'a') do |file|
|
144
|
-
file.puts "#{
|
154
|
+
file.puts "#{privateip} \t #{@hostname} #{@fqdn}"
|
145
155
|
end
|
146
156
|
@log.info("Added hostname(s) to /etc/hosts.")
|
147
157
|
else
|
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.3.
|
4
|
+
version: 0.3.2
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|