Added port autodiscovery for avahi services.
This commit is contained in:
parent
9edbc6ae12
commit
78d29ea44f
2 changed files with 32 additions and 1 deletions
|
@ -47,9 +47,14 @@ class avahi::daemon {
|
|||
# type => "_ssh._tcp",
|
||||
# }
|
||||
#
|
||||
define avahi::service($type, $port, $description = "%h", $ensure = "present", $txt = []) {
|
||||
define avahi::service($type, $port = "AUTO", $description = "%h", $ensure = "present", $txt = []) {
|
||||
|
||||
$srvtype = $type
|
||||
if $port == "AUTO" {
|
||||
$realport = avahi_service_port($srvtype)
|
||||
} else {
|
||||
$realport = $port
|
||||
}
|
||||
|
||||
file { "/etc/avahi/services/${name}.service":
|
||||
ensure => $ensure,
|
||||
|
|
26
avahi/plugins/puppet/parser/functions/avahi_service_port.rb
Normal file
26
avahi/plugins/puppet/parser/functions/avahi_service_port.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:avahi_service_port, :type => :rvalue) do |args|
|
||||
|
||||
type, name, proto = /^_([^\.]*)\._([^\.]*)$/.match(args[0]).to_a
|
||||
|
||||
port = nil
|
||||
|
||||
File.open('/etc/services', 'r') do |fd|
|
||||
while (line = fd.gets)
|
||||
begin
|
||||
port = /^#{name}[ \t]+(\d+)\/#{proto}.*/.match(line)[1]
|
||||
break
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not port
|
||||
raise Puppet::ParseError, 'Failed to get port for service %s' % type
|
||||
end
|
||||
port
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue