Skip to content

Commit

Permalink
machine: Populate networking information in the status
Browse files Browse the repository at this point in the history
  • Loading branch information
dlespiau committed Sep 9, 2019
1 parent 78b24d0 commit 6408853
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ require (
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect
gopkg.in/yaml.v2 v2.2.2
)

go 1.13
16 changes: 15 additions & 1 deletion pkg/cluster/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"syscall"

"github.com/docker/docker/api/types/network"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/weaveworks/footloose/pkg/config"
Expand Down Expand Up @@ -103,6 +104,19 @@ func (m *Machine) HostPort(containerPort int) (hostPort int, err error) {
return m.ports[containerPort], nil
}

func (m *Machine) networks() ([]*RuntimeNetwork, error) {
if len(m.runtimeNetworks) != 0 {
return m.runtimeNetworks, nil
}

var networks map[string]*network.EndpointSettings
if err := docker.InspectObject(m.name, ".NetworkSettings.Networks", &networks); err != nil {
return nil, err
}
m.runtimeNetworks = NewRuntimeNetworks(networks)
return m.runtimeNetworks, nil
}

// Status returns the machine status.
func (m *Machine) Status() *MachineStatus {
s := MachineStatus{}
Expand Down Expand Up @@ -138,7 +152,7 @@ func (m *Machine) Status() *MachineStatus {
}
}
s.Ports = ports
s.RuntimeNetworks = m.runtimeNetworks
s.RuntimeNetworks, _ = m.networks()

return &s
}
Expand Down

0 comments on commit 6408853

Please sign in to comment.