add container list
This commit is contained in:
@@ -9,7 +9,6 @@ extern crate serde_json;
|
|||||||
use nixideserver_lib::*;
|
use nixideserver_lib::*;
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::hash::Hash;
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::{
|
use std::path::{
|
||||||
Path,
|
Path,
|
||||||
@@ -18,14 +17,44 @@ use std::path::{
|
|||||||
|
|
||||||
// podman create --name test -p 3000:3000 -v $PWD:/nixide -w /nixide docker.io/nixos/nix nix-shell --pure start-ide.nix --run run_ide.sh
|
// podman create --name test -p 3000:3000 -v $PWD:/nixide -w /nixide docker.io/nixos/nix nix-shell --pure start-ide.nix --run run_ide.sh
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub enum PodmanState {
|
||||||
|
Unkown,
|
||||||
|
FetchingSource,
|
||||||
|
StartingContainer,
|
||||||
|
RunningContainer,
|
||||||
|
StoppingContainer,
|
||||||
|
StoppedContainer,
|
||||||
|
DeletingContainer,
|
||||||
|
DeletingSources,
|
||||||
|
}
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PodmanContainer{
|
||||||
|
state : PodmanState,
|
||||||
|
ide_param : NixIdeServerParam
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PodmanContainerList{
|
||||||
|
container : Vec<PodmanContainer>
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PodmanEngine {
|
pub struct PodmanEngine {
|
||||||
working_folder: PathBuf,
|
working_folder: PathBuf,
|
||||||
|
list : PodmanContainerList
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PodmanEngine {
|
impl PodmanEngine {
|
||||||
pub fn new(working_folder: PathBuf) -> Self {
|
pub fn new(working_folder: PathBuf) -> Self {
|
||||||
|
let list_path = format!("{}/.podman_containers", &working_folder.display());
|
||||||
|
let list = match read_from_list_file(&list_path) {
|
||||||
|
Ok(p) => p,
|
||||||
|
_ => PodmanContainerList{container: Vec::new()}
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
working_folder,
|
working_folder,
|
||||||
|
list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +107,7 @@ impl NixIdeManageServiceEngine for PodmanEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Hash)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct NixIdeServerParam {
|
pub struct NixIdeServerParam {
|
||||||
#[serde(default = "default_listen_address")]
|
#[serde(default = "default_listen_address")]
|
||||||
listen_address: String,
|
listen_address: String,
|
||||||
@@ -130,4 +159,12 @@ fn read_ide_state(json_string :&str) -> Result<IdeState,serde_json::Error>
|
|||||||
{
|
{
|
||||||
let status: PodmanIdeStatus = serde_json::from_str(json_string)?;
|
let status: PodmanIdeStatus = serde_json::from_str(json_string)?;
|
||||||
Ok(status.ide_state)
|
Ok(status.ide_state)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_from_list_file(path : &str) -> Result<PodmanContainerList, std::io::Error> {
|
||||||
|
match fs::read_to_string(path)
|
||||||
|
{
|
||||||
|
Ok(json_string) => serde_json::from_str::<PodmanContainerList>(&json_string).map_err(|_| std::io::Error::from(std::io::ErrorKind::InvalidData)),
|
||||||
|
Err(e) => Err(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user