finish work
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"floares/config"
|
||||
"floares/lib/model"
|
||||
"fmt"
|
||||
"github.com/go-jose/go-jose/v3/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -29,11 +32,26 @@ func DisConnect(ns string, id string) (err error) {
|
||||
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)
|
||||
type ConnectInfo struct {
|
||||
ContainerID string `json:"container"`
|
||||
Aliases []string `json:"aliases,aliases"`
|
||||
StaticIPs []string `json:"static_ips,omitempty"`
|
||||
StaticMac string `json:"static_mac,omitempty"`
|
||||
}
|
||||
|
||||
func Connect(ns string, r model.ConnectRequest) (err error) {
|
||||
var con ConnectInfo
|
||||
con.ContainerID = r.Id
|
||||
if r.Ip != "" {
|
||||
con.StaticIPs = strings.Split(r.Ip, ",")
|
||||
}
|
||||
if r.Alias != "" {
|
||||
con.Aliases = strings.Split(r.Alias, ",")
|
||||
}
|
||||
con.StaticMac = r.Mac
|
||||
b, _ := json.Marshal(&con)
|
||||
fmt.Println(string(b))
|
||||
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/"+ns+"/connect", bytes.NewReader(b))
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
log.Println("request for network list error:", err)
|
||||
|
||||
Reference in New Issue
Block a user