mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
remove useless port endpoint
This commit is contained in:
parent
60ddcaa15d
commit
075e1ebb0e
4 changed files with 9 additions and 62 deletions
18
api.go
18
api.go
|
@ -179,23 +179,6 @@ func getContainersChanges(srv *Server, w http.ResponseWriter, r *http.Request) (
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainersPort(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) {
|
|
||||||
if err := r.ParseForm(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
name := vars["name"]
|
|
||||||
out, err := srv.ContainerPort(name, r.Form.Get("port"))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b, err := json.Marshal(ApiPort{out})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getContainers(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) {
|
func getContainers(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -543,7 +526,6 @@ func ListenAndServe(addr string, srv *Server) error {
|
||||||
"/images/search": getImagesSearch,
|
"/images/search": getImagesSearch,
|
||||||
"/images/{name:.*}/history": getImagesHistory,
|
"/images/{name:.*}/history": getImagesHistory,
|
||||||
"/containers/{name:.*}/changes": getContainersChanges,
|
"/containers/{name:.*}/changes": getContainersChanges,
|
||||||
"/containers/{name:.*}/port": getContainersPort,
|
|
||||||
"/containers": getContainers,
|
"/containers": getContainers,
|
||||||
"/images/{name:.*}/json": getImagesByName,
|
"/images/{name:.*}/json": getImagesByName,
|
||||||
"/containers/{name:.*}/json": getContainersByName,
|
"/containers/{name:.*}/json": getContainersByName,
|
||||||
|
|
15
commands.go
15
commands.go
|
@ -469,19 +469,22 @@ func CmdPort(args ...string) error {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
v := url.Values{}
|
|
||||||
v.Set("port", cmd.Arg(1))
|
body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/json", nil)
|
||||||
body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/port?"+v.Encode(), nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var out Container
|
||||||
var out ApiPort
|
|
||||||
err = json.Unmarshal(body, &out)
|
err = json.Unmarshal(body, &out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(out.Port)
|
|
||||||
|
if frontend, exists := out.NetworkSettings.PortMapping[cmd.Arg(1)]; exists {
|
||||||
|
fmt.Println(frontend)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("error: No private port '%s' allocated on %s", cmd.Arg(1), cmd.Arg(0))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,34 +265,6 @@ Export a container
|
||||||
:statuscode 500: server error
|
:statuscode 500: server error
|
||||||
|
|
||||||
|
|
||||||
Map container's private ports
|
|
||||||
*****************************
|
|
||||||
|
|
||||||
.. http:get:: /containers/(id)/port
|
|
||||||
|
|
||||||
Map a private port of container ``id``
|
|
||||||
|
|
||||||
**Example request**:
|
|
||||||
|
|
||||||
.. sourcecode:: http
|
|
||||||
|
|
||||||
GET /containers/4fa6e0f0c678/port?port=80 HTTP/1.1
|
|
||||||
|
|
||||||
|
|
||||||
**Example response**:
|
|
||||||
|
|
||||||
.. sourcecode:: http
|
|
||||||
|
|
||||||
HTTP/1.1 200 OK
|
|
||||||
|
|
||||||
{"Port":"80"}
|
|
||||||
|
|
||||||
:query port: the container private port you want to get
|
|
||||||
:statuscode 200: no error
|
|
||||||
:statuscode 404: no such container
|
|
||||||
:statuscode 500: server error
|
|
||||||
|
|
||||||
|
|
||||||
Start a container
|
Start a container
|
||||||
*****************
|
*****************
|
||||||
|
|
||||||
|
|
10
server.go
10
server.go
|
@ -235,16 +235,6 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
||||||
return nil, fmt.Errorf("No such container: %s", name)
|
return nil, fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerPort(name, privatePort string) (string, error) {
|
|
||||||
if container := srv.runtime.Get(name); container != nil {
|
|
||||||
if frontend, exists := container.NetworkSettings.PortMapping[privatePort]; exists {
|
|
||||||
return frontend, nil
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("No private port '%s' allocated on %s", privatePort, name)
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("No such container: %s", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int) []ApiContainers {
|
func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int) []ApiContainers {
|
||||||
var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null'
|
var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null'
|
||||||
for i, container := range srv.runtime.List() {
|
for i, container := range srv.runtime.List() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue