Skip to content

Commit

Permalink
osdpctl: Remove Mode and add LogFile keys to device config files
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Nov 8, 2023
1 parent a94c405 commit ba793bb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion osdpctl/config/devices/cp-multiple-pd.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Mode = CP
Name = Multi-CP
NumPd = 2

[Service]
LogLevel = INFO
LogFile = /tmp/single-cp.log
PidFile = /tmp/cp-002.pid

[PD-0]
Expand Down
4 changes: 2 additions & 2 deletions osdpctl/config/devices/cp-single-pd.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Mode = CP
Name = Single-CP
NumPd = 1

[Service]
LogLevel = 6
LogLevel = INFO
LogFile = /tmp/single-cp.log
PidFile = /tmp/cp-002.pid

[PD-0]
Expand Down
3 changes: 2 additions & 1 deletion osdpctl/config/devices/pd-0.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Channel = unix::/tmp/conn-pd-0
KeyStore = /tmp/pd-0.key

[Service]
LogLevel =
LogLevel = INFO
LogFile = /tmp/pd-0.log
PidFile = /tmp/pd-0.pid

[PdCapability]
Expand Down
1 change: 1 addition & 0 deletions osdpctl/config/devices/pd-1.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Flags = EnforceSecure

[Service]
LogLevel = INFO
LogFile = /tmp/pd-0.log
PidFile = /tmp/pd-1.pid

[PdCapability]
Expand Down
25 changes: 18 additions & 7 deletions osdpctl/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ pub struct AppConfig {

impl AppConfig {
pub fn from(cfg: &Path) -> Result<Self> {
if !cfg.exists() {
let mut dir = PathBuf::from(cfg);
dir.pop();
return Ok(Self {
device_config_dir: dir,
});
}
let mut config = Ini::new();
let _ = config.load(cfg).unwrap();
let s = config.get("default", "device_config_dir").unwrap();
let device_config_dir = if s.starts_with("./") {
let mut path = PathBuf::from(cfg);
path.pop();
path.push(&s[2..]);
path = std::fs::canonicalize(&s)?;
path
} else {
PathBuf::from(s)
let path = std::fs::canonicalize(&s)?;
path
};
Ok(Self {
device_config_dir,
})
Ok(Self { device_config_dir })
}
}

Expand Down Expand Up @@ -102,6 +109,7 @@ pub struct CpConfig {
pub name: String,
pd_data: Vec<PdData>,
pub pid_file: PathBuf,
pub log_file: PathBuf,
pub log_level: String,
}

Expand All @@ -121,8 +129,9 @@ impl CpConfig {
});
}
let pid_file = PathBuf::from_str(&config.get("Service", "PidFile").unwrap())?;
let log_file = PathBuf::from_str(&config.get("Service", "LogFile").unwrap())?;
let log_level = config.get("Service", "LogLevel").unwrap();
Ok(Self { name, pd_data, pid_file, log_level })
Ok(Self { name, pd_data, pid_file, log_level, log_file })
}

pub fn pd_info(&self) -> Result<Vec<PdInfo>> {
Expand Down Expand Up @@ -155,6 +164,7 @@ pub struct PdConfig {
flags: OsdpFlag,
pub pid_file: PathBuf,
pub log_level: String,
pub log_file: PathBuf,
}

impl PdConfig {
Expand Down Expand Up @@ -184,8 +194,9 @@ impl PdConfig {
pd_cap.push(PdCapability::from_str(format!("{}:{}", key, val.as_deref().unwrap()).as_str())?);
}
let pid_file = PathBuf::from_str(&config.get("Service", "PidFile").unwrap())?;
let log_file = PathBuf::from_str(&config.get("Service", "LogFile").unwrap())?;
let log_level = config.get("Service", "LogLevel").unwrap();
Ok(Self { name, channel, address, key_store, pd_id, pd_cap, flags, pid_file, log_level })
Ok(Self { name, channel, address, key_store, pd_id, pd_cap, flags, pid_file, log_level, log_file })
}

pub fn pd_info(&self) -> Result<PdInfo> {
Expand Down Expand Up @@ -225,4 +236,4 @@ impl DeviceConfig {
DeviceConfig::PdConfig(c) => &c.name,
}
}
}
}
3 changes: 3 additions & 0 deletions osdpctl/src/pd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ impl PdDaemon {
},
OsdpCommand::KeySet(c) => {
println!("Command: {:?}", c);
let mut key = [0; 16];
key.copy_from_slice(&c.data[0..16]);
dev.key_store.store(key).unwrap();
},
OsdpCommand::Mfg(c) => {
println!("Command: {:?}", c);
Expand Down

0 comments on commit ba793bb

Please sign in to comment.