Ejemplo n.º 1
0
func newUnmountHandler(logger lager.Logger, client volman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		logger := logger.Session("unmount")
		logger.Info("start")
		defer logger.Info("end")

		body, err := ioutil.ReadAll(req.Body)
		if err != nil {
			respondWithError(logger, "Error reading unmount request body", err, w)
			return
		}

		var unmountRequest volman.UnmountRequest
		if err = json.Unmarshal(body, &unmountRequest); err != nil {
			respondWithError(logger, fmt.Sprintf("Error reading unmount request body: %#v", body), err, w)
			return
		}

		err = client.Unmount(logger, unmountRequest.DriverId, unmountRequest.VolumeId)
		if err != nil {
			respondWithError(logger, fmt.Sprintf("Error unmounting volume %s with driver %s", unmountRequest.VolumeId, unmountRequest.DriverId), err, w)
			return
		}

		cf_http_handlers.WriteJSONResponse(w, http.StatusOK, struct{}{})
	}
}
Ejemplo n.º 2
0
func newListDriversHandler(logger lager.Logger, client volman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		logger := logger.Session("drivers")
		logger.Info("start")
		defer logger.Info("end")

		drivers, _ := client.ListDrivers(logger) // <- fix this!
		cf_http_handlers.WriteJSONResponse(w, http.StatusOK, drivers)
	}
}
Ejemplo n.º 3
0
func respondWithError(logger lager.Logger, info string, err error, w http.ResponseWriter) {
	logger.Error(info, err)
	cf_http_handlers.WriteJSONResponse(w, http.StatusInternalServerError, volman.NewError(err))
}