From 24f692344e2e3be5cbbe576e4e91606774a5ad33 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 20 Jun 2018 01:24:32 +0200 Subject: [PATCH] TT#38200 Switch to new perl ngcp.get_hostname() function Change-Id: I87ca33c497e9a474abb1d57447369f74db1e7da1 --- lib/NGCP/Template.pm | 19 +++++++++++++++++++ lib/get_hostname | 13 +++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/NGCP/Template.pm b/lib/NGCP/Template.pm index 13705833..dab92c75 100644 --- a/lib/NGCP/Template.pm +++ b/lib/NGCP/Template.pm @@ -32,6 +32,21 @@ sub has_role return 0; } +sub get_hostname +{ + my $self = shift; + + # Do not trust hostname(1) as this might differ from the hostname of + # the system which runs the installer, instead rely on /etc/hostname + open my $hh, '<', '/etc/hostname' or die "Error opening /etc/hostname"; + my $hostname = <$hh>; + close $hh; + chomp $hostname; + die "Fatal error retrieving hostname [$hostname]" unless length $hostname; + + return $hostname; +} + sub get_nodename { my $self = shift; @@ -117,6 +132,10 @@ The $config argument contains the deserialized ngcp-config YAML configuration. Checks whether the $hostname node has the $role. +=item $hostname = $t->get_hostname() + +Returns the hostname of the node calling this function. + =item $nodename = $t->get_nodename() Returns the nodename of the node calling this function. diff --git a/lib/get_hostname b/lib/get_hostname index 6a80bcd8..1ce602b6 100644 --- a/lib/get_hostname +++ b/lib/get_hostname @@ -4,14 +4,7 @@ # Returns the hostname of the node calling this function. # # @return out The hostname of the node calling this function. + +out = ngcp.get_hostname(); + -%] -[% PERL -%] - # Do not trust hostname(1) as this might differ from the hostname of - # the system which runs the installer, instead rely on /etc/hostname - open my $hh, '<', '/etc/hostname' or die "Error opening /etc/hostname"; - my $hostname = <$hh>; - close $hh; - chomp $hostname; - die "Fatal error retrieving hostname [$hostname]" unless length $hostname; - $stash->set(out => $hostname); -[% END -%]