Skip to content

Commit

Permalink
Add /containers/create to apiserver
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Firshman <[email protected]>
  • Loading branch information
bfirsh authored and Solomon Hykes committed Jun 2, 2014
1 parent 991a109 commit ca1f554
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions backends/dockerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/dotcloud/docker/api"
"github.com/dotcloud/docker/pkg/version"
"github.com/gorilla/mux"
"io/ioutil"
"net"
"net/http"
)
Expand Down Expand Up @@ -61,6 +62,33 @@ func getContainersJSON(out beam.Sender, version version.Version, w http.Response
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 {
if vars == nil {
return fmt.Errorf("Missing parameter")
Expand Down Expand Up @@ -109,6 +137,7 @@ func createRouter(out beam.Sender) (*mux.Router, error) {
"/containers/json": getContainersJSON,
},
"POST": {
"/containers/create": postContainersCreate,
"/containers/{name:.*}/start": postContainersStart,
"/containers/{name:.*}/stop": postContainersStop,
},
Expand Down

0 comments on commit ca1f554

Please sign in to comment.