示例#1
0
func CreateProfileHandler(w http.ResponseWriter, r *http.Request) {
	var p Profile
	if err := httputils.UnmarshalJSONBody(r.Body, &p); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	if err := p.Save(); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	httputils.SetLocationHeader(w, "http://localhost:8080/profiles/"+p.Name)
	w.WriteHeader(http.StatusCreated)
}
示例#2
0
func CreateCloudConfigHandler(w http.ResponseWriter, r *http.Request) {
	var c CloudConfig
	if err := httputils.UnmarshalJSONBody(r.Body, &c); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	if err := c.Save(); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	httputils.SetLocationHeader(w, "http://localhost:8080/cloudconfigs/"+c.Name)
	w.WriteHeader(http.StatusCreated)
}
示例#3
0
func CreateSSHKeyHandler(w http.ResponseWriter, r *http.Request) {
	var s SSHKey
	if err := httputils.UnmarshalJSONBody(r.Body, &s); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	if err := s.Save(); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	httputils.SetLocationHeader(w, "http://localhost:8080/sshkeys/"+s.Name)
	w.WriteHeader(http.StatusCreated)
}
示例#4
0
func CreateMachineHandler(w http.ResponseWriter, r *http.Request) {
	var m Machine
	if err := httputils.UnmarshalJSONBody(r.Body, &m); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	if err := m.Save(); err != nil {
		httputils.JSONError(w, err.Error(), 500)
	}
	httputils.SetLocationHeader(w, "http://localhost:8080/machines/"+m.Name)
	w.WriteHeader(http.StatusCreated)
}
示例#5
0
func DeleteProfileHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	err := DeleteProfileByName(vars["name"])
	if err != nil {
		httputils.JSONError(w, err.Error(), 500)
		return
	}
	w.WriteHeader(http.StatusNoContent)
}
示例#6
0
func GetProfileHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	p, err := GetProfileByName(vars["name"])
	if err == ErrNotFound {
		http.NotFound(w, r)
		return
	}
	if err != nil {
		httputils.JSONError(w, err.Error(), 500)
		return
	}
	httputils.JSONWrite(w, p, 200)
}