TT#38200 Switch to new perl ngcp.has_role function

This replaces the old has_role Template "function" with a proper method
of the ngcp object, anywhere we need to check for the host role,
including other macros that could not use our previous "function"
before. Which will make it possible to modify the has_role behavior in
a single place, and affect all code paths.

Change-Id: I73526aa77fab3dec8f33361e142164204d7c1481
changes/76/21876/7
Guillem Jover 8 years ago
parent 5104409fd4
commit 711d2321ba

@ -17,6 +17,21 @@ sub new
return bless $self, $class;
}
sub has_role
{
my ($self, $hostname, $role) = @_;
if (not defined $self->{config}{hosts}{$hostname}) {
$hostname = 'self';
}
if (any { m/^$role$/ } @{$self->{config}{hosts}{$hostname}{role}}) {
return 1;
}
return 0;
}
1;
__END__
@ -48,6 +63,10 @@ the B<ngcp> internal variable, such as C<ngcp.some_method(argument)>.
The $config argument contains the deserialized ngcp-config YAML configuration.
=item $bool = $t->has_role($hostname, $role)
Checks whether the $hostname node has the $role.
=back
=head1 AUTHOR

@ -30,7 +30,7 @@ blktmp.processed_hosts = {};
out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;

@ -31,7 +31,7 @@ FOREACH set IN cluster_sets.keys;
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size();
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();

@ -44,7 +44,7 @@ FOREACH set IN cluster_sets.keys;
FOREACH host IN set_hosts;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size();
NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size();

@ -34,7 +34,7 @@ FOREACH set IN cluster_sets.keys;
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT IF blktmp.processed_hosts.$host.defined;
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
peer = hosts.$host.peer;
FOREACH iface IN hosts.$host.interfaces;
NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size();

@ -46,7 +46,7 @@ FOREACH set IN cluster_sets.keys;
FOREACH host IN set_hosts;
NEXT UNLESS status.item(hosts.$host.status);
NEXT IF blktmp.processed_hosts.$host.defined;
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
peer = hosts.$host.peer;
FOREACH iface IN hosts.$host.interfaces;
NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size();

@ -28,7 +28,7 @@ FOREACH set IN cluster_sets.keys;
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.type _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size();
out.$set = cluster_sets.$set.dispatcher_id;

@ -32,7 +32,7 @@ END;
out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;

@ -29,7 +29,7 @@ END;
out = [];
FOREACH host IN hosts.keys;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;

@ -24,9 +24,8 @@ X_out = {};
FOREACH X_host IN hosts.keys;
X_hd = hosts.$X_host;
X_roles = X_hd.role;
NEXT UNLESS status.item(X_hd.status);
NEXT IF X_roles.grep('^rtp$').size() == 0;
NEXT UNLESS ngcp.has_role(X_host, 'rtp');
FOREACH X_iface IN X_hd.interfaces;
X_if = X_hd.$X_iface;

@ -30,7 +30,7 @@ blktmp.processed_hosts = {};
out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;

@ -28,7 +28,7 @@ out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT IF blktmp.processed_hosts.$host.defined;
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
peer = hosts.$host.peer;
blktmp.processed_hosts.$peer = 1;
matches = host.match('^(\w+[0-9])[ab]$');

@ -31,7 +31,7 @@ blktmp.processed_hosts = {};
out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
NEXT IF blktmp.processed_hosts.$host.defined;
FOREACH iface IN hosts.$host.interfaces;

@ -29,7 +29,7 @@ END;
out = [];
FOREACH host IN hosts.keys.sort;
NEXT UNLESS status.item(hosts.$host.status);
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;

@ -10,10 +10,7 @@ ngcp_type = out;
IF ngcp_type == 'carrier';
FOREACH host IN hosts.keys;
argv.host = host;
argv.role = 'mgmt';
PROCESS '/usr/lib/ngcp-ngcpcfg/has_role';
is_mgmt = out;
is_mgmt = ngcp.has_role(host, 'mgmt');
IF is_mgmt;
matches = host.match('^(\w+[0-9])[ab]?$');
out = matches.0;

@ -13,7 +13,7 @@
out = {};
FOREACH host IN hosts.keys;
NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();
NEXT UNLESS ngcp.has_role(host, argv.role);
FOREACH iface IN hosts.$host.interfaces;
FOREACH realiface IN hosts.$host.keys;

@ -8,13 +8,6 @@
# proxy, lb, mgmt
# @return out 0 if false, 1 if true.
IF !hosts.${argv.host}.defined;
argv.host = 'self';
END;
out = 0;
IF hosts.${argv.host}.role.grep('^' _ argv.role _ '$').size();
out = 1;
END;
out = ngcp.has_role(argv.host, argv.role);
-%]

Loading…
Cancel
Save