yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/classic_storage.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 azure
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  
    21  	"yunion.io/x/jsonutils"
    22  	"yunion.io/x/pkg/errors"
    23  
    24  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    25  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    26  	"yunion.io/x/cloudmux/pkg/multicloud"
    27  )
    28  
    29  const (
    30  	STORAGE_LRS = "Standard-LRS"
    31  	STORAGE_GRS = "Standard-GRS"
    32  )
    33  
    34  type SClassicStorage struct {
    35  	multicloud.SStorageBase
    36  	AzureTags
    37  	region *SRegion
    38  
    39  	AccountType string
    40  }
    41  
    42  func (self *SClassicStorage) GetId() string {
    43  	zone := self.region.getZone()
    44  	return fmt.Sprintf("%s-%s-classic", zone.GetGlobalId(), self.AccountType)
    45  }
    46  
    47  func (self *SClassicStorage) GetName() string {
    48  	return self.AccountType
    49  }
    50  
    51  func (self *SClassicStorage) GetGlobalId() string {
    52  	return self.GetId()
    53  }
    54  
    55  func (self *SClassicStorage) IsEmulated() bool {
    56  	return true
    57  }
    58  
    59  func (self *SClassicStorage) GetIZone() cloudprovider.ICloudZone {
    60  	return self.region.getZone()
    61  }
    62  
    63  func (self *SClassicStorage) GetEnabled() bool {
    64  	return false
    65  }
    66  
    67  func (self *SClassicStorage) GetCapacityMB() int64 {
    68  	return 0 // unlimited
    69  }
    70  
    71  func (self *SClassicStorage) GetCapacityUsedMB() int64 {
    72  	return 0
    73  }
    74  
    75  func (self *SClassicStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
    76  	return nil, cloudprovider.ErrNotImplemented
    77  }
    78  
    79  func (self *SClassicStorage) GetIDiskById(diskId string) (cloudprovider.ICloudDisk, error) {
    80  	disk, err := self.region.GetClassicDisk(diskId)
    81  	if err != nil {
    82  		return nil, errors.Wrapf(err, "GetDisk(%s)", diskId)
    83  	}
    84  	return disk, nil
    85  }
    86  
    87  func (self *SClassicStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
    88  	return []cloudprovider.ICloudDisk{}, nil
    89  }
    90  
    91  func (self *SClassicStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
    92  	return self.region.getStoragecache()
    93  }
    94  
    95  func (self *SClassicStorage) GetMediumType() string {
    96  	if self.AccountType == STORAGE_LRS {
    97  		return api.DISK_TYPE_SSD
    98  	}
    99  	return api.DISK_TYPE_ROTATE
   100  }
   101  
   102  func (self *SClassicStorage) GetStorageConf() jsonutils.JSONObject {
   103  	conf := jsonutils.NewDict()
   104  	return conf
   105  }
   106  
   107  func (self *SClassicStorage) GetStatus() string {
   108  	return api.STORAGE_ONLINE
   109  }
   110  
   111  func (self *SClassicStorage) GetStorageType() string {
   112  	return strings.ToLower(self.AccountType)
   113  }
   114  
   115  func (self *SClassicStorage) Refresh() error {
   116  	// do nothing
   117  	return nil
   118  }
   119  
   120  func (self *SClassicStorage) GetMountPoint() string {
   121  	return ""
   122  }
   123  
   124  func (self *SClassicStorage) IsSysDiskStore() bool {
   125  	return true
   126  }