github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/worker/storageprovisioner/config.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storageprovisioner 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/juju/storage" 9 "github.com/juju/utils/clock" 10 "gopkg.in/juju/names.v2" 11 ) 12 13 // Config holds configuration and dependencies for a storageprovisioner worker. 14 type Config struct { 15 Scope names.Tag 16 StorageDir string 17 Volumes VolumeAccessor 18 Filesystems FilesystemAccessor 19 Life LifecycleManager 20 Registry storage.ProviderRegistry 21 Machines MachineAccessor 22 Status StatusSetter 23 Clock clock.Clock 24 } 25 26 // Validate returns an error if the config cannot be relied upon to start a worker. 27 func (config Config) Validate() error { 28 switch config.Scope.(type) { 29 case nil: 30 return errors.NotValidf("nil Scope") 31 case names.ModelTag: 32 if config.StorageDir != "" { 33 return errors.NotValidf("environ Scope with non-empty StorageDir") 34 } 35 case names.MachineTag: 36 if config.StorageDir == "" { 37 return errors.NotValidf("machine Scope with empty StorageDir") 38 } 39 default: 40 return errors.NotValidf("%T Scope", config.Scope) 41 } 42 if config.Volumes == nil { 43 return errors.NotValidf("nil Volumes") 44 } 45 if config.Filesystems == nil { 46 return errors.NotValidf("nil Filesystems") 47 } 48 if config.Life == nil { 49 return errors.NotValidf("nil Life") 50 } 51 if config.Registry == nil { 52 return errors.NotValidf("nil Registry") 53 } 54 if config.Machines == nil { 55 return errors.NotValidf("nil Machines") 56 } 57 if config.Status == nil { 58 return errors.NotValidf("nil Status") 59 } 60 if config.Clock == nil { 61 return errors.NotValidf("nil Clock") 62 } 63 return nil 64 }