diff --git a/lib/NGCP/Template.pm b/lib/NGCP/Template.pm index 2f43a3b3..13705833 100644 --- a/lib/NGCP/Template.pm +++ b/lib/NGCP/Template.pm @@ -68,6 +68,20 @@ sub get_peername return $self->{config}{hosts}{$hostname}{peer}; } +sub get_firstname +{ + my ($self, $hostname) = @_; + + if (not defined $self->{config}{hosts}{$hostname}) { + return 'self'; + } else { + my $peername = $self->get_peername($hostname); + my @hosts = ($hostname, $peername); + + return (sort @hosts)[0]; + } +} + 1; __END__ @@ -111,6 +125,11 @@ Returns the nodename of the node calling this function. Returns the peer name for a given $hostname. +=item $firstname = $t->get_firstname($hostname) + +Returns the (alphabetically) first hostname of a node pair for a given +$hostname. + =back =head1 AUTHOR diff --git a/lib/get_firstname b/lib/get_firstname index 528e2078..2d825496 100644 --- a/lib/get_firstname +++ b/lib/get_firstname @@ -6,14 +6,6 @@ # @param argv.host The hostname to get the first name for. # @return out The alphabetically first name. -IF !hosts.${argv.host}.defined; - argv.host = 'self'; -END; - -blktmp.hosts = [argv.host]; -IF hosts.${argv.host}.peer.defined; - blktmp.hosts.push(hosts.${argv.host}.peer); -END; -out = blktmp.hosts.sort.0; +out = ngcp.get_firstname(argv.host); -%]