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.
ngcpcfg/lib/get_network_for_host

32 lines
997 B

[%
# 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 network address in CDIR format
-%]
[% PERL %]
use Net::IPv4Addr qw( ipv4_network );
[% END %]
[% IF !hosts.${argv.host}.defined -%]
[% argv.host = 'self' -%]
[% END -%]
[% out = '' -%]
[% FOREACH iface IN hosts.${argv.host}.interfaces -%]
[% FOREACH realiface IN hosts.${argv.host}.keys -%]
[% IF realiface == iface -%]
[% IF hosts.${argv.host}.$realiface.type.grep('^' _ argv.type _ '$').size()
-%]
[% IF hosts.${argv.host}.$realiface.ip and hosts.${argv.host}.$realiface.netmask -%]
[% PERL -%]
my ($ip, $netmask) = ipv4_network("[% hosts.${argv.host}.${realiface}.ip %]/[% hosts.${argv.host}.${realiface}.netmask %]");
$stash->set( 'out' => "$ip/$netmask");
[% END -%]
[% END -%]
[% RETURN -%]
[% END -%]
[% END -%]
[% END -%]
[% END -%]