yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/ecloud/storage.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ecloud 16 17 import ( 18 "fmt" 19 20 "yunion.io/x/jsonutils" 21 22 api "yunion.io/x/cloudmux/pkg/apis/compute" 23 "yunion.io/x/cloudmux/pkg/cloudprovider" 24 "yunion.io/x/cloudmux/pkg/multicloud" 25 ) 26 27 var storageTypes = []string{ 28 api.STORAGE_ECLOUD_CAPEBS, 29 api.STORAGE_ECLOUD_EBS, 30 api.STORAGE_ECLOUD_SSD, 31 api.STORAGE_ECLOUD_SSDEBS, 32 // special storage 33 api.STORAGE_ECLOUD_SYSTEM, 34 } 35 36 type SStorage struct { 37 multicloud.SStorageBase 38 EcloudTags 39 zone *SZone 40 storageType string 41 } 42 43 func (s *SStorage) GetId() string { 44 return fmt.Sprintf("%s-%s-%s", s.zone.region.client.cpcfg.Id, s.zone.GetGlobalId(), s.storageType) 45 } 46 47 func (s *SStorage) GetName() string { 48 return fmt.Sprintf("%s-%s-%s", s.zone.region.client.cpcfg.Name, s.zone.GetId(), s.storageType) 49 } 50 51 func (s *SStorage) GetGlobalId() string { 52 return s.GetId() 53 } 54 55 func (s *SStorage) GetStatus() string { 56 return api.STORAGE_ONLINE 57 } 58 59 func (s *SStorage) Refresh() error { 60 return nil 61 } 62 63 func (s *SStorage) IsEmulated() bool { 64 return true 65 } 66 67 func (s *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache { 68 return s.zone.region.getStoragecache() 69 } 70 71 func (s *SStorage) GetIZone() cloudprovider.ICloudZone { 72 return s.zone 73 } 74 75 func (s *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) { 76 if s.storageType == api.STORAGE_ECLOUD_SYSTEM { 77 return nil, nil 78 } 79 disks, err := s.zone.region.GetDisks() 80 if err != nil { 81 return nil, err 82 } 83 84 // 按storage type 过滤出disk 85 filtedDisks := make([]SDisk, 0) 86 for i := range disks { 87 disk := disks[i] 88 if disk.Type == s.storageType && disk.Region == s.zone.Region { 89 filtedDisks = append(filtedDisks, disk) 90 } 91 } 92 93 idisks := make([]cloudprovider.ICloudDisk, len(filtedDisks)) 94 for i := 0; i < len(filtedDisks); i += 1 { 95 filtedDisks[i].storage = s 96 idisks[i] = &filtedDisks[i] 97 } 98 return idisks, nil 99 } 100 101 func (s *SStorage) GetStorageType() string { 102 return s.storageType 103 } 104 105 func (s *SStorage) GetMediumType() string { 106 if s.storageType == api.STORAGE_ECLOUD_SSD { 107 return api.DISK_TYPE_SSD 108 } else { 109 return api.DISK_TYPE_ROTATE 110 } 111 } 112 113 func (s *SStorage) GetCapacityMB() int64 { 114 return 0 115 } 116 117 func (s *SStorage) GetCapacityUsedMB() int64 { 118 return 0 119 } 120 121 func (s *SStorage) GetStorageConf() jsonutils.JSONObject { 122 return jsonutils.NewDict() 123 } 124 125 func (s *SStorage) GetEnabled() bool { 126 return true 127 } 128 129 func (s *SStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) { 130 return nil, cloudprovider.ErrNotImplemented 131 } 132 133 func (s *SStorage) GetIDiskById(idStr string) (cloudprovider.ICloudDisk, error) { 134 if len(idStr) == 0 { 135 return nil, cloudprovider.ErrNotFound 136 } 137 138 if disk, err := s.zone.region.GetDisk(idStr); err != nil { 139 return nil, err 140 } else { 141 disk.storage = s 142 return disk, nil 143 } 144 } 145 146 func (s *SStorage) GetMountPoint() string { 147 return "" 148 } 149 150 func (s *SStorage) IsSysDiskStore() bool { 151 return true 152 } 153 154 func (s *SStorage) DisableSync() bool { 155 if s.storageType == api.STORAGE_ECLOUD_SYSTEM { 156 return true 157 } 158 return s.SStorageBase.DisableSync() 159 } 160 161 func (s *SRegion) getStoragecache() *SStoragecache { 162 if s.storageCache == nil { 163 s.storageCache = &SStoragecache{region: s} 164 } 165 return s.storageCache 166 }