feat: custom hostname

This commit is contained in:
m1m1sha
2024-05-08 14:47:22 +08:00
parent c3df9ea7fa
commit 0498b55d39
10 changed files with 91 additions and 8 deletions
+17
View File
@@ -14,6 +14,9 @@ pub trait ConfigLoader: Send + Sync {
fn get_id(&self) -> uuid::Uuid;
fn set_id(&self, id: uuid::Uuid);
fn get_hostname(&self) -> String;
fn set_hostname(&self, name: Option<String>);
fn get_inst_name(&self) -> String;
fn set_inst_name(&self, name: String);
@@ -152,6 +155,7 @@ pub struct Flags {
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
struct Config {
netns: Option<String>,
hostname: Option<String>,
instance_name: Option<String>,
instance_id: Option<uuid::Uuid>,
ipv4: Option<String>,
@@ -216,6 +220,19 @@ impl ConfigLoader for TomlConfigLoader {
self.config.lock().unwrap().instance_name = Some(name);
}
fn get_hostname(&self) -> String {
self.config
.lock()
.unwrap()
.hostname
.clone()
.unwrap_or(gethostname::gethostname().to_string_lossy().to_string())
}
fn set_hostname(&self, name: Option<String>) {
self.config.lock().unwrap().hostname = name;
}
fn get_netns(&self) -> Option<String> {
self.config.lock().unwrap().netns.clone()
}