// VolumeCreate is a Handler function to create Gluster Volume
func VolumeCreate(w http.ResponseWriter, r *http.Request) {
	decoder := json.NewDecoder(r.Body)
	var opts glustercli.CreateOptions
	err := decoder.Decode(&opts)
	if err != nil {
		utils.HTTPErrorJSON(w, err.Error(), http.StatusBadRequest)
		return
	}

	vars := mux.Vars(r)
	volName := vars["volName"]
	errCreate := glustercli.VolumeCreate(volName, opts.Bricks, opts)
	if errCreate != nil {
		utils.HTTPErrorJSON(w, errCreate.Error(), http.StatusInternalServerError)
		return
	}
}
// VolumeDelete is a HTTP handler to Delete a Gluster Volume
func VolumeDelete(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	volName := vars["volName"]
	err := glustercli.VolumeDelete(volName)
	if err != nil {
		utils.HTTPErrorJSON(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
Exemple #3
0
// ListenHandler is a Handler function which listens to the events
// from other peers. This is a internal REST API.
func ListenHandler(w http.ResponseWriter, r *http.Request) {
	decoder := json.NewDecoder(r.Body)
	var msg utils.EventMsg
	err := decoder.Decode(&msg)
	if err != nil {
		utils.HTTPErrorJSON(w, err.Error(), http.StatusBadRequest)
		return
	}
	utils.WsSendAll([]byte(msg.Message))
}
// VolumeStatus is a HTTP Handler function to get Gluster Volume Status
func VolumeStatus(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	volName, ok := vars["volName"]
	if !ok {
		volName = ""
	}

	info, err := glustercli.VolumeStatus(volName)
	if err != nil {
		utils.HTTPErrorJSON(w, err.Error(), http.StatusInternalServerError)
	}
	utils.HTTPOutJSON(w, info)
}
// VolumeGet is a HTTP Handler function to get Gluster Volume Information
func VolumeGet(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	volName, ok := vars["volName"]
	if !ok {
		volName = ""
	}
	status := r.URL.Query().Get("status")
	var info []glustercli.Volume
	var err error
	if status == "1" {
		info, err = glustercli.VolumeStatus(volName)
	} else {
		info, err = glustercli.VolumeInfo(volName)
	}
	if err != nil {
		utils.HTTPErrorJSON(w, err.Error(), http.StatusInternalServerError)
	}
	utils.HTTPOutJSON(w, info)
}