summaryrefslogtreecommitdiffstats
path: root/modules/ketcd
diff options
context:
space:
mode:
authorMarek Vavruša <marek.vavrusa@nic.cz>2015-05-07 10:36:30 +0200
committerMarek Vavruša <marek.vavrusa@nic.cz>2015-05-07 10:36:30 +0200
commitafa670bb5e4de924bdaae4531f04aafe34e362b2 (patch)
treef85f2db201c921eeb72220eda2612bd4f7841789 /modules/ketcd
parentdaemon/bindings: report errors in events (diff)
downloadknot-resolver-afa670bb5e4de924bdaae4531f04aafe34e362b2.tar.xz
knot-resolver-afa670bb5e4de924bdaae4531f04aafe34e362b2.zip
modules/ketcd: Etcd module
Diffstat (limited to 'modules/ketcd')
-rw-r--r--modules/ketcd/ketcd.lua49
1 files changed, 37 insertions, 12 deletions
diff --git a/modules/ketcd/ketcd.lua b/modules/ketcd/ketcd.lua
index d4ee5053..fed76763 100644
--- a/modules/ketcd/ketcd.lua
+++ b/modules/ketcd/ketcd.lua
@@ -1,24 +1,49 @@
--- @module ketcd
local ketcd = {}
-local Etcd = require('etcd.luasocket')
-function ketcd.init(module)
- print('wip')
+-- @function update subtree configuration
+local function update_subtree(tree)
+ if not tree then return end
+ for i,k in pairs(tree) do
+ if k.dir then
+ update_subtree(k.nodes)
+ else
+ local key,opt = k.key:gmatch('([^/]+)/([^/]+)$')()
+ eval_cmd(key..'='..'{'..opt..'='..k.value..'}')
+ end
+ end
end
-function ketcd.deinit(module)
- print('wip')
+-- @function reload whole configuration
+function ketcd.reload()
+ local res, err = ketcd.cli:readdir('/', true)
+ if err then
+ error(err)
+ end
+ update_subtree(res.body.node.nodes)
+end
+
+function ketcd.init(module)
+ ketcd.Etcd = require('etcd.luasocket')
+ ketcd.cli = nil
+ ketcd.ev = nil
+ ketcd.defaults = { prefix = '/kresolved' }
end
-function ketcd.config(module, conf)
- local cli, err = Etcd.new({
- peer = conf,
- });
- ketcd._cli = cli
+function ketcd.deinit(module)
+ if ketcd.ev then event.cancel(ketcd.ev) end
end
-function ketcd.layers(module)
- return {}
+function ketcd.config(conf)
+ local options = ketcd.defaults
+ if type(conf) == 'table' then
+ for k,v in pairs(conf) do options[k] = v end
+ end
+ local cli, err = ketcd.Etcd.new(options)
+ if err then
+ error(err)
+ end
+ ketcd.cli = cli
end
return ketcd