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