1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-10-05 09:53:21 +08:00

Return swarm info to be displayed in the FE

This requires that PWD is working as a container in the same
network as all dinds

Add icons to swarmInfo
This commit is contained in:
Marcos Lilljedahl
2016-11-23 13:50:21 -03:00
parent 0f4aea4de3
commit 10bdf3d5f2
7 changed files with 72 additions and 8 deletions

View File

@@ -4,6 +4,9 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
@@ -40,6 +43,22 @@ func GetContainerInfo(id string) (types.ContainerJSON, error) {
return c.ContainerInspect(context.Background(), id)
}
func GetDaemonInfo(host string) (types.Info, error) {
transport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 1 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext}
cli := &http.Client{
Transport: transport,
}
c, err := client.NewClient(host, client.DefaultVersion, cli, nil)
if err != nil {
return types.Info{}, err
}
return c.Info(context.Background())
}
func CreateNetwork(name string) error {
opts := types.NetworkCreate{Driver: "overlay", Attachable: true}
_, err := c.NetworkCreate(context.Background(), name, opts)