MT#10093 add get_network_for_host

- returns network of a given interface in CIDR format

Change-Id: I5274f030b18c0b24a39f9d52e3173b052fa9159a
changes/85/585/1
Victor Seva 12 years ago
parent 86ae8e8d99
commit a7f8cd1617

2
debian/control vendored

@ -13,6 +13,7 @@ Build-Depends: asciidoc,
libipc-system-simple-perl,
liblist-moreutils-perl,
libnet-netmask-perl,
libnetwork-ipv4addr-perl,
libregexp-ipv6-perl,
libsocket-perl,
libsys-hostname-long-perl,
@ -36,6 +37,7 @@ Depends: etckeeper,
libipc-system-simple-perl,
liblist-moreutils-perl,
libnet-netmask-perl,
libnetwork-ipv4addr-perl,
libregexp-ipv6-perl,
libsocket-perl,
libsys-hostname-long-perl,

@ -0,0 +1,31 @@
[%
# 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 -%]
Loading…
Cancel
Save