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