mirror of https://github.com/sipwise/ngcpcfg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
991 B
38 lines
991 B
[%
|
|
# vi: ft=tt2
|
|
|
|
# Returns the network address of a certain interface type for a given host.
|
|
#
|
|
# @param argv.host The hostname to get the interface from.
|
|
# @param argv.type The interface type, one of:
|
|
# web_int, web_ext, sip_int, sip_ext, ...
|
|
# @return out The network address in CDIR format.
|
|
|
|
IF !hosts.${argv.host}.defined;
|
|
argv.host = 'self';
|
|
END;
|
|
|
|
out = '';
|
|
FOREACH iface IN hosts.${argv.host}.interfaces;
|
|
FOREACH realiface IN hosts.${argv.host}.keys;
|
|
NEXT IF realiface != iface;
|
|
NEXT UNLESS hosts.${argv.host}.$realiface.type.grep('^' _ argv.type _ '$').size();
|
|
|
|
IF hosts.${argv.host}.$realiface.ip AND
|
|
hosts.${argv.host}.$realiface.netmask;
|
|
-%]
|
|
[% PERL -%]
|
|
use Net::Netmask;
|
|
|
|
my $network = Net::Netmask->new("[% hosts.${argv.host}.${realiface}.ip %]/[% hosts.${argv.host}.${realiface}.netmask %]");
|
|
$stash->set(out => $network->desc);
|
|
[% END -%]
|
|
[%
|
|
END;
|
|
|
|
RETURN;
|
|
END;
|
|
END;
|
|
|
|
-%]
|