vagrant-dnsdock-hostupdater 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/event-watcher.rb +28 -13
- data/lib/host-manager.rb +52 -7
- data/lib/vagrant-dnsdock-hostupdater/plugin.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb921b210516dc5a4f384182c9ace1930aeb1d3e
|
4
|
+
data.tar.gz: aed719a5a8fa5ff68e5fba877b0cb72679ec3d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac6932c0a74e13fb6f8fa4ae0ff8a3b6e85d9e48de065bf6903979ff47176c4702d75fed3434954c423131322139a3bbcca1952a7d1508a67c67356f1642e24e
|
7
|
+
data.tar.gz: 5a5b3d0468c520e6c9a90d3bad1d8b82944d5889202fc7363399a7df927a39d4c0ab82d8f53dc979d57195e019c87485ffe775854eec66ba2bbe0745b55d3f11
|
data/lib/event-watcher.rb
CHANGED
@@ -6,23 +6,38 @@ loop {
|
|
6
6
|
Docker::Event.stream { |event|
|
7
7
|
HostManager.log.info 'Connected to docker socket. Listening for events.'
|
8
8
|
# respond to all container events
|
9
|
-
if event.type == 'container'
|
10
|
-
container_id = event.actor.id.chomp
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
begin
|
11
|
+
if event.type == 'container'
|
12
|
+
# container_id = event.actor.id.chomp
|
15
13
|
|
16
|
-
|
17
|
-
client.host_suffix '.local.signal.sh'
|
14
|
+
# puts event.action
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
# container = Docker::Container.get(container_id)
|
17
|
+
# ip = container.info['NetworkSettings']['IPAddress']
|
18
|
+
# HostManager.log.info container.
|
19
|
+
# puts event.type
|
20
|
+
|
21
|
+
# container_name = container.info['Name'].sub!(/^\//, '')
|
22
|
+
|
23
|
+
client = HostManager::Client.create('10.10.10.1', 2991)
|
24
|
+
client.host_suffix '.local.signal.sh'
|
24
25
|
|
25
|
-
|
26
|
+
# To handle updating single entries
|
27
|
+
# if event.action == 'start'
|
28
|
+
# client.send_action('create', container_name, ip, container_id)
|
29
|
+
# elsif event.action == 'die'
|
30
|
+
# client.send_action('delete', container_name, ip, container_id)
|
31
|
+
# end
|
32
|
+
|
33
|
+
# if event.action == 'start' || event.action == 'die'
|
34
|
+
client.sync_hosts Docker::Container.all({:all => true})
|
35
|
+
# end
|
36
|
+
|
37
|
+
client.close
|
38
|
+
end
|
39
|
+
rescue => e
|
40
|
+
puts e.inspect
|
26
41
|
end
|
27
42
|
|
28
43
|
break
|
data/lib/host-manager.rb
CHANGED
@@ -28,7 +28,7 @@ module HostManager
|
|
28
28
|
def self.log
|
29
29
|
unless @log
|
30
30
|
@log = Log4r::Logger.new('main')
|
31
|
-
|
31
|
+
@log.outputters << Log4r::Outputter.stdout
|
32
32
|
@log.outputters << Log4r::FileOutputter.new('logmain', :filename => 'host-manager.log')
|
33
33
|
end
|
34
34
|
|
@@ -53,7 +53,7 @@ module HostManager
|
|
53
53
|
if container_name.include?('.')
|
54
54
|
container_name
|
55
55
|
else
|
56
|
-
container_name + host_suffix
|
56
|
+
container_name.sub!(/^\//, '') + host_suffix
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -81,14 +81,36 @@ module HostManager
|
|
81
81
|
begin
|
82
82
|
unless content.to_s.chomp.strip.empty?
|
83
83
|
data = JSON.parse(content)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
|
85
|
+
if data.is_a?(Hash)
|
86
|
+
required_keys = %w(action hostname ip containerId)
|
87
|
+
required_keys.each do |key|
|
88
|
+
unless data.key?(key)
|
89
|
+
raise "Data for key #{key} not provided."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
execute(data['action'], data['hostname'], data['ip'], data['containerId'])
|
93
|
+
|
94
|
+
elsif data.is_a?(Array)
|
95
|
+
hosts = get_hosts
|
96
|
+
|
97
|
+
# initially remove all entries
|
98
|
+
hosts.elements.delete_if do |element|
|
99
|
+
if valid_entry?(element)
|
100
|
+
log.info 'Removing entry for ' + element.name
|
101
|
+
true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# add recieved entries
|
106
|
+
data.each do |entry|
|
107
|
+
execute('create', entry['hostname'], entry['ip'], entry['containerId'])
|
88
108
|
end
|
109
|
+
|
89
110
|
end
|
90
|
-
|
111
|
+
|
91
112
|
end
|
113
|
+
|
92
114
|
rescue => e
|
93
115
|
log.error("Caught exception attempting to execute with data #{content}. #{e}")
|
94
116
|
end
|
@@ -105,6 +127,9 @@ module HostManager
|
|
105
127
|
def execute(action, hostname, ip, container_id = nil)
|
106
128
|
hosts = get_hosts
|
107
129
|
|
130
|
+
|
131
|
+
# todo: remove all entries and then re-add (sync hosts every time)
|
132
|
+
|
108
133
|
if action == 'create'
|
109
134
|
hosts.elements.each do |element|
|
110
135
|
if valid_entry?(element)
|
@@ -180,6 +205,26 @@ module HostManager
|
|
180
205
|
send(data)
|
181
206
|
end
|
182
207
|
|
208
|
+
def sync_hosts(container_data)
|
209
|
+
data = []
|
210
|
+
container_data.each do |container|
|
211
|
+
container.info['Names'].each do |name|
|
212
|
+
ip = container.info['NetworkSettings']['IPAddress']
|
213
|
+
|
214
|
+
if ip
|
215
|
+
item = {
|
216
|
+
:hostname => host_name(name),
|
217
|
+
:ip => ip,
|
218
|
+
:containerId => container.info['id']
|
219
|
+
}
|
220
|
+
|
221
|
+
data.push(item)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
183
228
|
def send(data)
|
184
229
|
log.info("Sending data via client: #{data.to_json}")
|
185
230
|
@socket.write data.to_json + "\n"
|
@@ -61,7 +61,7 @@ module Vagrant
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def self.init_plugin
|
64
|
+
def self.init_plugin
|
65
65
|
server_path = File.expand_path('../../server.rb', __FILE__)
|
66
66
|
|
67
67
|
if @started
|
@@ -84,7 +84,7 @@ module Vagrant
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
action_hook(:up, :machine_action_up) { init_plugin
|
87
|
+
action_hook(:up, :machine_action_up) { init_plugin }
|
88
88
|
|
89
89
|
end
|
90
90
|
end
|
data/lib/version.rb
CHANGED