Exemple #1
0
// ReadMount reads a mount request and returns the name of the volume to mount.
//
// NOTE: this is the same for both path and mount and unmount. The docker
// implementation provides us with no other information.
func (v *Volplugin) ReadMount(r *http.Request) (*api.Volume, error) {
	vol, err := unmarshal(r)
	if err != nil {
		return nil, err
	}

	policy, name, err := storage.SplitName(vol.Name)
	if err != nil {
		return nil, err
	}

	return &api.Volume{Policy: policy, Name: name}, nil
}
Exemple #2
0
// ReadGet reads requests for the various Get endpoints (which all do the same thing)
func (v *Volplugin) ReadGet(r *http.Request) (string, error) {
	vc := &VolumeGetRequest{}

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return "", err
	}

	if err := json.Unmarshal(content, vc); err != nil {
		return "", err
	}

	_, _, err = storage.SplitName(vc.Name)
	if err != nil {
		return "", err
	}

	return vc.Name, nil
}
Exemple #3
0
func (a *API) get(origName string, r *http.Request) (string, error) {
	policy, name, err := storage.SplitName(origName)
	if err != nil {
		return "", errors.GetVolume.Combine(err)
	}

	driver, volConfig, driverOpts, err := a.GetStorageParameters(&Volume{Policy: policy, Name: name})
	if err != nil {
		return "", errors.GetVolume.Combine(err)
	}

	if err := volConfig.Validate(); err != nil {
		return "", errors.ConfiguringVolume.Combine(err)
	}

	path, err := driver.MountPath(driverOpts)
	if err != nil {
		return "", errors.MountPath.Combine(err)
	}

	return path, nil
}
Exemple #4
0
// ReadCreate reads a create request from docker and parses it into a policy/volume.
func (v *Volplugin) ReadCreate(r *http.Request) (*config.VolumeRequest, error) {
	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return nil, errors.ReadBody.Combine(err)
	}

	var req VolumeCreateRequest

	if err := json.Unmarshal(content, &req); err != nil {
		return nil, errors.UnmarshalRequest.Combine(err)
	}

	policy, volume, err := storage.SplitName(req.Name)
	if err != nil {
		return nil, errors.UnmarshalRequest.Combine(errors.InvalidVolume).Combine(err)
	}

	return &config.VolumeRequest{
		Policy:  policy,
		Name:    volume,
		Options: req.Opts,
	}, nil
}