cncflora_commons 0.0.39 → 0.0.40
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.
- data/lib/cncflora_commons.rb +0 -53
- metadata +1 -1
data/lib/cncflora_commons.rb
CHANGED
@@ -113,17 +113,6 @@ def setup(file)
|
|
113
113
|
}
|
114
114
|
}
|
115
115
|
|
116
|
-
if ENV["ETCD"] || @config["etcd"] then
|
117
|
-
etcd_cfg = etcd2config(ENV["ETCD"] || @config["etcd"])
|
118
|
-
onchange(ENV["ETCD"] || @config["etcd"]) do |newconfig|
|
119
|
-
newconfig.each {|k,v| @config[k] = v }
|
120
|
-
if defined? settings then
|
121
|
-
newconfig.each {|k,v| set k.to_sym,v }
|
122
|
-
end
|
123
|
-
end
|
124
|
-
etcd_cfg.each {|k,v| @config[k] = v }
|
125
|
-
end
|
126
|
-
|
127
116
|
ENV.each {|k,v| @config[k]=v }
|
128
117
|
|
129
118
|
if @config["lang"] then
|
@@ -146,45 +135,3 @@ def setup(file)
|
|
146
135
|
@config
|
147
136
|
end
|
148
137
|
|
149
|
-
def flatten(obj)
|
150
|
-
flat = {}
|
151
|
-
if obj["dir"] && obj["nodes"] then
|
152
|
-
obj["nodes"].each { |n|
|
153
|
-
flat = flat.merge(flatten(n))
|
154
|
-
}
|
155
|
-
else
|
156
|
-
key = obj["key"].gsub("/","_").gsub("-","_")
|
157
|
-
flat[key[1..key.length]]=obj["value"]
|
158
|
-
end
|
159
|
-
flat
|
160
|
-
end
|
161
|
-
|
162
|
-
def etcd2config(server)
|
163
|
-
cfg = flatten( http_get("#{server}/v2/keys/?recursive=true")["node"] )
|
164
|
-
to_add={}
|
165
|
-
cfg.each {|k,v|
|
166
|
-
if k.match(/_port$/) then
|
167
|
-
name = /(\w+)_port/.match(k).captures[0]
|
168
|
-
ip = cfg["#{name}_networksettings_ipaddress"]
|
169
|
-
port = 80
|
170
|
-
cfg.each {|kk,vv|
|
171
|
-
if /^#{name}_networksettings/.match(kk) && vv == v then
|
172
|
-
port = /ports_(\d+)_tcp/.match(kk).captures[0]
|
173
|
-
end
|
174
|
-
}
|
175
|
-
to_add[name] = "http://#{ip}:#{port}"
|
176
|
-
end
|
177
|
-
}
|
178
|
-
to_add.each{|k,v| cfg[k]=v}
|
179
|
-
cfg
|
180
|
-
end
|
181
|
-
|
182
|
-
def onchange(etcd)
|
183
|
-
Thread.new do
|
184
|
-
while true do
|
185
|
-
a = http_get("#{etcd}/v2/keys/?recursive=true&wait=true")
|
186
|
-
puts "etcd updated"
|
187
|
-
yield etcd2config(etcd)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|