new features during cli rework
parent
848b321228
commit
afeece915c
|
|
@ -0,0 +1 @@
|
||||||
|
NOXIS_SOCKET_PATH = "/home/vladislavd/diplom_code/noxis-rs/noxis.sock"
|
||||||
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.94"
|
anyhow = "1.0.94"
|
||||||
clap = { version = "4.5.22", features = ["derive"] }
|
clap = { version = "4.5.22", features = ["derive"] }
|
||||||
|
dotenv = "0.15.0"
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
serde = { version = "1.0.215", features = ["derive"] }
|
||||||
serde_json = "1.0.133"
|
serde_json = "1.0.133"
|
||||||
thiserror = "2.0.11"
|
thiserror = "2.0.11"
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,23 @@ pub enum ConfigAction {
|
||||||
about = "To reset all config settings",
|
about = "To reset all config settings",
|
||||||
)]
|
)]
|
||||||
Reset,
|
Reset,
|
||||||
|
#[command(
|
||||||
|
about = "To get current Noxis configuration",
|
||||||
|
name = "ls"
|
||||||
|
)]
|
||||||
|
Show(EnvConfig),
|
||||||
}
|
}
|
||||||
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct EnvConfig {
|
||||||
|
// flag
|
||||||
|
#[arg(
|
||||||
|
long = "env",
|
||||||
|
action,
|
||||||
|
help = "to read environment vars configuration",
|
||||||
|
)]
|
||||||
|
pub is_env : bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct LocalConfig {
|
pub struct LocalConfig {
|
||||||
|
|
@ -148,4 +164,28 @@ pub enum ProcessAction {
|
||||||
about = "To get info about current process's services-dependencies",
|
about = "To get info about current process's services-dependencies",
|
||||||
)]
|
)]
|
||||||
Services,
|
Services,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod metrics_models {
|
||||||
|
pub enum MetricsMode {
|
||||||
|
Full,
|
||||||
|
// system
|
||||||
|
Cpu,
|
||||||
|
Memory,
|
||||||
|
Ram,
|
||||||
|
Rom,
|
||||||
|
Network,
|
||||||
|
// processes
|
||||||
|
Processes
|
||||||
|
// Config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cli {
|
||||||
|
pub fn validate_socket(mut self) -> Self {
|
||||||
|
if let Ok(path) = std::env::var("NOXIS_SOCKET_PATH") {
|
||||||
|
self.socket = path;
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum NoxisCliError {
|
pub enum NoxisCliError {
|
||||||
#[error("Can't find socket `{0}`. Error : {1}")]
|
#[error("Can't find socket `{0}`. {1}")]
|
||||||
NoxisDaemonMissing(String, String),
|
NoxisDaemonMissing(String, String),
|
||||||
#[error("Noxis CLI can't write any data to the Noxis-rs port. Check daemon and it's runtime!")]
|
#[error("Noxis CLI can't write any data to the Noxis-rs port. Check daemon and it's runtime!")]
|
||||||
PortIsNotWritable,
|
PortIsNotWritable,
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,6 @@ pub async fn try_send(cli: Cli) -> Result<()> {
|
||||||
.await
|
.await
|
||||||
.map_err(|er| NoxisCliError::CliResponseReadError(er.to_string()))?;
|
.map_err(|er| NoxisCliError::CliResponseReadError(er.to_string()))?;
|
||||||
|
|
||||||
println!("Received response: {}", String::from_utf8_lossy(&response));
|
println!("{}", String::from_utf8_lossy(&response));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,8 @@ use anyhow::Result;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()>{
|
async fn main() -> Result<()>{
|
||||||
let cli = Cli::parse();
|
dotenv::dotenv().ok();
|
||||||
|
let cli = Cli::parse().validate_socket();
|
||||||
try_send(cli).await?;
|
try_send(cli).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use log::{error, info};
|
use log::{error, info, warn};
|
||||||
use tokio::net::{ UnixStream, UnixListener };
|
use tokio::net::{ UnixStream, UnixListener };
|
||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
@ -34,7 +34,7 @@ pub async fn init_cli_pipeline(params: Arc<PrebootParams>) -> anyhow::Result<()>
|
||||||
match list.accept().await {
|
match list.accept().await {
|
||||||
Ok((socket, _)) => {
|
Ok((socket, _)) => {
|
||||||
// tokio::spawn();
|
// tokio::spawn();
|
||||||
process_connection(socket).await;
|
process_connection(socket, params.clone()).await;
|
||||||
},
|
},
|
||||||
Err(er) => {
|
Err(er) => {
|
||||||
error!("Cannot poll connection to CLI due to {}", er);
|
error!("Cannot poll connection to CLI due to {}", er);
|
||||||
|
|
@ -64,7 +64,7 @@ pub async fn init_cli_pipeline(params: Arc<PrebootParams>) -> anyhow::Result<()>
|
||||||
///
|
///
|
||||||
/// *depends on* : `tokio::net::TcpStream`
|
/// *depends on* : `tokio::net::TcpStream`
|
||||||
///
|
///
|
||||||
async fn process_connection(mut stream: UnixStream) {
|
async fn process_connection(mut stream: UnixStream, params: Arc<PrebootParams>) {
|
||||||
let mut buf = vec![0; 1024];
|
let mut buf = vec![0; 1024];
|
||||||
match stream.read(&mut buf).await {
|
match stream.read(&mut buf).await {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
|
|
@ -76,9 +76,15 @@ async fn process_connection(mut stream: UnixStream) {
|
||||||
match serde_json::from_slice::<Cli>(&buf) {
|
match serde_json::from_slice::<Cli>(&buf) {
|
||||||
Ok(cli) => {
|
Ok(cli) => {
|
||||||
info!("Received CLI request: {:?}", cli);
|
info!("Received CLI request: {:?}", cli);
|
||||||
let response = "OK";
|
match process_cli_cmd(cli, params.clone()).await {
|
||||||
if let Err(e) = stream.write_all(response.as_bytes()).await {
|
Ok(response) => {
|
||||||
error!("Failed to send response: {}", e);
|
if let Err(e) = stream.write_all(response.as_bytes()).await {
|
||||||
|
error!("Failed to send response: {}", e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(er) => {
|
||||||
|
error!("Can't send response from cli_pipeline: {}", er);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -90,3 +96,27 @@ async fn process_connection(mut stream: UnixStream) {
|
||||||
}
|
}
|
||||||
let _ = stream.shutdown().await;
|
let _ = stream.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn process_cli_cmd(cli : Cli, params: Arc<PrebootParams>) -> anyhow::Result<String> {
|
||||||
|
use noxis_cli::{Commands, ConfigAction};
|
||||||
|
return match cli.command {
|
||||||
|
Commands::Config(config) => {
|
||||||
|
match config.action {
|
||||||
|
ConfigAction::Show(env ) => {
|
||||||
|
if env.is_env {
|
||||||
|
Ok(serde_json::to_string_pretty(params.as_ref())?)
|
||||||
|
} else {
|
||||||
|
/* */
|
||||||
|
Ok(String::from("Ok"))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/* */
|
||||||
|
_ => Ok(String::from("Ok"))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/* */
|
||||||
|
Commands::Status => Ok(String::from("Ok")),
|
||||||
|
_ => Ok(String::from("Ok"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ use dotenv::dotenv;
|
||||||
/// noxis-rs ... --metrics none
|
/// noxis-rs ... --metrics none
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
#[derive(clap::ValueEnum, Debug, Clone)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum MetricsPrebootParams {
|
pub enum MetricsPrebootParams {
|
||||||
Full,
|
Full,
|
||||||
System,
|
System,
|
||||||
Processes,
|
Processes,
|
||||||
Net,
|
Net,
|
||||||
|
|
@ -177,7 +177,7 @@ impl std::fmt::Display for MetricsPrebootParams {
|
||||||
/// export NOXIS_METRICS_MODE "full"
|
/// export NOXIS_METRICS_MODE "full"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
#[derive(Debug)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct PrebootParams {
|
pub struct PrebootParams {
|
||||||
pub no_hostagent : bool,
|
pub no_hostagent : bool,
|
||||||
pub no_logs: bool,
|
pub no_logs: bool,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue