yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/ecloud/storagecache.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 "context" 19 "fmt" 20 21 "yunion.io/x/jsonutils" 22 "yunion.io/x/pkg/errors" 23 24 "yunion.io/x/cloudmux/pkg/cloudprovider" 25 "yunion.io/x/onecloud/pkg/mcclient" 26 "yunion.io/x/cloudmux/pkg/multicloud" 27 ) 28 29 type SStoragecache struct { 30 multicloud.SResourceBase 31 EcloudTags 32 region *SRegion 33 } 34 35 func (sc *SStoragecache) CreateIImage(snapshotId, imageName, osType, imageDesc string) (cloudprovider.ICloudImage, error) { 36 return nil, cloudprovider.ErrNotSupported 37 } 38 39 func (sc *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error) { 40 return nil, cloudprovider.ErrNotSupported 41 } 42 43 func (sc *SStoragecache) UploadImage(ctx context.Context, userCred mcclient.TokenCredential, image *cloudprovider.SImageCreateOption, callback func(progress float32)) (string, error) { 44 return "", cloudprovider.ErrNotSupported 45 } 46 47 func (sc *SStoragecache) GetId() string { 48 return fmt.Sprintf("%s-%s", sc.region.client.cpcfg.Id, sc.region.GetId()) 49 } 50 51 func (sc *SStoragecache) GetName() string { 52 return fmt.Sprintf("%s-%s", sc.region.client.cpcfg.Name, sc.region.GetId()) 53 } 54 55 func (sc *SStoragecache) GetGlobalId() string { 56 return fmt.Sprintf("%s-%s", sc.region.client.cpcfg.Id, sc.region.GetGlobalId()) 57 } 58 59 func (sc *SStoragecache) GetStatus() string { 60 return "available" 61 } 62 63 func (sc *SStoragecache) Refresh() error { 64 return nil 65 } 66 67 func (sc *SStoragecache) IsEmulated() bool { 68 return false 69 } 70 71 func (sc *SStoragecache) GetICloudImages() ([]cloudprovider.ICloudImage, error) { 72 return nil, cloudprovider.ErrNotImplemented 73 } 74 75 func (sc *SStoragecache) GetICustomizedCloudImages() ([]cloudprovider.ICloudImage, error) { 76 imagesSelf, err := sc.region.GetImages(false) 77 if err != nil { 78 return nil, errors.Wrapf(err, "GetImages") 79 } 80 ret := []cloudprovider.ICloudImage{} 81 for i := range imagesSelf { 82 imagesSelf[i].storageCache = sc 83 ret = append(ret, &imagesSelf[i]) 84 } 85 return ret, nil 86 } 87 88 func (sc *SStoragecache) GetIImageById(extId string) (cloudprovider.ICloudImage, error) { 89 image, err := sc.region.GetImage(extId) 90 if err != nil { 91 return nil, errors.Wrap(err, "SStoragecache.GetIImageById.GetImage") 92 } 93 94 image.storageCache = sc 95 return image, err 96 } 97 98 func (sc *SStoragecache) GetPath() string { 99 return "" 100 }