Revision 7466fc08
Added by Marc Dequènes almost 14 years ago
- ID 7466fc083799a22deae3d56779823c810028f280
bin/mapmaker | ||
---|---|---|
class MapMakerValidator < CyborgHoodValidator
|
||
def validate_hook_in(value, rule, path, msg_list)
|
||
case rule.name
|
||
when 'MasterZonePattern'
|
||
when 'MasterZonePattern', 'SignedMasterZonePattern', 'SlaveZonePattern'
|
||
if value.gsub('#ZONE#', 'test') == value
|
||
msg_list << "pattern is constant"
|
||
end
|
||
... | ... | |
|
||
include BotNet
|
||
|
||
def interface
|
||
MapMakerInterface.instance
|
||
end
|
||
end
|
||
|
||
class MapMakerInterface
|
||
include CyborgServerInterface
|
||
include CyborgServerRootInterfaceAddon
|
||
|
||
class Taiste
|
||
include CyborgServerInterface
|
||
|
||
def api_methods
|
||
["coucou", "toto", "plop"]
|
||
end
|
||
|
||
dynamic_interface {|node_name| ">>> #{node_name} <<<" }
|
||
end
|
||
|
||
class DNS < Services::DNS::System
|
||
include CyborgServerInterface
|
||
|
||
export_parent_methods
|
||
unexport_method :zones, :'[]'
|
||
|
||
def test(data)
|
||
"coucou: " + data.inspect
|
||
end
|
||
|
||
class Zones
|
||
include CyborgServerStatefulInterface
|
||
|
||
def initialize
|
||
@dns = Services::DNS::System.new
|
||
end
|
||
|
||
def api_methods
|
||
@dns.zones
|
||
end
|
||
|
||
def api_container_methods
|
||
api_methods
|
||
def setup
|
||
super
|
||
|
||
define_interface "0.1~" do
|
||
node "DNS" do
|
||
dns = Services::DNS::System.new
|
||
on_request do |request|
|
||
request.reply.results = {
|
||
:type => dns.type
|
||
}
|
||
end
|
||
node "check_config" do
|
||
on_request do |request|
|
||
request.reply.results = dns.check_config
|
||
end
|
||
end
|
||
node "Zones" do
|
||
zone_list = Proc.new{dns.zones}
|
||
node zone_list do
|
||
zone = Services::DNS::Zone.new(node_name)
|
||
on_request do |request|
|
||
request.reply.results = {
|
||
:master => zone.master?,
|
||
:signed => zone.signed?,
|
||
:serial => zone.serial_in_dns
|
||
}
|
||
if zone.master?
|
||
reply.results.merge!({
|
||
:serial_in_zone_file => zone.serial_in_zone_file,
|
||
:serial_in_signed_zone_file => zone.serial_in_signed_zone_file
|
||
})
|
||
end
|
||
end
|
||
node "content" do
|
||
on_request do |request|
|
||
request.reply.results = {:content => zone.content}
|
||
end
|
||
end
|
||
node "content=" do
|
||
on_request do |request|
|
||
content = request.args.shift
|
||
if content.nil?
|
||
request.errors << "Zone content missing"
|
||
end
|
||
|
||
zone.content = content
|
||
if zone.changed?
|
||
check_result = zone.check
|
||
if check_result[:ok]
|
||
reply.warnings = check_result[:warnings]
|
||
# zone signer automatically handles serial bump
|
||
if check_result[:serial] > zone.serial or zone.signed?
|
||
zone.save
|
||
zone.activate
|
||
else
|
||
reply.errors << _("Zone serial is not superior to current serial.")
|
||
end
|
||
else
|
||
reply.errors = check_result[:errors]
|
||
zone.cancel_changes
|
||
end
|
||
else
|
||
reply.warnings << _("Zone is unmodified (same content)")
|
||
zone.cancel_changes
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
stateful_dynamic_interface("DnsZone/#NODE#") {|node_name| DnsZone.new(node_name) }
|
||
end
|
||
end # interface
|
||
end
|
||
end
|
||
|
||
class DnsZone < Services::DNS::Zone
|
||
include CyborgServerEmbeddedInterface
|
||
end
|
||
end # class MapMaker
|
||
end
|
||
end
|
||
|
Also available in: Unified diff
[evol] server API tree reworked using a DSL (reply handling rework is WIP)