func postVmCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseForm(); err != nil { return nil } job := eng.Job("vmCreate", r.Form.Get("cpu"), r.Form.Get("mem")) stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) }
func postPodRemove(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseForm(); err != nil { return nil } glog.V(1).Infof("Pod(%s) is process to be removed", r.Form.Get("podId")) job := eng.Job("podRm", r.Form.Get("podId")) stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) }
func postContainerCommit(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseForm(); err != nil { return nil } glog.V(1).Infof("container ID is %s", r.Form.Get("container")) job := eng.Job("commit", r.Form.Get("container"), r.Form.Get("repo"), r.Form.Get("author"), r.Form.Get("change"), r.Form.Get("message"), r.Form.Get("pause")) stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) }
func postStop(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } glog.V(1).Infof("Stop the POD name is %s", r.Form.Get("podName")) job := eng.Job("podStop", r.Form.Get("podId"), r.Form.Get("stopVm")) stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) }
func postPodLabels(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } podID := r.Form.Get("podId") override := r.Form.Get("override") labels := r.Form.Get("labels") job := eng.Job("podLabels", podID, override, labels) stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) }
func postPodCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } if r.Body != nil && (r.ContentLength > 0 || r.ContentLength == -1) { if err := checkForJson(r); err != nil { return err } } else { return fmt.Errorf("no provided podfile data") } podArgs, _ := ioutil.ReadAll(r.Body) autoRemove := r.Form.Get("remove") glog.V(1).Infof("Args string is %s, %s", string(podArgs), autoRemove) job := eng.Job("podCreate", string(podArgs), autoRemove) stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) }
func postPodStart(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseForm(); err != nil { return nil } ttyTag := r.Form.Get("tag") job := eng.Job("podStart", r.Form.Get("podId"), r.Form.Get("vmId"), ttyTag) if ttyTag == "" { stdoutBuf := bytes.NewBuffer(nil) job.Stdout.Add(stdoutBuf) if err := job.Run(); err != nil { return err } var ( env engine.Env dat map[string]interface{} returnedJSONstr string ) returnedJSONstr = engine.Tail(stdoutBuf, 1) if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil { return err } env.Set("ID", dat["ID"].(string)) env.SetInt("Code", (int)(dat["Code"].(float64))) env.Set("Cause", dat["Cause"].(string)) return writeJSONEnv(w, http.StatusOK, env) } else { var ( errOut io.Writer = os.Stderr errStream io.Writer ) // Setting up the streaming http interface. inStream, outStream, err := hijackServer(w) if err != nil { return err } defer closeStreams(inStream, outStream) fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n") errStream = outStream job.Stdin.Add(inStream) job.Stdout.Add(outStream) job.Stderr.Set(errStream) // Now run the user process in container. job.SetCloseIO(false) if err := job.Run(); err != nil { fmt.Fprintf(errOut, "Error starting attach to POD %s: %s\n", r.Form.Get("podname"), err.Error()) return err } w.WriteHeader(http.StatusNoContent) return nil } }