Revision b65f3926
Added by Ohad Levy over 13 years ago
- ID b65f3926eeed723e71846330100a55f7453fdfa4
lib/dns_api.rb | ||
---|---|---|
def setup(opts)
|
||
@server = Proxy::DNS::Bind.new(opts)
|
||
end
|
||
post "/dns" do
|
||
fqdn = params[:fqdn]
|
||
|
||
post "/dns/" do
|
||
fqdn = params[:fqdn]
|
||
value = params[:value]
|
||
type = params[:type]
|
||
type = params[:type]
|
||
begin
|
||
setup({:fqdn => fqdn, :value => value, :type => type})
|
||
halt 400 unless @server.create
|
||
rescue Exception => e.to_s
|
||
halt 400, e
|
||
status = @server.create
|
||
halt 400, "DNS create failed for #{fqdn}" unless status
|
||
rescue Exception => e
|
||
halt 400, e.to_s
|
||
end
|
||
end
|
||
|
||
... | ... | |
end
|
||
begin
|
||
setup({:fqdn => fqdn, :value => value, :type => type})
|
||
halt 400 unless @server.remove
|
||
halt 400, "DNS delete failed for #{fqdn}" unless @server.remove
|
||
rescue => e
|
||
halt 400, e.to_s
|
||
end
|
lib/tftp_api.rb | ||
---|---|---|
begin
|
||
Proxy::TFTP.fetch_boot_file(params[:prefix], params[:path])
|
||
rescue => e
|
||
halt 400, e
|
||
halt 400, e.to_s
|
||
end
|
||
end
|
||
|
||
... | ... | |
mac = params[:mac]
|
||
syslinux = params[:syslinux_config]
|
||
begin
|
||
halt 400 unless Proxy::TFTP.create(mac, syslinux)
|
||
rescue Exception => e.to_s
|
||
halt 400, e
|
||
halt 400, "Failed to create a tftp reservation for #{mac}" unless Proxy::TFTP.create(mac, syslinux)
|
||
rescue Exception => e
|
||
halt 400, e.to_s
|
||
end
|
||
end
|
||
|
||
# delete a record from a network
|
||
delete "/tftp/:mac" do
|
||
halt 400 unless Proxy::TFTP.remove(params[:mac])
|
||
begin
|
||
halt 400, "Failed to remove tftp reservation for #{params[:mac]}" unless Proxy::TFTP.remove(params[:mac])
|
||
rescue => e
|
||
halt 400, e.to_s
|
||
end
|
||
end
|
||
|
Also available in: Unified diff
Added more verbose errors upon API requests
based on pikelly patches