-
Notifications
You must be signed in to change notification settings - Fork 2
/
containers.go
41 lines (37 loc) · 911 Bytes
/
containers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"log"
"net"
"github.com/fsouza/go-dockerclient"
)
func refreshContainers() {
client, err := docker.NewClientFromEnv()
if err != nil {
//log.Printf("Unable to refresh containers: %s\n", err)
return
}
victimContainers, err := client.ListContainers(docker.ListContainersOptions{
All: true,
Filters: map[string][]string{"label": {"victim"}},
})
if err != nil {
log.Printf("Unable to refresh containers: %s\n", err)
return
}
for _, c := range victimContainers {
log.Printf("Found container: %s\n", c.Names[0])
if victims[c.ID] == nil {
victims[c.ID] = &victim{
Controller: "<none>",
IP: net.ParseIP(c.Networks.Networks["bridge"].IPAddress).To4(),
Mac: c.ID,
Name: c.Names[0],
State: StateOffline,
Type: "container",
}
}
if c.State == "running" {
victims[c.ID].State = StateRunning
}
}
}