TT#38200 Switch to new perl ngcp.get_nodename() function

This is another good candidate to replace with a proper ngcp method, as
the function is already implemented as a PERL block, and the most used
"function".

Change-Id: I49dc638a197a0215ea65c0a60c82c6c556aca3fa
changes/77/21877/7
Guillem Jover 8 years ago
parent 711d2321ba
commit 1c5e435a1e

@ -32,6 +32,31 @@ sub has_role
return 0;
}
sub get_nodename
{
my $self = shift;
return $self->{nodename} if exists $self->{nodename};
my $filename = '/etc/ngcp_ha_node';
$filename = '/etc/ngcp_nodename' unless -f $filename;
open my $hh, '<', $filename or die "Error opening $filename";
my $nodename = <$hh>;
close $hh;
chomp $nodename;
die "Fatal error retrieving nodename [$nodename]" unless length $nodename;
if (defined $self->{config}{hosts}{self} and
not defined $self->{config}{hosts}{$nodename}) {
$nodename = 'self';
}
$self->{nodename} = $nodename;
return $nodename;
}
1;
__END__
@ -67,6 +92,10 @@ The $config argument contains the deserialized ngcp-config YAML configuration.
Checks whether the $hostname node has the $role.
=item $nodename = $t->get_nodename()
Returns the nodename of the node calling this function.
=back
=head1 AUTHOR

@ -4,21 +4,7 @@
# Returns the nodename of the node calling this function.
#
# @return out The nodename of the node calling this function.
-%]
[% PERL -%]
my $filename = '/etc/ngcp_ha_node';
$filename = '/etc/ngcp_nodename' unless -f $filename;
open my $hh, '<', $filename or die "Error opening $filename";
my $nodename = <$hh>;
close $hh;
chomp $nodename;
die "Fatal error retrieving nodename [$nodename]" unless length $nodename;
$stash->set(out => $nodename);
[% END -%]
[%-
IF hosts.self.defined && !hosts.${out}.defined;
out = 'self';
END;
out = ngcp.get_nodename();
-%]

Loading…
Cancel
Save