예제 #1
0
func (c *Command) volumeStop(w http.ResponseWriter, r *http.Request) {
	p := mux.Vars(r)
	/* TODO : As of now we consider the request as volname, later on we need
	* to consider the volume id as well */
	volname := p["volname"]

	log.Info("In Volume stop API")

	vol, e := context.Store.GetVolume(volname)
	if e != nil {
		client.SendResponse(w, -1, http.StatusBadRequest, errors.ErrVolNotFound.Error(), http.StatusBadRequest, "")
		return
	}
	if vol.Status == volume.VolStopped {
		client.SendResponse(w, -1, http.StatusBadRequest, errors.ErrVolAlreadyStopped.Error(), http.StatusBadRequest, "")
		return
	}
	vol.Status = volume.VolStopped

	e = context.Store.AddOrUpdateVolume(vol)
	if e != nil {
		log.WithField("error", e).Error("Couldn't update volume into the store")
		client.SendResponse(w, -1, http.StatusInternalServerError, e.Error(), http.StatusInternalServerError, "")
		return
	}
	log.WithField("volume", vol.Name).Debug("Volume updated into the store")
	client.SendResponse(w, 0, 0, "", http.StatusOK, "")
}
예제 #2
0
func (c *Command) volumeList(w http.ResponseWriter, r *http.Request) {

	log.Info("In Volume list API")

	volumes, e := context.Store.GetVolumes()
	if e != nil {
		client.SendResponse(w, -1, http.StatusNotFound, e.Error(), http.StatusNotFound, "")
	} else {
		client.SendResponse(w, 0, 0, "", http.StatusNotFound, volumes)
	}
}
예제 #3
0
func (c *Command) volumeInfo(w http.ResponseWriter, r *http.Request) {
	p := mux.Vars(r)
	/* TODO : As of now we consider the request as volname, later on we need
	* to consider the volume id as well */
	volname := p["volname"]

	log.Debug("In Volume info API")

	vol, e := context.Store.GetVolume(volname)
	if e != nil {
		client.SendResponse(w, -1, http.StatusNotFound, errors.ErrVolNotFound.Error(), http.StatusNotFound, "")
	} else {
		client.SendResponse(w, 0, 0, "", http.StatusOK, vol)
	}
}
예제 #4
0
func (c *Command) volumeDelete(w http.ResponseWriter, r *http.Request) {
	p := mux.Vars(r)
	/* TODO : As of now we consider the request as volname, later on we need
	* to consider the volume id as well */
	volname := p["volname"]

	log.Info("In Volume delete API")

	if context.Store.VolumeExists(volname) {
		client.SendResponse(w, -1, http.StatusBadRequest, errors.ErrVolNotFound.Error(), http.StatusBadRequest, "")
		return
	}

	e := context.Store.DeleteVolume(volname)
	if e != nil {
		client.SendResponse(w, -1, http.StatusInternalServerError, e.Error(), http.StatusInternalServerError, "")
		return
	}
	client.SendResponse(w, 0, 0, "", http.StatusOK, "")
}
예제 #5
0
func (c *Command) volumeCreate(w http.ResponseWriter, r *http.Request) {

	var msg volume.VolCreateRequest

	e := utils.GetJSONFromRequest(r, &msg)
	if e != nil {
		client.SendResponse(w, -1, 422, errors.ErrJSONParsingFailed.Error(), 422, "")
		return
	}

	if msg.Name == "" {
		log.Error("Volume name is empty")
		client.SendResponse(w, -1, http.StatusBadRequest, errors.ErrEmptyVolName.Error(), http.StatusBadRequest, "")
		return
	}
	if len(msg.Bricks) <= 0 {
		log.Error("Brick list is empty")
		client.SendResponse(w, -1, http.StatusBadRequest, errors.ErrEmptyBrickList.Error(), http.StatusBadRequest, "")
		return
	}

	if context.Store.VolumeExists(msg.Name) {
		log.WithField("Volume", msg.Name).Error("Volume already exists")
		client.SendResponse(w, -1, http.StatusBadRequest, errors.ErrVolExists.Error(), http.StatusBadRequest, "")
		return
	}

	vol := volume.NewVolumeEntry(msg)
	e = context.Store.AddOrUpdateVolume(vol)
	if e != nil {
		log.WithField("error", e).Error("Couldn't add volume to store")
		client.SendResponse(w, -1, http.StatusInternalServerError, e.Error(), http.StatusInternalServerError, "")
		return
	}

	// Creating client  and server volfile
	volgen.GenerateVolfile(vol)

	log.WithField("volume", vol.Name).Debug("NewVolume added to store")
	client.SendResponse(w, 0, 0, "", http.StatusCreated, "")
}