Exemple #1
0
func (d *DaemonConfig) createVolume(w http.ResponseWriter, req *config.VolumeRequest, policy *config.Policy) func(ld *lock.Driver, ul []config.UseLocker) error {
	return func(ld *lock.Driver, ucs []config.UseLocker) error {
		volConfig, err := d.Config.CreateVolume(req)
		if err != nil {
			return err
		}

		logrus.Debugf("Volume Create: %#v", *volConfig)

		do, err := control.CreateVolume(policy, volConfig, d.Global.Timeout)
		if err == errors.NoActionTaken {
			goto publish
		}

		if err != nil {
			return errors.CreateVolume.Combine(err)
		}

		if err := control.FormatVolume(volConfig, do); err != nil {
			if err := control.RemoveVolume(volConfig, d.Global.Timeout); err != nil {
				logrus.Errorf("Error during cleanup of failed format: %v", err)
			}
			return errors.FormatVolume.Combine(err)
		}

	publish:
		if err := ld.Config.PublishVolume(volConfig); err != nil && err != errors.Exists {
			// FIXME this shouldn't leak down to the client.
			if _, ok := err.(*errored.Error); !ok {
				return errors.PublishVolume.Combine(err)
			}
			return err
		}

		content, err := json.Marshal(volConfig)
		if err != nil {
			return errors.MarshalPolicy.Combine(err)
		}

		w.Write(content)
		return nil
	}
}
Exemple #2
0
func (a *API) createVolume(w http.ResponseWriter, volume *config.VolumeRequest, policyObj *config.Policy) func(ld *lock.Driver, ucs []config.UseLocker) error {
	return func(ld *lock.Driver, ucs []config.UseLocker) error {
		global := *a.Global

		volConfig, err := a.Client.CreateVolume(volume)
		if err != nil {
			return err
		}

		logrus.Debugf("Volume Create: %#v", *volConfig)

		do, err := control.CreateVolume(policyObj, volConfig, global.Timeout)
		if err == errors.NoActionTaken {
			goto publish
		}

		if err != nil {
			return errors.CreateVolume.Combine(err)
		}

		if err := control.FormatVolume(volConfig, do); err != nil {
			if err := control.RemoveVolume(volConfig, global.Timeout); err != nil {
				logrus.Errorf("Error during cleanup of failed format: %v", err)
			}
			return errors.FormatVolume.Combine(err)
		}

	publish:
		if err := a.Client.PublishVolume(volConfig); err != nil && err != errors.Exists {
			if _, ok := err.(*errored.Error); !ok {
				return errors.PublishVolume.Combine(err)
			}
			return err
		}

		return a.WriteCreate(volConfig, w)
	}
}