feat(gui): GUI add support to connect to config server (#1596)

This commit is contained in:
Mg Pig
2025-12-04 23:05:36 +08:00
committed by GitHub
parent 53f279f5ff
commit 0a718163fd
15 changed files with 458 additions and 105 deletions

View File

@@ -7,16 +7,18 @@ use crate::{
api::{config::GetConfigRequest, manage::*},
rpc_types::{self, controller::BaseController},
},
web_client::WebClientHooks,
};
#[derive(Clone)]
pub struct InstanceManageRpcService {
manager: Arc<NetworkInstanceManager>,
hooks: Arc<dyn WebClientHooks>,
}
impl InstanceManageRpcService {
pub fn new(manager: Arc<NetworkInstanceManager>) -> Self {
Self { manager }
pub fn new(manager: Arc<NetworkInstanceManager>, hooks: Arc<dyn WebClientHooks>) -> Self {
Self { manager, hooks }
}
}
@@ -51,7 +53,14 @@ impl WebClientService for InstanceManageRpcService {
};
let mut control = if let Some(control) = self.manager.get_instance_config_control(&id) {
if !req.overwrite {
let error_msg = self
.manager
.get_network_info(&id)
.await
.and_then(|i| i.error_msg)
.unwrap_or_default();
if !req.overwrite && error_msg.is_empty() {
return Ok(resp);
}
if control.is_read_only() {
@@ -96,8 +105,17 @@ impl WebClientService for InstanceManageRpcService {
}
}
if let Err(e) = self.hooks.pre_run_network_instance(&cfg).await {
return Err(anyhow::anyhow!("pre-run hook failed: {}", e).into());
}
self.manager.run_network_instance(cfg, true, control)?;
println!("instance {} started", id);
if let Err(e) = self.hooks.post_run_network_instance(&id).await {
tracing::warn!("post-run hook failed: {}", e);
}
Ok(resp)
}
@@ -173,6 +191,9 @@ impl WebClientService for InstanceManageRpcService {
req: DeleteNetworkInstanceRequest,
) -> Result<DeleteNetworkInstanceResponse, rpc_types::error::Error> {
let inst_ids: HashSet<uuid::Uuid> = req.inst_ids.into_iter().map(Into::into).collect();
let hook_ids: Vec<uuid::Uuid> = inst_ids.iter().cloned().collect();
let inst_ids = self
.manager
.iter()
@@ -190,6 +211,11 @@ impl WebClientService for InstanceManageRpcService {
.collect::<Vec<_>>();
let remain_inst_ids = self.manager.delete_network_instance(inst_ids)?;
println!("instance {:?} retained", remain_inst_ids);
if let Err(e) = self.hooks.post_remove_network_instances(&hook_ids).await {
tracing::warn!("post-remove hook failed: {}", e);
}
for config_file in config_files {
if let Err(e) = std::fs::remove_file(&config_file) {
tracing::warn!(