Beispiel #1
0
func (c *Control) volumeMount(w http.ResponseWriter, req *http.Request) {
	const reqMaxSize = 4096
	buf, err := ioutil.ReadAll(http.MaxBytesReader(w, req.Body, reqMaxSize))
	if err != nil {
		// they really should export that error
		if err.Error() == "http: request body too large" {
			http.Error(w, err.Error(), http.StatusRequestEntityTooLarge)
			return
		}
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var msg wire.VolumeMountRequest
	err = msg.Unmarshal(buf)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	_, err = c.app.Mount(msg.VolumeName, msg.Mountpoint)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
Beispiel #2
0
func (cmd *mountCommand) Run() error {
	req := wire.VolumeMountRequest{
		VolumeName: cmd.Arguments.VolumeName,
		Mountpoint: cmd.Arguments.Mountpoint.String(),
	}
	buf, err := req.Marshal()
	if err != nil {
		return err
	}
	resp, err := clibazil.Bazil.Control.Post(
		"http+unix://bazil/control/volumeMount",
		"binary/x.bazil.control.volumeMountRequest",
		bytes.NewReader(buf),
	)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		buf, _ := ioutil.ReadAll(resp.Body)
		if len(buf) == 0 {
			buf = []byte(resp.Status)
		}
		return errors.New(string(buf))
	}
	return nil
}