yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/localstorage.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 qcloud
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  
    21  	"yunion.io/x/jsonutils"
    22  
    23  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    24  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    25  	"yunion.io/x/cloudmux/pkg/multicloud"
    26  )
    27  
    28  var QCLOUD_LOCAL_STORAGE_TYPES = []string{
    29  	"LOCAL_NVME",
    30  	"LOCAL_BASIC",
    31  	"LOCAL_SSD",
    32  	"LOCAL_PRO",
    33  }
    34  
    35  type SLocalStorage struct {
    36  	multicloud.SStorageBase
    37  	zone        *SZone
    38  	storageType string
    39  	available   bool
    40  }
    41  
    42  func (self *SLocalStorage) GetId() string {
    43  	return fmt.Sprintf("%s-%s-%s", self.zone.region.client.cpcfg.Id, self.zone.GetId(), self.storageType)
    44  }
    45  
    46  func (self *SLocalStorage) GetName() string {
    47  	return fmt.Sprintf("%s-%s-%s", self.zone.region.client.cpcfg.Name, self.zone.GetId(), self.storageType)
    48  }
    49  
    50  func (self *SLocalStorage) GetGlobalId() string {
    51  	return fmt.Sprintf("%s-%s-%s", self.zone.region.client.cpcfg.Id, self.zone.GetGlobalId(), self.storageType)
    52  }
    53  
    54  func (self *SLocalStorage) IsEmulated() bool {
    55  	return true
    56  }
    57  
    58  func (self *SLocalStorage) GetIZone() cloudprovider.ICloudZone {
    59  	return self.zone
    60  }
    61  
    62  func (self *SLocalStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
    63  	disks := []SLocalDisk{}
    64  	idisks := make([]cloudprovider.ICloudDisk, len(disks))
    65  	for i := 0; i < len(disks); i++ {
    66  		disks[i].storage = self
    67  		idisks[i] = &disks[i]
    68  	}
    69  	return idisks, nil
    70  }
    71  
    72  func (self *SLocalStorage) GetStorageType() string {
    73  	return strings.ToLower(self.storageType)
    74  }
    75  
    76  func (self *SLocalStorage) GetMediumType() string {
    77  	if strings.HasSuffix(self.storageType, "_BASIC") {
    78  		return api.DISK_TYPE_ROTATE
    79  	}
    80  	return api.DISK_TYPE_SSD
    81  }
    82  
    83  func (self *SLocalStorage) GetCapacityMB() int64 {
    84  	return 0 // unlimited
    85  }
    86  
    87  func (self *SLocalStorage) GetCapacityUsedMB() int64 {
    88  	return 0
    89  }
    90  
    91  func (self *SLocalStorage) GetStorageConf() jsonutils.JSONObject {
    92  	conf := jsonutils.NewDict()
    93  	return conf
    94  }
    95  
    96  func (self *SLocalStorage) GetStatus() string {
    97  	if !self.available {
    98  		return api.STORAGE_OFFLINE
    99  	}
   100  	return api.STORAGE_ONLINE
   101  }
   102  
   103  func (self *SLocalStorage) Refresh() error {
   104  	// do nothing
   105  	return nil
   106  }
   107  
   108  func (self *SLocalStorage) GetEnabled() bool {
   109  	return self.available == true
   110  }
   111  
   112  func (self *SLocalStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
   113  	return self.zone.region.getStoragecache()
   114  }
   115  
   116  func (self *SLocalStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
   117  	return nil, cloudprovider.ErrNotSupported
   118  }
   119  
   120  func (self *SLocalStorage) GetIDiskById(idStr string) (cloudprovider.ICloudDisk, error) {
   121  	return &SLocalDisk{storage: self, DiskId: idStr}, nil
   122  }
   123  
   124  func (self *SLocalStorage) GetMountPoint() string {
   125  	return ""
   126  }
   127  
   128  func (self *SLocalStorage) IsSysDiskStore() bool {
   129  	return true
   130  }
   131  
   132  func (self *SLocalStorage) DisableSync() bool {
   133  	return true
   134  }