func createVolinfo(msg *volume.VolCreateRequest) (*volume.Volinfo, error) { vol, err := volume.NewVolumeEntry(msg) if err != nil { return nil, err } vol.Bricks, err = volume.NewBrickEntriesFunc(msg.Bricks) if err != nil { return nil, err } return vol, nil }
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, "") }