From 74a69302a752ddd12b03671a91d14f50c7cfb123 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 18 Jan 2019 09:58:15 +0100 Subject: [PATCH] tools.rs: new helper nodename() --- src/tools.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/tools.rs b/src/tools.rs index 6f14f812..3d95b184 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -6,6 +6,8 @@ use failure::*; use nix::unistd; use nix::sys::stat; +use lazy_static::lazy_static; + use std::fs::{File, OpenOptions}; use std::io::Write; use std::path::Path; @@ -227,6 +229,23 @@ pub fn file_chunker( Ok(()) } +pub fn nodename() -> &'static str { + + lazy_static!{ + static ref NODENAME: String = { + + let utsname = nix::sys::utsname::uname(); + let nodename = utsname.nodename(); + + let parts: Vec<&str> = nodename.split('.').collect(); + + parts[0].to_owned() + }; + } + + &NODENAME +} + pub fn required_string_param<'a>(param: &'a Value, name: &str) -> Result<&'a str, Error> { match param[name].as_str() { Some(s) => Ok(s),