2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/puppet/parser/functions/format_interface.rb', line 2
newfunction(:format_interface, :type => :rvalue,:doc => <<-EOS
EOS
) do |args|
out_rx = /^out(going)?$/i
in_rx = /^in(coming)?$/i
int_rx = /^[a-z0-9\.\-_]+\+?$/i
return '' if args == nil or args[0] == :undef
interface = ''
interface = String(args[0]).dup
raise Puppet::ParseError, "non-string interface passed - #{interface}" \
unless interface.kind_of?(String)
return interface if interface == ''
direction = 'in'
direction = args[1] unless args[1] == nil
raise Puppet::ParseError, "invalid direction specified - #{direction}" \
unless direction =~ /(#{out_rx}|#{in_rx})/i
raise Puppet::ParseError, "bad interface name passed - #{interface}" \
unless interface =~ int_rx
return "-o #{interface}" if direction =~ out_rx
return "-i #{interface}"
end
|