github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/oracle/storage_provider.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package oracle 5 6 import ( 7 "github.com/juju/clock" 8 "github.com/juju/errors" 9 ociCommon "github.com/juju/go-oracle-cloud/common" 10 11 "github.com/juju/juju/storage" 12 ) 13 14 type poolType string 15 16 const ( 17 // for details please see: 18 // https://docs.oracle.com/cloud/latest/stcomputecs/STCSA/op-storage-volume--post.html#request-definitions-StorageVolume-post-request-properties-properties 19 latencyPool poolType = "latency" 20 defaultPool poolType = "default" 21 oracleVolumeType string = "volume-type" 22 ) 23 24 var poolTypeMap map[poolType]ociCommon.StoragePool = map[poolType]ociCommon.StoragePool{ 25 latencyPool: ociCommon.LatencyPool, 26 defaultPool: ociCommon.DefaultPool, 27 } 28 29 // VolumeSource is defined on the storage.Provider interface. 30 func (s *storageProvider) VolumeSource(cfg *storage.Config) (storage.VolumeSource, error) { 31 environConfig := s.env.Config() 32 name := environConfig.Name() 33 uuid := environConfig.UUID() 34 return newOracleVolumeSource(s.env, name, uuid, s.env.client, clock.WallClock) 35 } 36 37 // FilesystemSource is defined on the storage.Provider interface. 38 func (s storageProvider) FilesystemSource(cfg *storage.Config) (storage.FilesystemSource, error) { 39 return nil, errors.NotSupportedf("filesystemsource") 40 } 41 42 // Supports is defined on the storage.Provider interface. 43 func (s storageProvider) Supports(kind storage.StorageKind) bool { 44 return kind == storage.StorageKindBlock 45 } 46 47 // Scope is defined on the storage.Provider interface. 48 func (s storageProvider) Scope() storage.Scope { 49 return storage.ScopeEnviron 50 } 51 52 // Dynamic is defined on the storage.Provider interface. 53 func (s storageProvider) Dynamic() bool { 54 return true 55 } 56 57 // Releasable is defined on the Provider interface. 58 func (s storageProvider) Releasable() bool { 59 // TODO(axw) support releasing Oracle storage volumes. 60 return false 61 } 62 63 // DefaultPools is defined on the storage.Provider interface. 64 func (s storageProvider) DefaultPools() []*storage.Config { 65 latencyPool, _ := storage.NewConfig("oracle-latency", oracleStorageProviderType, map[string]interface{}{ 66 oracleVolumeType: latencyPool, 67 }) 68 return []*storage.Config{latencyPool} 69 } 70 71 // ValidateConfig is defined on the storage.Provider interface. 72 func (s storageProvider) ValidateConfig(cfg *storage.Config) error { 73 attrs := cfg.Attrs() 74 if volType, ok := attrs[oracleVolumeType]; ok { 75 switch kind := volType.(type) { 76 case string: 77 pool := volType.(string) 78 if _, ok := poolTypeMap[poolType(pool)]; !ok { 79 return errors.Errorf("invalid volume-type %q", volType) 80 } 81 return nil 82 case poolType: 83 if _, ok := poolTypeMap[volType.(poolType)]; !ok { 84 return errors.Errorf("invalid volume-type %q", volType) 85 } 86 return nil 87 default: 88 return errors.Errorf("invalid volume-type %T", kind) 89 } 90 } 91 return nil 92 }