finish runtime
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package containers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"floares/config"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Inspect struct {
|
||||
Id string `json:"Id"`
|
||||
Image string `json:"Image"`
|
||||
NetworkSettings struct {
|
||||
Ports map[string][]struct {
|
||||
HostIp string `json:"HostIp"`
|
||||
HostPort string `json:"HostPort"`
|
||||
} `json:"Ports"`
|
||||
Networks map[string]struct {
|
||||
EndpointID string `json:"EndpointID"`
|
||||
Gateway string `json:"Gateway"`
|
||||
IPAddress string `json:"IPAddress"`
|
||||
IPPrefixLen int `json:"IPPrefixLen"`
|
||||
MacAddress string `json:"MacAddress"`
|
||||
DriverOpts interface{} `json:"DriverOpts"`
|
||||
IPAMConfig interface{} `json:"IPAMConfig"`
|
||||
Links interface{} `json:"Links"`
|
||||
Aliases []string `json:"Aliases"`
|
||||
} `json:"Networks"`
|
||||
} `json:"NetworkSettings"`
|
||||
}
|
||||
|
||||
func InspectContainer(id string) (res Inspect) {
|
||||
req, err := http.NewRequest(http.MethodGet, config.Entrypoint+"/v2.2.2/libpod/containers/"+id+"/json", nil)
|
||||
if err != nil {
|
||||
log.Println("request for containers list error:", err)
|
||||
return
|
||||
}
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
log.Println("request for containers list error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||
if err != nil {
|
||||
log.Println("json decode container list error:", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -24,14 +24,12 @@ type Inspect struct {
|
||||
Network string `json:"Network"`
|
||||
} `json:"ConfigFrom"`
|
||||
ConfigOnly bool `json:"ConfigOnly"`
|
||||
Containers struct {
|
||||
C8E63Bfb95Cf391126C4B7A13327Cd781Af0Dd080B858Cdb7A2B26B4304E02C struct {
|
||||
Name string `json:"Name"`
|
||||
EndpointID string `json:"EndpointID"`
|
||||
MacAddress string `json:"MacAddress"`
|
||||
IPv4Address string `json:"IPv4Address"`
|
||||
IPv6Address string `json:"IPv6Address"`
|
||||
} `json:"9c8e63bfb95cf391126c4b7a13327cd781af0dd080b858cdb7a2b26b4304e02c"`
|
||||
Containers map[string]struct {
|
||||
Name string `json:"Name"`
|
||||
EndpointID string `json:"EndpointID"`
|
||||
MacAddress string `json:"MacAddress"`
|
||||
IPv4Address string `json:"IPv4Address"`
|
||||
IPv6Address string `json:"IPv6Address"`
|
||||
} `json:"Containers"`
|
||||
Options struct {
|
||||
} `json:"Options"`
|
||||
@@ -30,6 +30,9 @@ func ListNetwork() []model.NetWork {
|
||||
Subnet: val.Subnet, Gateway: val.Gateway,
|
||||
})
|
||||
}
|
||||
if v.Name == "bridge" {
|
||||
v.Name = "podman"
|
||||
}
|
||||
result = append(result, model.NetWork{
|
||||
Name: v.Name,
|
||||
Id: v.Id,
|
||||
|
||||
Reference in New Issue
Block a user