MT#55942 lib: Add multi-site support to get some network information

We need to get the network information for the remote site. So we add
a new library file, and extend the get_all_shared_ips* ones to support
specifying a site name, defaulting to 'current'.

Change-Id: Id133ba1fc62b758c0779ac5951075c10cdf5736c
mr11.5
Guillem Jover 2 years ago
parent ea151663b6
commit 7e3b07b71a

@ -0,0 +1,26 @@
[%
# vi: ft=tt2
# Return an array of shared IPs from the interface of a given type for all
# remote site nodes which act as a given role.
#
# @param argv.role The role of the node to process, one of:
# proxy, lb, mgmt
# @param argv.type The interface type of a node to extract the shared
# IP from, one of:
# web_int, web_ext, sip_int, sip_ext, ...
# @param argv.status node status [ online, offline, inactive ]
# default value: ['online', 'inactive']
# @return out The array of shared IPs.
out = [];
shared_ips = [];
FOREACH site IN sites.keys.sort;
NEXT IF sites.$site.id == sites.current.id;
argv.site = site;
PROCESS '/usr/lib/ngcp-ngcpcfg/get_all_shared_ips';
shared_ips = shared_ips.merge(out);
END;
out = shared_ips.sort;
-%]

@ -4,6 +4,7 @@
# Return an array of shared IPs from the interface of a given type for all
# nodes which act as a given role.
#
# @param argv.site The site to use, default value: current.
# @param argv.role The role of the node to process, one of:
# proxy, lb, mgmt
# @param argv.type The interface type of a node to extract the shared
@ -13,6 +14,10 @@
# default value: ['online', 'inactive']
# @return out The array of shared IPs.
IF !argv.site.length;
argv.site = 'current';
END;
IF !argv.status.size;
argv.status = ['online', 'inactive'];
END;
@ -28,18 +33,18 @@ END;
blktmp.processed_hosts = {};
out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
FOREACH host IN sites.${argv.site}.hosts.keys.sort;
NEXT UNLESS status.item(sites.${argv.site}.hosts.$host.status);
NEXT UNLESS ngcp.has_role(host, argv.role);
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH iface IN sites.${argv.site}.hosts.$host.interfaces;
NEXT UNLESS sites.${argv.site}.hosts.$host.exists(iface);
NEXT UNLESS sites.${argv.site}.hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
peer = hosts.$host.peer;
peer = sites.${argv.site}.hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$iface.shared_ip;
FOREACH ip IN sites.${argv.site}.hosts.$host.$iface.shared_ip;
NEXT UNLESS ip;
out.push(ip);
END;

@ -3,6 +3,7 @@
# Return an array of shared IPs for a given host.
#
# @param argv.site The site to use, default value: current.
# @param argv.host The host to get all shared IPs for.
# @param argv.type The interface type or empty string for all types.
# @param argv.status node status [ online, offline, inactive ]
@ -10,7 +11,11 @@
# @param argv.format Return a flat list (default) or a list of hashes ('hash')
# @return out The array of shared IPs.
IF !hosts.${argv.host}.defined;
IF !argv.site.length;
argv.site = 'current';
END;
IF !sites.${argv.site}.hosts.${argv.host}.defined;
argv.host = 'self';
END;
@ -32,23 +37,23 @@ FOREACH val IN argv.status;
END;
out = [];
IF status.item(hosts.${argv.host}.status);
FOREACH iface IN hosts.${argv.host}.interfaces;
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
IF status.item(sites.${argv.site}.hosts.${argv.host}.status);
FOREACH iface IN sites.${argv.site}.hosts.${argv.host}.interfaces;
NEXT UNLESS sites.${argv.site}.hosts.${argv.host}.exists(iface);
NEXT UNLESS sites.${argv.site}.hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH ip IN hosts.${argv.host}.$iface.shared_ip;
FOREACH ip IN sites.${argv.site}.hosts.${argv.host}.$iface.shared_ip;
NEXT UNLESS ip;
IF argv.format == 'hash';
PERL; -%]
use Net::Netmask;
my $network = Net::Netmask->new("[% ip %]/[% hosts.${argv.host}.$iface.netmask %]");
my $network = Net::Netmask->new("[% ip %]/[% sites.${argv.site}.hosts.${argv.host}.$iface.netmask %]");
$stash->set(netmask_bits => $network->bits);
[% END;
out.push({
ip = ip,
interface = iface,
netmask = hosts.${argv.host}.$iface.netmask,
netmask = sites.${argv.site}.hosts.${argv.host}.$iface.netmask,
bits = netmask_bits
});
ELSE;

Loading…
Cancel
Save