small-ops 0.0.32 → 0.0.33

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.
Files changed (2) hide show
  1. data/bin/docker2etcd +56 -33
  2. metadata +1 -1
data/bin/docker2etcd CHANGED
@@ -19,43 +19,66 @@ OptionParser.new do |opts|
19
19
  opts.on("-c","--clear","clear etcd of previous data (only containers data)") do |c|
20
20
  @options[:clear]=c
21
21
  end
22
+ opts.on("-f","--foreground","Keep running on foregroud. Default is run once and exit.") do |f|
23
+ @options[:foreground]=f
24
+ end
22
25
  end.parse!
23
26
 
24
- if @options[:clear] then
25
- data = nodes2obj( http_get("#{@options[:etcd]}/v2/keys/?recursive=true")["node"]["nodes"] ,"/")
26
- data.keys.each {|k|
27
- n = data[k]
28
- if n.has_key?("host") && n.has_key?("name") && n.has_key?("port") then
29
- puts "del #{n["name"]}"
30
- http_delete("#{@options[:etcd]}/v2/keys/#{n["name"]}?dir=true&recursive=true")
31
- end
32
- }
33
- end
27
+ run = true
28
+ last = []
29
+
30
+ while run do
34
31
 
35
- `docker ps | tail -n+2 | awk '{ print $1 }'`.split("\n")
36
- .map { |id| `docker inspect #{id}` }
37
- .map { |inspect| JSON.parse(inspect)[0]}
38
- .map { |data| flatten(data,data["Name"]) }
39
- .each { |container|
40
- name = container.keys.first.split("/")[1]
41
- port = `docker inspect #{container["/#{name}/id"]} | grep -o '[0-9]\\+/tcp' | head -n1 | grep -o '[0-9]\\+'`.gsub("\n","")
42
- hport = container["/#{name}/networksettings/ports/#{port}/tcp/hostport"]
43
- container["/#{name}/name"] = name
44
- container["/#{name}/port"] = hport
45
- container["/#{name}/host"] = @options[:host]
46
- if @options[:url] then
47
- container["/#{name}/url"] = "http://#{@options[:host]}/#{name}"
48
- else
49
- container["/#{name}/url"] = "http://#{@options[:host]}:#{hport}"
32
+ containers = `docker ps | tail -n+2 | awk '{ print $1 }'`.split("\n")
33
+
34
+ if last != containers then
35
+
36
+ if @options[:clear] then
37
+ data = nodes2obj( http_get("#{@options[:etcd]}/v2/keys/?recursive=true")["node"]["nodes"] ,"/")
38
+ data.keys.each {|k|
39
+ n = data[k]
40
+ if n.has_key?("host") && n.has_key?("name") && n.has_key?("port") then
41
+ puts "delete #{n["name"]}"
42
+ http_delete("#{@options[:etcd]}/v2/keys/#{n["name"]}?dir=true&recursive=true")
50
43
  end
51
- container.keys.each {|key|
52
- if container[key] != nil then
53
- if @options[:verbose] then
54
- puts "#{key} = #{container[key]}"
55
- end
56
- http_put("#{@options[:etcd]}/v2/keys#{key}","value=#{URI.encode(container[key])}")
44
+ }
45
+ end
46
+
47
+ containers
48
+ .map { |id| `docker inspect #{id}` }
49
+ .map { |inspect| JSON.parse(inspect)[0]}
50
+ .map { |data| flatten(data,data["Name"]) }
51
+ .each { |container|
52
+ name = container.keys.first.split("/")[1]
53
+ port = `docker inspect #{container["/#{name}/id"]} | grep -o '[0-9]\\+/tcp' | head -n1 | grep -o '[0-9]\\+'`.gsub("\n","")
54
+ hport = container["/#{name}/networksettings/ports/#{port}/tcp/hostport"]
55
+ container["/#{name}/name"] = name
56
+ container["/#{name}/port"] = hport
57
+ container["/#{name}/host"] = @options[:host]
58
+ if @options[:url] then
59
+ container["/#{name}/url"] = "http://#{@options[:host]}/#{name}"
60
+ else
61
+ container["/#{name}/url"] = "http://#{@options[:host]}:#{hport}"
57
62
  end
63
+ container.keys.each {|key|
64
+ if container[key] != nil then
65
+ if @options[:verbose] then
66
+ puts "#{key} = #{container[key]}"
67
+ end
68
+ #http_put("#{@options[:etcd]}/v2/keys#{key}","value=#{URI.encode(container[key])}")
69
+ end
70
+ }
71
+ puts "-> #{name} : #{container["/#{name}/url"]}"
58
72
  }
59
- puts "-> #{name} : #{container["/#{name}/url"]}"
60
- }
73
+ last = containers
74
+ end
75
+
76
+ run =false
77
+
78
+ if @options[:foreground] then
79
+ run = true
80
+ sleep 5
81
+ end
82
+
83
+ end
61
84
 
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.32
4
+ version: 0.0.33
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: