Add /containers/create to apiserver

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
Ben Firshman 2014-06-07 19:17:19 -07:00 committed by Solomon Hykes
parent 991a109959
commit ca1f554608
1 changed files with 29 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/dotcloud/docker/api" "github.com/dotcloud/docker/api"
"github.com/dotcloud/docker/pkg/version" "github.com/dotcloud/docker/pkg/version"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"io/ioutil"
"net" "net"
"net/http" "net/http"
) )
@ -61,6 +62,33 @@ func getContainersJSON(out beam.Sender, version version.Version, w http.Response
return writeJSON(w, http.StatusOK, names) return writeJSON(w, http.StatusOK, names)
} }
func postContainersCreate(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
container, err := beam.Obj(out).Spawn(string(body))
if err != nil {
return err
}
responseJson, err := container.Get()
if err != nil {
return err
}
var response struct{ Id string }
if err = json.Unmarshal([]byte(responseJson), &response); err != nil {
return err
}
return writeJSON(w, http.StatusCreated, response)
}
func postContainersStart(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { func postContainersStart(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if vars == nil { if vars == nil {
return fmt.Errorf("Missing parameter") return fmt.Errorf("Missing parameter")
@ -109,6 +137,7 @@ func createRouter(out beam.Sender) (*mux.Router, error) {
"/containers/json": getContainersJSON, "/containers/json": getContainersJSON,
}, },
"POST": { "POST": {
"/containers/create": postContainersCreate,
"/containers/{name:.*}/start": postContainersStart, "/containers/{name:.*}/start": postContainersStart,
"/containers/{name:.*}/stop": postContainersStop, "/containers/{name:.*}/stop": postContainersStop,
}, },