Revert "feat(cni): refactor cni_network with RAII design (#13)" (#23)

This reverts commit d46ccf6ea77c62527df7977ec2dd5fbaad6c1245.
This commit is contained in:
Samuel Dai 2025-04-03 13:59:24 +08:00 committed by GitHub
parent d46ccf6ea7
commit 1830e40326
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,19 +67,11 @@ fn get_netns(ns: &str, cid: &str) -> String {
fn get_path(netns: &str) -> String {
format!("/var/run/netns/{}", netns)
}
pub struct CNINetwork {
cid: String,
ns: String
}
impl CNINetwork{
fn new (cid: String,ns:String) -> CNINetwork{
return CNINetwork { cid: cid, ns: ns }
}
//TODO: 创建网络和删除网络的错误处理
pub fn create_cni_network(&self) -> Result<(String, String), Err> {
pub fn create_cni_network(cid: String, ns: String) -> Result<(String, String), Err> {
// let netid = format!("{}-{}", cid, pid);
let netns = get_netns(self.ns.as_str(), self.cid.as_str());
let netns = get_netns(ns.as_str(), cid.as_str());
let path = get_path(netns.as_str());
let mut ip = String::new();
@ -127,12 +119,6 @@ pub fn create_cni_network(&self) -> Result<(String, String), Err> {
Ok((ip, path))
}
}
impl Drop for CNINetwork {
fn drop(&mut self) {
delete_cni_network(&self.ns, &self.cid);
}
}
pub fn delete_cni_network(ns: &str, cid: &str) {
let netns = get_netns(ns, cid);
@ -153,7 +139,6 @@ pub fn delete_cni_network(ns: &str, cid: &str) {
.output();
}
fn dir_exists(dirname: &Path) -> bool {
path_exists(dirname).is_some_and(|info| info.is_dir())
}