Exemple #1
0
// CreateVolume performs the dirty work of actually constructing a volume.
func CreateVolume(policy *config.Policy, config *config.Volume, timeout time.Duration) (storage.DriverOptions, error) {
	var (
		fscmd string
		ok    bool
	)

	if config.Backends.CRUD == "" {
		logrus.Debugf("Not creating volume %q, backend is unspecified", config)
		return storage.DriverOptions{}, errors.NoActionTaken
	}

	if policy.FileSystems == nil {
		fscmd = defaultFsCmd
	} else {
		fscmd, ok = policy.FileSystems[config.CreateOptions.FileSystem]
		if !ok {
			return storage.DriverOptions{}, errored.Errorf("Invalid filesystem %q", config.CreateOptions.FileSystem)
		}
	}

	actualSize, err := config.CreateOptions.ActualSize()
	if err != nil {
		return storage.DriverOptions{}, err
	}

	driver, err := backend.NewCRUDDriver(config.Backends.CRUD)
	if err != nil {
		return storage.DriverOptions{}, err
	}

	driverOpts := storage.DriverOptions{
		Volume: storage.Volume{
			Name:   config.String(),
			Size:   actualSize,
			Params: config.DriverOptions,
		},
		FSOptions: storage.FSOptions{
			Type:          config.CreateOptions.FileSystem,
			CreateCommand: fscmd,
		},
		Timeout: timeout,
	}

	logrus.Infof("Creating volume %v with size %d", config, actualSize)
	return driverOpts, driver.Create(driverOpts)
}
Exemple #2
0
// FormatVolume formats an existing volume.
func FormatVolume(config *config.Volume, do storage.DriverOptions) error {
	actualSize, err := config.CreateOptions.ActualSize()
	if err != nil {
		return err
	}

	if config.Backends.CRUD == "" {
		logrus.Debugf("Not formatting volume %q, backend is unspecified", config)
		return errors.NoActionTaken
	}

	driver, err := backend.NewCRUDDriver(config.Backends.CRUD)
	if err != nil {
		return err
	}

	logrus.Infof("Formatting volume %v (filesystem %q) with size %d", config, config.CreateOptions.FileSystem, actualSize)
	return driver.Format(do)
}
Exemple #3
0
// ExistsVolume tells if a volume exists. It is *not* suitable for any locking primitive.
func ExistsVolume(config *config.Volume, timeout time.Duration) (bool, error) {
	if config.Backends.CRUD == "" {
		logrus.Debugf("volume %q, backend is unspecified", config)
		return true, errors.NoActionTaken
	}

	driver, err := backend.NewCRUDDriver(config.Backends.CRUD)
	if err != nil {
		return false, err
	}

	driverOpts := storage.DriverOptions{
		Volume: storage.Volume{
			Name:   config.String(),
			Params: config.DriverOptions,
		},
		Timeout: timeout,
	}

	return driver.Exists(driverOpts)
}
Exemple #4
0
func (cfg *Volume) validateBackends() error {
	// We use a few dummy variables to ensure that global configuration is
	// not needed in the storage drivers, that the validation does not fail
	// because of it.
	do, err := cfg.ToDriverOptions(time.Second)
	if err != nil {
		return err
	}

	if cfg.Backends.CRUD != "" {
		crud, err := backend.NewCRUDDriver(cfg.Backends.CRUD)
		if err != nil {
			return err
		}

		if err := crud.Validate(&do); err != nil {
			return err
		}
	}

	mnt, err := backend.NewMountDriver(cfg.Backends.Mount, backend.MountPath)
	if err != nil {
		return err
	}

	if err := mnt.Validate(&do); err != nil {
		return err
	}
	if cfg.Backends.Snapshot != "" {
		snapshot, err := backend.NewSnapshotDriver(cfg.Backends.Snapshot)
		if err != nil {
			return err
		}
		if err := snapshot.Validate(&do); err != nil {

			return err
		}
	}
	return nil
}
Exemple #5
0
// RemoveVolume removes a volume.
func RemoveVolume(config *config.Volume, timeout time.Duration) error {
	if config.Backends.CRUD == "" {
		logrus.Debugf("Not removing volume %q, backend is unspecified", config)
		return errors.NoActionTaken
	}

	driver, err := backend.NewCRUDDriver(config.Backends.CRUD)
	if err != nil {
		return err
	}

	driverOpts := storage.DriverOptions{
		Volume: storage.Volume{
			Name:   config.String(),
			Params: config.DriverOptions,
		},
		Timeout: timeout,
	}

	logrus.Infof("Destroying volume %v", config)

	return driver.Destroy(driverOpts)
}