yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/proxmox/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 proxmox
    16  
    17  import (
    18  	"context"
    19  
    20  	"yunion.io/x/jsonutils"
    21  
    22  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    23  	"yunion.io/x/onecloud/pkg/mcclient"
    24  	"yunion.io/x/cloudmux/pkg/multicloud"
    25  )
    26  
    27  type SStoragecache struct {
    28  	multicloud.SResourceBase
    29  	ProxmoxTags
    30  
    31  	zone *SZone
    32  }
    33  
    34  func (self *SStoragecache) GetGlobalId() string {
    35  	return self.zone.GetGlobalId()
    36  }
    37  
    38  func (self *SStoragecache) GetId() string {
    39  	return self.zone.GetId()
    40  }
    41  
    42  func (self *SStoragecache) GetName() string {
    43  	return self.zone.GetName()
    44  }
    45  
    46  func (self *SStoragecache) GetStatus() string {
    47  	return "available"
    48  }
    49  
    50  func (self *SStoragecache) GetICloudImages() ([]cloudprovider.ICloudImage, error) {
    51  	ret := []cloudprovider.ICloudImage{}
    52  	images, err := self.zone.region.GetImageList()
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	for i := range images {
    57  		images[i].cache = self
    58  		ret = append(ret, &images[i])
    59  	}
    60  
    61  	return ret, nil
    62  }
    63  
    64  func (seflf *SStoragecache) GetICustomizedCloudImages() ([]cloudprovider.ICloudImage, error) {
    65  	return nil, cloudprovider.ErrNotSupported
    66  }
    67  
    68  func (self *SStoragecache) GetIImageById(id string) (cloudprovider.ICloudImage, error) {
    69  	images, err := self.GetICloudImages()
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  	for i := range images {
    74  		if images[i].GetGlobalId() == id {
    75  			return images[i], nil
    76  		}
    77  	}
    78  	return nil, cloudprovider.ErrNotFound
    79  }
    80  
    81  func (self *SStoragecache) GetPath() string {
    82  	return ""
    83  }
    84  
    85  func (self *SStoragecache) CreateIImage(snpId, imageName, osType, imageDesc string) (cloudprovider.ICloudImage, error) {
    86  	return nil, cloudprovider.ErrNotSupported
    87  }
    88  
    89  func (self *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error) {
    90  	return nil, cloudprovider.ErrNotSupported
    91  }
    92  
    93  func (self *SStoragecache) UploadImage(ctx context.Context, userCred mcclient.TokenCredential, image *cloudprovider.SImageCreateOption, callback func(float32)) (string, error) {
    94  	return "", cloudprovider.ErrNotSupported
    95  }