mirror of https://github.com/docker/docs.git
Adds support for `docker inspect` to dockerserver
Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83) Conflicts: backends/dockerserver.go
This commit is contained in:
parent
75531daa58
commit
200867288c
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/docker/libswarm/beam"
|
||||
"github.com/dotcloud/docker/api"
|
||||
"github.com/dotcloud/docker/pkg/version"
|
||||
dockerContainerConfig "github.com/dotcloud/docker/runconfig"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"github.com/gorilla/mux"
|
||||
"io"
|
||||
|
@ -13,10 +14,10 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func DockerServer() beam.Sender {
|
||||
|
@ -73,6 +74,68 @@ func ping(out beam.Sender, version version.Version, w http.ResponseWriter, r *ht
|
|||
return err
|
||||
}
|
||||
|
||||
type containerJson struct {
|
||||
Config *dockerContainerConfig.Config
|
||||
HostConfig *dockerContainerConfig.HostConfig
|
||||
ID string
|
||||
Created string
|
||||
Driver string
|
||||
ExecDriver string
|
||||
NetworkSettings struct {
|
||||
Bridge string
|
||||
Gateway string
|
||||
IPAddress string
|
||||
IPPrefixLen int
|
||||
Ports map[string][]map[string]string
|
||||
}
|
||||
State struct {
|
||||
Running bool
|
||||
StartedAt string
|
||||
FinishedAt string
|
||||
ExitCode int
|
||||
Paused bool
|
||||
Pid int
|
||||
}
|
||||
Name string
|
||||
Args []string
|
||||
ProcessLbael string
|
||||
ResolvConfPath string
|
||||
HostnamePath string
|
||||
HostsPath string
|
||||
MountLabel string
|
||||
Volumes map[string]string
|
||||
VolumesRW map[string]bool
|
||||
}
|
||||
|
||||
func getContainerJson(out beam.Sender, containerID string) (containerJson, error) {
|
||||
o := beam.Obj(out)
|
||||
|
||||
_, containerOut, err := o.Attach(containerID)
|
||||
if err != nil {
|
||||
return containerJson{}, err
|
||||
}
|
||||
container := beam.Obj(containerOut)
|
||||
responseJson, err := container.Get()
|
||||
if err != nil {
|
||||
return containerJson{}, err
|
||||
}
|
||||
var response containerJson
|
||||
|
||||
if err = json.Unmarshal([]byte(responseJson), &response); err != nil {
|
||||
return containerJson{}, err
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func getContainerInfo(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
container, err := getContainerJson(out, vars["name"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return writeJSON(w, http.StatusOK, container)
|
||||
}
|
||||
|
||||
func getContainersJSON(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
return err
|
||||
|
@ -87,36 +150,10 @@ func getContainersJSON(out beam.Sender, version version.Version, w http.Response
|
|||
var responses []interface{}
|
||||
|
||||
for _, name := range names {
|
||||
_, containerOut, err := o.Attach(name)
|
||||
response, err := getContainerJson(out, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
container := beam.Obj(containerOut)
|
||||
responseJson, err := container.Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var response struct {
|
||||
ID string
|
||||
Created string
|
||||
Name string
|
||||
Config struct {
|
||||
Cmd []string
|
||||
Image string
|
||||
}
|
||||
State struct {
|
||||
Running bool
|
||||
StartedAt string
|
||||
FinishedAt string
|
||||
ExitCode int
|
||||
}
|
||||
NetworkSettings struct {
|
||||
Ports map[string][]map[string]string
|
||||
}
|
||||
}
|
||||
if err = json.Unmarshal([]byte(responseJson), &response); err != nil {
|
||||
return err
|
||||
}
|
||||
created, err := time.Parse(time.RFC3339, response.Created)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -157,7 +194,7 @@ func getContainersJSON(out beam.Sender, version version.Version, w http.Response
|
|||
}
|
||||
} else {
|
||||
newport := port{
|
||||
PrivatePort: portnum,
|
||||
PublicPort: portnum,
|
||||
Type: proto,
|
||||
}
|
||||
ports = append(ports, newport)
|
||||
|
@ -334,6 +371,7 @@ func createRouter(out beam.Sender) (*mux.Router, error) {
|
|||
"GET": {
|
||||
"/_ping": ping,
|
||||
"/containers/json": getContainersJSON,
|
||||
"/containers/{name}/json": getContainerInfo,
|
||||
},
|
||||
"POST": {
|
||||
"/containers/create": postContainersCreate,
|
||||
|
|
Loading…
Reference in New Issue