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

Change-Id: I87ca33c497e9a474abb1d57447369f74db1e7da1
changes/73/22073/3
Guillem Jover 8 years ago
parent 5d35213a3a
commit 24f692344e

@ -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.

@ -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 -%]

Loading…
Cancel
Save