Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
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)
}