small-ops 0.0.2 → 0.0.3
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/bin/etcd2conf +57 -0
- metadata +4 -2
data/bin/etcd2conf
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'small-setup'
|
|
4
|
+
require 'erb'
|
|
5
|
+
require 'zlib'
|
|
6
|
+
|
|
7
|
+
if !@input || !@output then
|
|
8
|
+
raise "Need input and output!"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Namespace
|
|
12
|
+
def initialize(data,config)
|
|
13
|
+
@data=data
|
|
14
|
+
@config=config
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_binding
|
|
18
|
+
binding
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
run = true
|
|
24
|
+
`bash -c '[[ ! -e #{@output} ]] && touch #{@output}'`
|
|
25
|
+
last = File.read(@output)
|
|
26
|
+
|
|
27
|
+
while run do
|
|
28
|
+
r = http_get("#{@etcd}/v2/keys/#{@prefix}?recursive=true")
|
|
29
|
+
|
|
30
|
+
data = nodes2obj(r["node"]["nodes"],"/")
|
|
31
|
+
|
|
32
|
+
template = File.read(@input)
|
|
33
|
+
|
|
34
|
+
if @prefix.length >= 1 then prefix = "#{prefix}/" end
|
|
35
|
+
|
|
36
|
+
ns = Namespace.new(data,{"host"=>@host,"prefix"=>prefix})
|
|
37
|
+
result=ERB.new(template).result(ns.get_binding)
|
|
38
|
+
|
|
39
|
+
actual = Zlib::crc32(result)
|
|
40
|
+
|
|
41
|
+
if actual != last then
|
|
42
|
+
puts "Writing #{@output}"
|
|
43
|
+
|
|
44
|
+
File.open(@output, 'w') { |file| file.write(result) }
|
|
45
|
+
|
|
46
|
+
last = actual
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
run = false
|
|
50
|
+
|
|
51
|
+
if @foreground then
|
|
52
|
+
sleep 10
|
|
53
|
+
run = true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: small-ops
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -11,17 +11,19 @@ bindir: bin
|
|
|
11
11
|
cert_chain: []
|
|
12
12
|
date: 2014-07-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
|
-
description: Docker, etcd, confd...
|
|
14
|
+
description: Docker, etcd, confd, fig...
|
|
15
15
|
email: diogo@diogok.net
|
|
16
16
|
executables:
|
|
17
17
|
- docker2etcd
|
|
18
18
|
- etcd2env
|
|
19
|
+
- etcd2conf
|
|
19
20
|
extensions: []
|
|
20
21
|
extra_rdoc_files: []
|
|
21
22
|
files:
|
|
22
23
|
- lib/small-setup.rb
|
|
23
24
|
- bin/docker2etcd
|
|
24
25
|
- bin/etcd2env
|
|
26
|
+
- bin/etcd2conf
|
|
25
27
|
homepage: https://github.com/
|
|
26
28
|
licenses:
|
|
27
29
|
- MIT
|