From 1c5e435a1e10b90c5614e7a8b4dea92aa9e7c8dc Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 13 Jun 2018 14:17:59 +0200 Subject: [PATCH] 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 --- lib/NGCP/Template.pm | 29 +++++++++++++++++++++++++++++ lib/get_nodename | 16 +--------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/NGCP/Template.pm b/lib/NGCP/Template.pm index 8faddede..5c6baf8a 100644 --- a/lib/NGCP/Template.pm +++ b/lib/NGCP/Template.pm @@ -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 diff --git a/lib/get_nodename b/lib/get_nodename index cac87584..74579f9b 100644 --- a/lib/get_nodename +++ b/lib/get_nodename @@ -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(); -%]