func addPoolHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error { allowed := permission.Check(t, permission.PermPoolCreate) if !allowed { return permission.ErrUnauthorized } b, err := ioutil.ReadAll(r.Body) if err != nil { return err } var p provision.AddPoolOptions err = json.Unmarshal(b, &p) if err != nil { return err } forceAdd, _ := strconv.ParseBool(r.URL.Query().Get("force")) p.Force = forceAdd err = provision.AddPool(p) if err != nil { if err == provision.ErrDefaultPoolAlreadyExists { return &terrors.HTTP{ Code: http.StatusConflict, Message: "Default pool already exists.", } } return err } return nil }
func addPoolHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error { b, err := ioutil.ReadAll(r.Body) if err != nil { return err } var p provision.AddPoolOptions err = json.Unmarshal(b, &p) if err != nil { return err } forceAdd, _ := strconv.ParseBool(r.URL.Query().Get("force")) p.Force = forceAdd err = provision.AddPool(p) if err != nil { if err == provision.ErrDefaultPoolAlreadyExists { return &terrors.HTTP{ Code: http.StatusPreconditionFailed, Message: "Default pool already exists.", } } return err } return nil }