Project

General

Profile

« Previous | Next » 

Revision 849a61fb

Added by Marc Dequènes about 13 years ago

  • ID 849a61fbc6316122e796c45804ce367dfe50f3dd

[evol] Librarian API work §1, using DI too

View differences:

bin/librarian
# to allow in-place run for test
$: << File.join(File.dirname(__FILE__), "..", "lib")
require 'needle'
require 'cyborghood/cyborg'
module CyborgHood
module LibrarianHome
module LibrarianLand
include I18nTranslation
bindtextdomain("cyborghood_librarian", {:path => Config::L10N_DIR, :charset => "UTF-8"})
......
def setup
super
define_interface "0.1~" do
node "Gruik" do
node ["g1", "g2", "g3"] do
on_request do |request|
request.reply.results = {
:plouf => ">>> #{node_name} <<<"
}
end
end
end
end
define_interface "0.1~"
end
end
end
end # LibrarianLand
end
bot = CyborgHood::LibrarianHome::Librarian.new
reg = Needle::Registry.new
reg.define do |b|
b.require 'cyborghood', CyborgHood
b.require 'cyborghood-librarian/land', CyborgHood::LibrarianLand
b.bot { CyborgHood::LibrarianLand::Librarian.new(b.librarian_land) }
end
ldap_config = reg.config.ldap.marshal_dump
ldap_config[:logger] = reg.logger
begin
ActiveLdap::Base.setup_connection(ldap_config)
# force testing a connection NOW (by default ActiveLdap is doing lazy connections)
# (the loaded schema will be useful soon anyway)
# it also tests search parameters (provided to setup_connection)
ActiveLdap::Base.find(:first)
rescue
reg.logger.fatal "LDAP failure: " + $!
exit 1
end
bot = reg.bot
trap('INT') do
bot.ask_to_stop
bin/postman
end
end
# setup LDAP
ldap_config = @config.ldap.marshal_dump
ldap_config[:logger] = logger
begin
ActiveLdap::Base.setup_connection(ldap_config)
# force testing a connection NOW (by default ActiveLdap is doing lazy connections)
# (the loaded schema will be useful soon anyway)
# it also tests search parameters (provided to setup_connection)
ActiveLdap::Base.find(:first)
rescue
logger.fatal "LDAP failure: " + $!
exit 1
end
@imap = IMAP.new(@config.imap, @config.imap.min_check_interval)
logger.info "Bot '#{self.human_name}' loaded"
bin/test_client
task "compare stuff" do
ask "MapMaker", :info1, "/_cyborg_"
ask "Librarian", :info2, "/_cyborg_"
ask "MapMaker", :zones, "/Zones"
ask "Librarian", :library, "/Records"
ask "Librarian", :persons, "/Records/persons"
ask "Librarian", :dns_domains, "/Records/dns_domains"
#ask "MapMaker", :zones, "/Zones"
#ask "MapMaker", :wanted_failure, "/prout"
ask "MapMaker", :dns, "/Services/DNS"
ask "MapMaker", :dnssec, "/Services/DNSSEC"
ask "MapMaker", :zone_mp, "/Zones/milkypond.org"
ask "MapMaker", :dns_check, "/Services/DNS/check_config"
#ask "MapMaker", :dns, "/Services/DNS"
#ask "MapMaker", :dnssec, "/Services/DNSSEC"
#ask "MapMaker", :zone_mp, "/Zones/milkypond.org"
#ask "MapMaker", :dns_check, "/Services/DNS/check_config"
#ask "MapMaker", :search, "/Zones/?"
#ask "MapMaker", :search_master, "/Zones/?", {:master => true}
#ask "MapMaker", :search_slave, "/Zones/?", {:master => false}
data/cyborghood/default_config/global.yaml
botnet:
connection_type: unix_socket
params: {}
ldap:
host: localhost
port: 389
scope: sub
data/cyborghood/default_config/librarian.yaml
---
ldap:
host: localhost
port: 389
scope: sub
data/cyborghood/schema/global.yaml
mapping:
=:
type: any
# temporary location
"ldap":
type: map
required: true
name: LdapMapping
mapping:
=:
type: any
data/cyborghood/schema/librarian.yaml
---
type: map
mapping:
zzz: { type: str }
"ldap":
type: map
required: true
name: LdapMapping
mapping:
=:
type: any
lib/cyborghood-librarian/interface/0_base.rb
node 'Records' do
node ['persons', 'dns_domains'] do
on_request do |request|
request.reply.results = bot.services.records.send(node_name)
end
end
end
lib/cyborghood-librarian/interface_dsl_addons.rb
-> ldap search /?
lib/cyborghood-librarian/land.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
require 'active_ldap'
module CyborgHood
module LibrarianLand
def register_services(container)
container.namespace_define(:librarian_land) do |b|
b.records do
require 'cyborghood-librarian/records'
Records.new
end
end
end
module_function :register_services
end # LibrarianLand
end
lib/cyborghood-librarian/records.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
Dir.glob(File.join(File.dirname(__FILE__), "records", "*.rb")).each do |f|
logger.debug "Loading record definition '#{f}'"
require f
end
module CyborgHood
module LibrarianLand
class Records
def persons
LdapPerson.find(:all, :attributes => ['uid']).collect{|i| i.uid }
end
def dns_domains
LdapDnsDomain.find(:all, :attributes => ['cn']).collect{|i| i.cn }
end
end
end # LibrarianLand
end
lib/cyborghood-librarian/records/dns_domain.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
module CyborgHood
module LibrarianLand
class LdapDnsDomain < ActiveLdap::Base
ldap_mapping :dn_attribute => 'cn', :prefix => '', :classes => ['genericDomain']
def managers
list = self.manager
return [] if list.nil?
return list.collect{|dn| dn.to_s } if list.is_a? Array
return [list.to_s]
end
end
end # LibrarianLand
end
lib/cyborghood-librarian/records/person.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
module CyborgHood
module LibrarianLand
class LdapPerson < ActiveLdap::Base
ldap_mapping :dn_attribute => 'uid', :prefix => '', :classes => ['individual']
end
end # LibrarianLand
end
lib/cyborghood.rb
b.config do
Config.instance
end
b.logger do
Logger.instance
end
end
end
lib/cyborghood/objects/ldap.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
require 'active_ldap'
module CyborgHood
class LdapDnsDomain < ActiveLdap::Base
ldap_mapping :dn_attribute => 'cn', :prefix => '', :classes => ['genericDomain']
def managers
list = self.manager
return [] if list.nil?
return list.collect{|dn| dn.to_s } if list.is_a? Array
return [list.to_s]
end
end
class LdapPerson < ActiveLdap::Base
ldap_mapping :dn_attribute => 'uid', :prefix => '', :classes => ['individual']
end
end

Also available in: Unified diff