TT#76851 Remove unnecessary inner-loop for interface access

The host hash contains interfaces and other keys, but one of these keys
contains a list of the interfaces, so we just need to check whether the
interface exists in the hash, instead of scanning all the keys in the
hash and matching the one that is equal to the one we are looking for
which is rather inefficient.

Change-Id: If7d49f0a0680b82cd35ffb3007666d19741372c4
changes/60/38060/1
Guillem Jover 6 years ago
parent 5001800b38
commit d1ad545c22

@ -34,16 +34,14 @@ FOREACH host IN hosts.keys.sort;
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$realiface.advertised_ip;
NEXT UNLESS ip;
out.push(ip);
END;
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$iface.advertised_ip;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -33,14 +33,12 @@ END;
out = [];
IF status.item(hosts.${argv.host}.status);
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();
FOREACH ip IN hosts.${argv.host}.$realiface.advertised_ip;
NEXT UNLESS ip;
out.push(ip);
END;
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH ip IN hosts.${argv.host}.$iface.advertised_ip;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -35,14 +35,12 @@ FOREACH host IN hosts.keys.sort;
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT IF out.grep('^' _ hosts.$host.$realiface.ip _ '$').size();
NEXT UNLESS hosts.$host.$realiface.ip;
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
NEXT IF out.grep('^' _ hosts.$host.$iface.ip _ '$').size();
NEXT UNLESS hosts.$host.$iface.ip;
out.push({ name = host, ip = hosts.$host.$realiface.ip });
END;
out.push({ name = host, ip = hosts.$host.$iface.ip });
END;
END;

@ -30,12 +30,10 @@ END;
out = [];
IF status.item(hosts.${argv.host}.status);
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();
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
out.push(realiface);
END;
out.push(iface);
END;
END;
out = out.sort;

@ -32,14 +32,12 @@ FOREACH host IN hosts.keys;
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT IF out.grep('^' _ hosts.$host.$realiface.ip _ '$').size();
NEXT UNLESS hosts.$host.$realiface.ip;
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
NEXT IF out.grep('^' _ hosts.$host.$iface.ip _ '$').size();
NEXT UNLESS hosts.$host.$iface.ip;
out.push(hosts.$host.$realiface.ip);
END;
out.push(hosts.$host.$iface.ip);
END;
END;
out = out.sort;

@ -33,13 +33,11 @@ END;
out = [];
IF status.item(hosts.${argv.host}.status);
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();
NEXT UNLESS hosts.${argv.host}.$realiface.ip;
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.${argv.host}.$iface.ip;
out.push(hosts.${argv.host}.$realiface.ip);
END;
out.push(hosts.${argv.host}.$iface.ip);
END;
END;
out = out.sort;

@ -34,16 +34,14 @@ FOREACH host IN hosts.keys.sort;
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$realiface.shared_ip;
NEXT UNLESS ip;
out.push(ip);
END;
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$iface.shared_ip;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -33,14 +33,12 @@ END;
out = [];
IF status.item(hosts.${argv.host}.status);
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();
FOREACH ip IN hosts.${argv.host}.$realiface.shared_ip;
NEXT UNLESS ip;
out.push(ip);
END;
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH ip IN hosts.${argv.host}.$iface.shared_ip;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -35,19 +35,17 @@ FOREACH host IN hosts.keys.sort;
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$realiface.shared_v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
FOREACH ip IN hosts.$host.$iface.shared_v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -34,17 +34,15 @@ END;
out = [];
IF status.item(hosts.${argv.host}.status);
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();
FOREACH ip IN hosts.${argv.host}.$realiface.shared_v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH ip IN hosts.${argv.host}.$iface.shared_v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -33,17 +33,15 @@ FOREACH host IN hosts.keys.sort;
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.$host.exists(iface);
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH ip IN hosts.$host.$realiface.v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
FOREACH ip IN hosts.$host.$iface.v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -35,17 +35,15 @@ END;
out = [];
IF status.item(hosts.${argv.host}.status);
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();
FOREACH ip IN hosts.${argv.host}.$realiface.v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
FOREACH ip IN hosts.${argv.host}.$iface.v6ip;
IF argv.format == 'expand';
ip = ngcp.net_ip_expand(ip);
END;
NEXT UNLESS ip;
out.push(ip);
END;
END;
END;

@ -11,25 +11,20 @@ host = ngcp.get_hostname();
out = [];
FOREACH iface IN hosts.${host}.interfaces;
FOREACH realiface IN hosts.${host}.keys;
IF realiface == iface;
IF hosts.${host}.$realiface.gateway;
NEXT UNLESS hosts.${host}.exists(iface);
NEXT UNLESS hosts.${host}.$iface.gateway;
IF argv.gw == 'yes';
out.push(hosts.${host}.$realiface.gateway);
END;
IF argv.dns == 'yes';
FOREACH dns_server_ip IN hosts.${host}.${realiface}.dns_nameservers;
out.push(dns_server_ip);
END;
END;
IF argv.gw == 'yes';
out.push(hosts.${host}.$iface.gateway);
END;
END;
IF argv.dns == 'yes';
FOREACH dns_server_ip IN hosts.${host}.${iface}.dns_nameservers;
out.push(dns_server_ip);
END;
END;
END;
out = out.sort;
-%]
-%]

@ -14,13 +14,11 @@ 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();
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
out = realiface;
RETURN;
END;
out = iface;
RETURN;
END;
-%]

@ -14,24 +14,20 @@ 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();
NEXT UNLESS hosts.${argv.host}.exists(iface);
NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size();
IF hosts.${argv.host}.$realiface.ip AND
hosts.${argv.host}.$realiface.netmask;
-%]
[% PERL -%]
IF hosts.${argv.host}.$iface.ip AND
hosts.${argv.host}.$iface.netmask;
PERL -%]
use Net::Netmask;
my $network = Net::Netmask->new("[% hosts.${argv.host}.${realiface}.ip %]/[% hosts.${argv.host}.${realiface}.netmask %]");
my $network = Net::Netmask->new("[% hosts.${argv.host}.${iface}.ip %]/[% hosts.${argv.host}.${iface}.netmask %]");
$stash->set(out => $network->desc);
[% END -%]
[%
END;
RETURN;
[% END;
END;
RETURN;
END;
-%]

Loading…
Cancel
Save