finish runtime

This commit is contained in:
2025-04-15 19:57:11 +08:00
parent 72b2c8d089
commit 0a5f457059
13 changed files with 1097 additions and 45 deletions
+49
View File
@@ -0,0 +1,49 @@
package network
import (
"errors"
"floares/config"
"fmt"
"io"
"log"
"net/http"
"strings"
)
func DisConnect(ns string, id string) (err error) {
reader := strings.NewReader(fmt.Sprintf(`{
"container":"%s"
}`, id))
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/networks/"+ns+"/disconnect", reader)
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Println("request for network list error:", err)
return
}
if res.StatusCode != 200 {
str, _ := io.ReadAll(res.Body)
log.Println(string(str))
err = errors.New(res.Status)
}
return
}
func Connect(ns string, id string) (err error) {
reader := strings.NewReader(fmt.Sprintf(`{
"container":"%s"
}`, id))
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/"+ns+"/connect", reader)
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Println("request for network list error:", err)
return
}
if res.StatusCode != 200 {
str, _ := io.ReadAll(res.Body)
log.Println(string(str))
err = errors.New(res.Status)
}
return
}