Explorar o código

remove useless port endpoint

Victor Vieux %!s(int64=12) %!d(string=hai) anos
pai
achega
075e1ebb0e
Modificáronse 4 ficheiros con 9 adicións e 62 borrados
  1. 0 18
      api.go
  2. 9 6
      commands.go
  3. 0 28
      docs/sources/remote-api/api.rst
  4. 0 10
      server.go

+ 0 - 18
api.go

@@ -179,23 +179,6 @@ func getContainersChanges(srv *Server, w http.ResponseWriter, r *http.Request) (
 	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) {
 	if err := r.ParseForm(); err != nil {
 		return nil, err
@@ -543,7 +526,6 @@ func ListenAndServe(addr string, srv *Server) error {
 			"/images/search":                getImagesSearch,
 			"/images/{name:.*}/history":     getImagesHistory,
 			"/containers/{name:.*}/changes": getContainersChanges,
-			"/containers/{name:.*}/port":    getContainersPort,
 			"/containers":                   getContainers,
 			"/images/{name:.*}/json":        getImagesByName,
 			"/containers/{name:.*}/json":    getContainersByName,

+ 9 - 6
commands.go

@@ -469,19 +469,22 @@ func CmdPort(args ...string) error {
 		cmd.Usage()
 		return nil
 	}
-	v := url.Values{}
-	v.Set("port", cmd.Arg(1))
-	body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/port?"+v.Encode(), nil)
+
+	body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/json", nil)
 	if err != nil {
 		return err
 	}
-
-	var out ApiPort
+	var out Container
 	err = json.Unmarshal(body, &out)
 	if err != nil {
 		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
 }
 

+ 0 - 28
docs/sources/remote-api/api.rst

@@ -265,34 +265,6 @@ Export a container
 	: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
 *****************
 

+ 0 - 10
server.go

@@ -235,16 +235,6 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
 	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 {
 	var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null'
 	for i, container := range srv.runtime.List() {