add nodename helper (copied from proxmox-backup)

This commit is contained in:
Dietmar Maurer 2019-08-03 17:00:02 +02:00
parent ce18d8c035
commit d6d65be42e
2 changed files with 20 additions and 1 deletions

View File

@ -10,7 +10,7 @@ authors = [
[dependencies]
failure = "0.1"
libc = "0.2"
nix = "0.13"
nix = "0.14"
proxmox-tools = { path = "../proxmox-tools" }
lazy_static = "1.1"
regex = "1.0"

View File

@ -1,6 +1,7 @@
//! This is a general utility crate used by all our rust projects.
use failure::*;
use lazy_static::lazy_static;
pub mod common_regex;
pub mod io;
@ -146,3 +147,21 @@ pub fn hex_to_digest(hex: &str) -> Result<[u8; 32], Error> {
Ok(digest)
}
/// Returns the hosts node name (UTS node name)
pub fn nodename() -> &'static str {
lazy_static!{
static ref NODENAME: String = {
nix::sys::utsname::uname()
.nodename()
.split('.')
.next()
.unwrap()
.to_owned()
};
}
&NODENAME
}