TT#37257 NGCP::Template::Object: Add new ngcp.get_ssh_pub_key function

To be able to generate an authorized_keys file from templates we need
to fetch the public ssh keys for the root user. This function will make
this task easier.

Change-Id: If8edef0e77a5f3c1167fe8dfd0e92e4d9e468a6a
changes/86/23286/3
Guillem Jover 8 years ago
parent 89fd54e83f
commit 769ef925e4

@ -150,6 +150,21 @@ sub get_mgmt_node
return;
}
sub get_ssh_pub_key
{
my ($self, $key_type) = @_;
my $ssh_keys_dir = '/etc/ngcp-config/shared-files/ssh/';
my $ssh_key_file = "$ssh_keys_dir/id_${key_type}.pub";
open my $fh, '<', $ssh_key_file or die "Error opening $ssh_key_file";
my $ssh_pub_key = <$fh>;
close $fh;
chomp $ssh_pub_key;
die "Fatal error retrieving SSH public key" unless length $ssh_pub_key;
return $ssh_pub_key;
}
1;
__END__
@ -210,6 +225,11 @@ Returns the name of the management node calling this function.
Returns the NGCP management node shared name.
=item $ssh_pub_keye = $t->get_ssh_pub_key($key_type)
Returns the SSH public key with $key_type ('rsa', 'ed25519', etc.) from
the ngcpcfg shared-files storage.
=back
=head1 AUTHOR

Loading…
Cancel
Save