finish containers persistance
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::deploy;
|
||||
use crate::conf::storage::MemStorage;
|
||||
use crate::conf::Instance;
|
||||
use std::sync::Mutex;
|
||||
use log::{error};
|
||||
|
||||
pub struct Controller {
|
||||
driver: Docker,
|
||||
@@ -24,7 +25,7 @@ impl Controller {
|
||||
}
|
||||
|
||||
pub async fn create_container(&self, domain: String, ip: String, image: String) -> String {
|
||||
match self.load_container(domain.clone(),ip.clone(),image.clone()).await {
|
||||
match self.load_container(None,domain.clone(),ip.clone(),image.clone()).await {
|
||||
Ok(c) => {
|
||||
let ret = c.get_id();
|
||||
self.storage.lock().unwrap().new_instance(c).unwrap();
|
||||
@@ -37,28 +38,34 @@ impl Controller {
|
||||
pub async fn start_container_from_instance(&self, instance: Instance) {
|
||||
let image = match self.storage.lock().unwrap().id_to_image(instance.image.clone()) {
|
||||
Ok(i) => i,
|
||||
Err(_e) => return, //meter logs aquí
|
||||
Err(e) => {
|
||||
log::error!("image not found: {}", e);
|
||||
return
|
||||
},
|
||||
};
|
||||
match self.load_container(
|
||||
Some(instance.docker_id.clone()),
|
||||
instance.domain.clone(),
|
||||
instance.ip.clone(),
|
||||
image).await {
|
||||
Ok(c) => {
|
||||
self.storage.lock().unwrap().loaded_instance(instance, c);
|
||||
},
|
||||
Err(_e) => (),
|
||||
Err(e) => log::error!("{}",e),
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_container(&self, domain: String,
|
||||
async fn load_container(&self, docker_id: Option<String>,
|
||||
domain: String,
|
||||
ip: String,
|
||||
image: String) -> Result<deploy::container::Container,
|
||||
bollard::errors::Error>
|
||||
{
|
||||
deploy::container::Container::new(self.driver.clone(),
|
||||
domain.clone(),
|
||||
ip.clone(),
|
||||
image.clone(),
|
||||
docker_id,
|
||||
domain,
|
||||
ip,
|
||||
image,
|
||||
self.network.clone()).await
|
||||
}
|
||||
|
||||
@@ -69,7 +76,10 @@ impl Controller {
|
||||
pub async fn load_all_instances(&self) -> bool {
|
||||
let data = match self.storage.lock().unwrap().get_instances_db() {
|
||||
Ok(d) => d,
|
||||
Err(_e) => return false,
|
||||
Err(e) => {
|
||||
log::error!("instances can't be loaded: {}",e);
|
||||
return false
|
||||
},
|
||||
};
|
||||
println!("instances {}", data.len());
|
||||
for instance in data {
|
||||
|
||||
Reference in New Issue
Block a user