github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/storage/provider/dummy/provider.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package dummy 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/juju/environs/config" 9 "github.com/juju/juju/storage" 10 ) 11 12 var _ storage.Provider = (*StorageProvider)(nil) 13 14 // StorageProvider is an implementation of storage.Provider, suitable for testing. 15 // Each method's default behaviour may be overridden by setting the corresponding 16 // Func field. 17 type StorageProvider struct { 18 // StorageScope defines the scope of storage managed by this provider. 19 StorageScope storage.Scope 20 21 // IsDynamic defines whether or not the provider reports that it supports 22 // dynamic provisioning. 23 IsDynamic bool 24 25 // VolumeSourceFunc will be called by VolumeSource, if non-nil; 26 // otherwise VolumeSource will return a NotSupported error. 27 VolumeSourceFunc func(*config.Config, *storage.Config) (storage.VolumeSource, error) 28 29 // FilesystemSourceFunc will be called by FilesystemSource, if non-nil; 30 // otherwise FilesystemSource will return a NotSupported error. 31 FilesystemSourceFunc func(*config.Config, *storage.Config) (storage.FilesystemSource, error) 32 33 // ValidateConfigFunc will be called by ValidateConfig, if non-nil; 34 // otherwise ValidateConfig returns nil. 35 ValidateConfigFunc func(*storage.Config) error 36 37 // SupportsFunc will be called by Supports, if non-nil; otherwise, 38 // Supports returns true. 39 SupportsFunc func(kind storage.StorageKind) bool 40 } 41 42 // VolumeSource is defined on storage.Provider. 43 func (p *StorageProvider) VolumeSource(environConfig *config.Config, providerConfig *storage.Config) (storage.VolumeSource, error) { 44 if p.VolumeSourceFunc != nil { 45 return p.VolumeSourceFunc(environConfig, providerConfig) 46 } 47 return nil, errors.NotSupportedf("volumes") 48 } 49 50 // FilesystemSource is defined on storage.Provider. 51 func (p *StorageProvider) FilesystemSource(environConfig *config.Config, providerConfig *storage.Config) (storage.FilesystemSource, error) { 52 if p.FilesystemSourceFunc != nil { 53 return p.FilesystemSourceFunc(environConfig, providerConfig) 54 } 55 return nil, errors.NotSupportedf("filesystems") 56 } 57 58 // ValidateConfig is defined on storage.Provider. 59 func (p *StorageProvider) ValidateConfig(providerConfig *storage.Config) error { 60 if p.ValidateConfigFunc != nil { 61 return p.ValidateConfigFunc(providerConfig) 62 } 63 return nil 64 } 65 66 // Supports is defined on storage.Provider. 67 func (p *StorageProvider) Supports(kind storage.StorageKind) bool { 68 if p.SupportsFunc != nil { 69 return p.SupportsFunc(kind) 70 } 71 return true 72 } 73 74 // Scope is defined on storage.Provider. 75 func (p *StorageProvider) Scope() storage.Scope { 76 return p.StorageScope 77 } 78 79 // Dynamic is defined on storage.Provider. 80 func (p *StorageProvider) Dynamic() bool { 81 return p.IsDynamic 82 }