github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/provider/oci/storage.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package oci 5 6 import ( 7 "github.com/juju/clock" 8 "github.com/juju/errors" 9 10 "github.com/juju/juju/storage" 11 ) 12 13 type poolType string 14 15 const ( 16 ociStorageProviderType = storage.ProviderType("oci") 17 18 // maxVolumeSizeInGB represents the maximum size in GiB for 19 // a single volume. For more information please see: 20 // https://docs.oracle.com/cloud/latest/stcomputecs/STCSA/op-storage-volume--post.html#request 21 maxVolumeSizeInGB = 16000 22 // minVolumeSizeInGB represents the minimum size in GiB for 23 // a single volume. For more information please see: 24 // https://docs.oracle.com/cloud/latest/stcomputecs/STCSA/op-storage-volume--post.html#request 25 minVolumeSizeInGB = 50 26 27 iscsiPool poolType = "iscsi" 28 ociVolumeType string = "volume-type" 29 ) 30 31 var poolTypeMap map[string]poolType = map[string]poolType{ 32 "iscsi": iscsiPool, 33 } 34 35 type StorageAPI interface{} 36 37 type storageProvider struct { 38 env *Environ 39 api StorageClient 40 } 41 42 var _ storage.Provider = (*storageProvider)(nil) 43 44 func (s *storageProvider) VolumeSource(cfg *storage.Config) (storage.VolumeSource, error) { 45 envConfig := s.env.Config() 46 name := envConfig.Name() 47 uuid := envConfig.UUID() 48 return &volumeSource{ 49 env: s.env, 50 envName: name, 51 modelUUID: uuid, 52 storageAPI: s.env.Storage, 53 computeAPI: s.env.Compute, 54 clock: clock.WallClock, 55 }, nil 56 } 57 58 func (s *storageProvider) FilesystemSource(cfg *storage.Config) (storage.FilesystemSource, error) { 59 return nil, errors.NotSupportedf("filesystemsource") 60 } 61 62 func (s *storageProvider) Supports(kind storage.StorageKind) bool { 63 return kind == storage.StorageKindBlock 64 } 65 66 func (s *storageProvider) Scope() storage.Scope { 67 return storage.ScopeEnviron 68 } 69 70 func (s *storageProvider) Dynamic() bool { 71 return true 72 } 73 74 func (s *storageProvider) Releasable() bool { 75 // TODO (gsamfira): add support 76 return false 77 } 78 79 func (s *storageProvider) DefaultPools() []*storage.Config { 80 pool, _ := storage.NewConfig("iscsi", ociStorageProviderType, map[string]interface{}{ 81 ociVolumeType: iscsiPool, 82 }) 83 return []*storage.Config{pool} 84 } 85 86 func (s *storageProvider) ValidateForK8s(map[string]any) error { 87 return errors.NotValidf("storage provider type %q", ociStorageProviderType) 88 } 89 90 func (s *storageProvider) ValidateConfig(cfg *storage.Config) error { 91 attrs := cfg.Attrs() 92 var pool string 93 if volType, ok := attrs[ociVolumeType]; ok { 94 switch kind := volType.(type) { 95 case string: 96 pool = volType.(string) 97 98 case poolType: 99 pool = string(volType.(poolType)) 100 default: 101 return errors.Errorf("invalid volume-type %T", kind) 102 } 103 if _, ok := poolTypeMap[pool]; !ok { 104 return errors.Errorf("invalid volume-type %q", volType) 105 } 106 return nil 107 } 108 return nil 109 } 110 111 // StorageProviderTypes implements storage.ProviderRegistry. 112 func (e *Environ) StorageProviderTypes() ([]storage.ProviderType, error) { 113 return []storage.ProviderType{ociStorageProviderType}, nil 114 } 115 116 // StorageProvider implements storage.ProviderRegistry. 117 func (e *Environ) StorageProvider(t storage.ProviderType) (storage.Provider, error) { 118 if t == ociStorageProviderType { 119 return &storageProvider{ 120 env: e, 121 api: e.Storage, 122 }, nil 123 } 124 125 return nil, errors.NotFoundf("storage provider %q", t) 126 }