add dhcp reload command

This commit is contained in:
Jörg Thalheim 2015-01-19 09:18:25 +01:00
parent a9f49bc6f5
commit 757e0f8992
3 changed files with 24 additions and 2 deletions

View File

@ -27,6 +27,17 @@ class DhcpRegistry < Registry
end end
dhcp_path = Pathname.new(File.expand_path("../../dhcp.peers.conf", __FILE__)) dhcp_path = Pathname.new(File.expand_path("../../dhcp.peers.conf", __FILE__))
File.open(dhcp_path, "w+").write(dhcp_template.render(leases: static_leases)) File.open(dhcp_path, "w+").write(dhcp_template.render(leases: static_leases))
reload_dhcp
end
def reload_dhcp
command = try(data, "host", "reload_command")
if command.nil?
puts "skip to reload dhcpd because reload_command is not defined"
else
sh(command)
end
end end
end end

View File

@ -113,9 +113,8 @@ class OpenvpnRegistry < Registry
end end
def service_command(command_type, peer_name) def service_command(command_type, peer_name)
openvpn = @host["openvpn"] || {}
cmd_name = "#{command_type}_command" cmd_name = "#{command_type}_command"
command = openvpn[cmd_name] command = try(@host, "openvpn", cmd_name)
if command.nil? if command.nil?
puts "skip to #{command_type} openvpn because #{cmd_name} is not defined" puts "skip to #{command_type} openvpn because #{cmd_name} is not defined"
else else

View File

@ -41,6 +41,18 @@ def die(msg)
exit(1) exit(1)
end end
def try(hash, *args)
result = hash
args.each do |arg|
if result.respond_to?(:[]) && result[arg]
result = result[arg]
else
return nil
end
end
result
end
class TemplateContext < OpenStruct class TemplateContext < OpenStruct
def get_binding def get_binding
binding binding