github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/storage/provider/loop.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package provider
     5  
     6  import (
     7  	"path/filepath"
     8  	"strings"
     9  
    10  	"github.com/juju/errors"
    11  
    12  	"github.com/juju/juju/environs/config"
    13  	"github.com/juju/juju/instance"
    14  	"github.com/juju/juju/storage"
    15  )
    16  
    17  const (
    18  	// Loop provider types
    19  	LoopProviderType     = storage.ProviderType("loop")
    20  	HostLoopProviderType = storage.ProviderType("hostloop")
    21  
    22  	// Config attributes
    23  	LoopDataDir = "data-dir" // top level directory where loop devices are created.
    24  	LoopSubDir  = "sub-dir"  // optional subdirectory for loop devices.
    25  )
    26  
    27  // loopProviders create volume sources which use loop devices.
    28  type loopProvider struct{}
    29  
    30  var _ storage.Provider = (*loopProvider)(nil)
    31  
    32  // ValidateConfig is defined on the Provider interface.
    33  func (lp *loopProvider) ValidateConfig(providerConfig *storage.Config) error {
    34  	dataDir, ok := providerConfig.ValueString(LoopDataDir)
    35  	if !ok || dataDir == "" {
    36  		return errors.New("no data directory specified")
    37  	}
    38  	return nil
    39  }
    40  
    41  // VolumeSource is defined on the Provider interface.
    42  func (lp *loopProvider) VolumeSource(environConfig *config.Config, providerConfig *storage.Config) (storage.VolumeSource, error) {
    43  	if err := lp.ValidateConfig(providerConfig); err != nil {
    44  		return nil, err
    45  	}
    46  	dataDir, _ := providerConfig.ValueString(LoopDataDir)
    47  	subDir, _ := providerConfig.ValueString(LoopDataDir)
    48  	return &loopVolumeSource{
    49  		dataDir,
    50  		subDir,
    51  	}, nil
    52  }
    53  
    54  // loopVolumeSource provides common functionality to handle
    55  // loop devices for rootfs and host loop volume sources.
    56  type loopVolumeSource struct {
    57  	dataDir string
    58  	subDir  string
    59  }
    60  
    61  var _ storage.VolumeSource = (*loopVolumeSource)(nil)
    62  
    63  func (lvs *loopVolumeSource) rootDeviceDir() string {
    64  	dirParts := []string{lvs.dataDir}
    65  	dirParts = append(dirParts, strings.Split(lvs.subDir, "/")...)
    66  	return filepath.Join(dirParts...)
    67  }
    68  
    69  func (lvs *loopVolumeSource) CreateVolumes(params []storage.VolumeParams) ([]storage.BlockDevice, error) {
    70  	panic("not implemented")
    71  }
    72  
    73  func (lvs *loopVolumeSource) DescribeVolumes(volIds []string) ([]storage.BlockDevice, error) {
    74  	panic("not implemented")
    75  }
    76  
    77  func (lvs *loopVolumeSource) DestroyVolumes(volIds []string) error {
    78  	panic("not implemented")
    79  }
    80  
    81  func (lvs *loopVolumeSource) ValidateVolumeParams(params storage.VolumeParams) error {
    82  	panic("not implemented")
    83  }
    84  
    85  func (lvs *loopVolumeSource) AttachVolumes(volIds []string, instId []instance.Id) error {
    86  	panic("not implemented")
    87  }
    88  
    89  func (lvs *loopVolumeSource) DetachVolumes(volIds []string, instId []instance.Id) error {
    90  	panic("not implemented")
    91  }