Ian Main
2009-Feb-10 21:40 UTC
[Ovirt-devel] [PATCH server] Use DNS SRV records for qpidd on appliance
This patch makes taskomatic and dbomatic etc. use dns srv records when connecting to qpidd. This fixes the installer problems we were seeing when connecting to various host names. Signed-off-by: Ian Main <imain at redhat.com> --- src/db-omatic/db_omatic.rb | 6 +++++- src/dutils/dutils.rb | 32 ++++++++++++++++++++++++++++++++ src/qmf-libvirt-example.rb | 5 ++++- src/task-omatic/taskomatic.rb | 7 +++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/db-omatic/db_omatic.rb b/src/db-omatic/db_omatic.rb index 06adc19..845a714 100755 --- a/src/db-omatic/db_omatic.rb +++ b/src/db-omatic/db_omatic.rb @@ -327,8 +327,12 @@ def main() get_credentials('qpidd') dbsync = DbOmatic.new() + + server, port = get_srv('qpidd', 'tcp') + raise "Unable to determine qpid server from DNS SRV record" if not server + s = Qpid::Qmf::Session.new(:console => dbsync, :rcv_events => false) - b = s.add_broker("amqp://management.priv.ovirt.org:5672", :mechanism => 'GSSAPI') + b = s.add_broker("amqp://#{server}:#{port}", :mechanism => 'GSSAPI') dbsync.db_init_cleanup() diff --git a/src/dutils/dutils.rb b/src/dutils/dutils.rb index 6df2f06..5b2ac50 100644 --- a/src/dutils/dutils.rb +++ b/src/dutils/dutils.rb @@ -18,6 +18,8 @@ require 'active_record_env' require 'krb5_auth' +require 'resolv' + include Krb5Auth ENV['KRB5CCNAME'] = '/usr/share/ovirt-server/ovirt-cc' @@ -56,3 +58,33 @@ def get_credentials(service = 'libvirt') end end end + +# Returns the server and port of the specified service using DNS SRV records +# to perform the look up. +# +# For example: +# +# server, port = get_srv('qpidd', 'tcp') +# +def get_srv(service, proto) + server = nil + port = nil + + Resolv::DNS.open do |dns| + begin + hostname = Socket.gethostbyname(Socket.gethostname).first + lst = hostname.split('.') + lst.shift + domainname = lst.join('.') + res = dns.getresource("_#{service}._#{proto}.#{domainname}", Resolv::DNS::Resource::IN::SRV) + server = res.target.to_s + port = res.port + rescue => ex + puts "Error looking up SRV record: #{ex}" + end + dns.close + end + + return server, port +end + diff --git a/src/qmf-libvirt-example.rb b/src/qmf-libvirt-example.rb index f8d6aca..64e3ba7 100644 --- a/src/qmf-libvirt-example.rb +++ b/src/qmf-libvirt-example.rb @@ -8,8 +8,11 @@ require "dutils" get_credentials('qpidd') +server, port = get_srv('qpidd', 'tcp') +raise "Unable to determine qpid server from DNS SRV record" if not server + s = Qpid::Qmf::Session.new() -b = s.add_broker("amqp://management.priv.ovirt.org:5672", :mechanism => 'GSSAPI') +b = s.add_broker("amqp://#{server}:#{port}", :mechanism => 'GSSAPI') while true: nodes = s.objects(:class => "node") diff --git a/src/task-omatic/taskomatic.rb b/src/task-omatic/taskomatic.rb index 79e2082..77fe6da 100755 --- a/src/task-omatic/taskomatic.rb +++ b/src/task-omatic/taskomatic.rb @@ -47,8 +47,11 @@ class TaskOmatic @nth_host = 0 @session = Qpid::Qmf::Session.new() - # FIXME: Should come from some kind of config or DNS SRV or what have you. - @broker = @session.add_broker("amqp://management.priv.ovirt.org:5672", :mechanism => 'GSSAPI') + + server, port = get_srv('qpidd', 'tcp') + raise "Unable to determine qpid server from DNS SRV record" if not server + + @broker = @session.add_broker("amqp://#{server}:#{port}", :mechanism => 'GSSAPI') do_daemon = true -- 1.6.0.4
Alan Pevec
2009-Feb-11 10:37 UTC
[Ovirt-devel] [PATCH server] Use DNS SRV records for qpidd on appliance
> + Resolv::DNS.open do |dns| > + begin > + hostname = Socket.gethostbyname(Socket.gethostname).first > + lst = hostname.split('.') > + lst.shift > + domainname = lst.join('.')there really isn't something like getdomainname in ruby lib?> + res = dns.getresource("_#{service}._#{proto}.#{domainname}", Resolv::DNS::Resource::IN::SRV) > + server = res.target.to_s > + port = res.portThis assumes that hostname is correctly set - I had reports where this wasn't the case, hence the following patch for the node: http://git.et.redhat.com/?p=ovirt-node.git;a=commitdiff;h=378b5f90b01e471cdf19d51fa7e81fa3139f9b80 where all search domains, as defined in resolve.conf, are tried. Is there equivalent for dig +search option in Resolve::DNS ?