mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Tweaks to get it running. No python support yet, but the basics now seem to work.
This commit is contained in:
@@ -171,6 +171,7 @@ impl EtcLqos {
|
||||
}
|
||||
|
||||
pub(crate) fn load_from_string(raw: &str) -> Result<Self, EtcLqosError> {
|
||||
log::info!("Trying to load old TOML version from /etc/lqos.conf");
|
||||
let document = raw.parse::<Document>();
|
||||
match document {
|
||||
Err(e) => {
|
||||
@@ -188,6 +189,7 @@ impl EtcLqos {
|
||||
Err(e) => {
|
||||
error!("Unable to parse TOML from /etc/lqos.conf");
|
||||
error!("Full error: {:?}", e);
|
||||
panic!();
|
||||
Err(EtcLqosError::CannotParseToml)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ pub enum MigrationError {
|
||||
}
|
||||
|
||||
pub fn migrate_if_needed() -> Result<(), MigrationError> {
|
||||
log::info!("Checking config file version");
|
||||
let raw =
|
||||
std::fs::read_to_string("/etc/lqos.conf").map_err(|e| MigrationError::ReadError(e))?;
|
||||
|
||||
@@ -30,11 +31,12 @@ pub fn migrate_if_needed() -> Result<(), MigrationError> {
|
||||
.parse::<Document>()
|
||||
.map_err(|e| MigrationError::ParseError(e))?;
|
||||
if let Some((_key, version)) = doc.get_key_value("version") {
|
||||
if version.as_str().unwrap() == "1.5.0" {
|
||||
log::info!("Configuration file is already at version 1.5.0, no migration needed");
|
||||
log::info!("Configuration file is at version {}", version.as_str().unwrap());
|
||||
if version.as_str().unwrap().trim() == "1.5" {
|
||||
log::info!("Configuration file is already at version 1.5, no migration needed");
|
||||
return Ok(());
|
||||
} else {
|
||||
log::error!("Configuration file is at version {}, but this version of lqos only supports version 1.5.0", version.as_str().unwrap());
|
||||
log::error!("Configuration file is at version {}, but this version of lqos only supports version 1.5", version.as_str().unwrap());
|
||||
return Err(MigrationError::UnknownVersion(
|
||||
version.as_str().unwrap().to_string(),
|
||||
));
|
||||
|
||||
@@ -17,9 +17,9 @@ static CONFIG: Mutex<Option<Config>> = Mutex::new(None);
|
||||
|
||||
/// Load the configuration from `/etc/lqos.conf`.
|
||||
pub fn load_config() -> Result<Config, LibreQoSConfigError> {
|
||||
log::info!("Loading configuration file /etc/lqos.conf");
|
||||
let mut lock = CONFIG.lock().unwrap();
|
||||
if lock.is_none() {
|
||||
log::info!("Loading configuration file /etc/lqos.conf");
|
||||
migrate_if_needed().map_err(|e| {
|
||||
log::error!("Unable to migrate configuration: {:?}", e);
|
||||
LibreQoSConfigError::FileNotFoud
|
||||
@@ -41,9 +41,11 @@ pub fn load_config() -> Result<Config, LibreQoSConfigError> {
|
||||
config_result
|
||||
)));
|
||||
}
|
||||
log::info!("Set cached version of config file");
|
||||
*lock = Some(config_result.unwrap());
|
||||
}
|
||||
|
||||
log::info!("Returning cached config");
|
||||
Ok(lock.as_ref().unwrap().clone())
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,7 @@ fn isp_config_py_path(cfg: &EtcLqos) -> PathBuf {
|
||||
|
||||
/// Does thie ispConfig.py file exist?
|
||||
fn config_exists(cfg: &EtcLqos) -> bool {
|
||||
if let Ok(cfg) = crate::etc::EtcLqos::load() {
|
||||
isp_config_py_path(&cfg).exists()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
isp_config_py_path(&cfg).exists()
|
||||
}
|
||||
|
||||
fn from_python<'a, T>(py: &'a Python, variable_name: &str) -> Result<T, PythonMigrationError>
|
||||
|
||||
@@ -80,9 +80,9 @@ impl Config {
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if self.version != "1.5" {
|
||||
if self.version.trim() != "1.5" {
|
||||
return Err(format!(
|
||||
"Configuration file is at version {}, but this version of lqos only supports version 1.5.0",
|
||||
"Configuration file is at version [{}], but this version of lqos only supports version 1.5.0",
|
||||
self.version
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::etc;
|
||||
use dashmap::DashSet;
|
||||
use log::{error, info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -105,7 +104,7 @@ impl NetworkJson {
|
||||
/// file.
|
||||
pub fn path() -> Result<PathBuf, NetworkJsonError> {
|
||||
let cfg =
|
||||
etc::EtcLqos::load().map_err(|_| NetworkJsonError::ConfigLoadError)?;
|
||||
crate::load_config().map_err(|_| NetworkJsonError::ConfigLoadError)?;
|
||||
let base_path = Path::new(&cfg.lqos_directory);
|
||||
Ok(base_path.join("network.json"))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use log::error;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::etc;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
@@ -11,14 +9,14 @@ const PYTHON_PATH: &str = "/usr/bin/python3";
|
||||
|
||||
fn path_to_libreqos() -> Result<PathBuf, ProgramControlError> {
|
||||
let cfg =
|
||||
etc::EtcLqos::load().map_err(|_| ProgramControlError::ConfigLoadError)?;
|
||||
crate::load_config().map_err(|_| ProgramControlError::ConfigLoadError)?;
|
||||
let base_path = Path::new(&cfg.lqos_directory);
|
||||
Ok(base_path.join("LibreQoS.py"))
|
||||
}
|
||||
|
||||
fn working_directory() -> Result<PathBuf, ProgramControlError> {
|
||||
let cfg =
|
||||
etc::EtcLqos::load().map_err(|_| ProgramControlError::ConfigLoadError)?;
|
||||
crate::load_config().map_err(|_| ProgramControlError::ConfigLoadError)?;
|
||||
let base_path = Path::new(&cfg.lqos_directory);
|
||||
Ok(base_path.to_path_buf())
|
||||
}
|
||||
|
||||
@@ -34,9 +34,11 @@ impl ConfigShapedDevices {
|
||||
/// file.
|
||||
pub fn path() -> Result<PathBuf, ShapedDevicesError> {
|
||||
let cfg =
|
||||
etc::EtcLqos::load().map_err(|_| ShapedDevicesError::ConfigLoadError)?;
|
||||
crate::load_config().map_err(|_| ShapedDevicesError::ConfigLoadError)?;
|
||||
let base_path = Path::new(&cfg.lqos_directory);
|
||||
Ok(base_path.join("ShapedDevices.csv"))
|
||||
let full_path = base_path.join("ShapedDevices.csv");
|
||||
log::info!("ShapedDevices.csv path: {:?}", full_path);
|
||||
Ok(full_path)
|
||||
}
|
||||
|
||||
/// Does ShapedDevices.csv exist?
|
||||
@@ -146,7 +148,7 @@ impl ConfigShapedDevices {
|
||||
/// Saves the current shaped devices list to `ShapedDevices.csv`
|
||||
pub fn write_csv(&self, filename: &str) -> Result<(), ShapedDevicesError> {
|
||||
let cfg =
|
||||
etc::EtcLqos::load().map_err(|_| ShapedDevicesError::ConfigLoadError)?;
|
||||
crate::load_config().map_err(|_| ShapedDevicesError::ConfigLoadError)?;
|
||||
let base_path = Path::new(&cfg.lqos_directory);
|
||||
let path = base_path.join(filename);
|
||||
let csv = self.to_csv_string()?;
|
||||
|
||||
Reference in New Issue
Block a user