yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/jdcloud/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 jdcloud
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"yunion.io/x/jsonutils"
    21  
    22  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    23  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    24  	"yunion.io/x/cloudmux/pkg/multicloud"
    25  )
    26  
    27  var storageTypes = []string{
    28  	api.STORAGE_JDCLOUD_STD,
    29  	api.STORAGE_JDCLOUD_GP1,
    30  	api.STORAGE_JDCLOUD_IO1,
    31  	api.STORAGE_JDCLOUD_SSD,
    32  	api.STORAGE_JDCLOUD_PHD,
    33  }
    34  
    35  type SStorage struct {
    36  	multicloud.SStorageBase
    37  	JdcloudTags
    38  	zone        *SZone
    39  	storageType string
    40  }
    41  
    42  func (s *SStorage) GetId() string {
    43  	return fmt.Sprintf("%s-%s-%s", s.zone.region.cpcfg.Id, s.zone.GetGlobalId(), s.storageType)
    44  }
    45  
    46  func (s *SStorage) GetName() string {
    47  	return fmt.Sprintf("%s-%s-%s", s.zone.region.cpcfg.Name, s.zone.GetName(), s.storageType)
    48  }
    49  
    50  func (s *SStorage) GetGlobalId() string {
    51  	return s.GetId()
    52  }
    53  
    54  func (s *SStorage) GetStatus() string {
    55  	return api.STORAGE_ONLINE
    56  }
    57  
    58  func (s *SStorage) Refresh() error {
    59  	return nil
    60  }
    61  
    62  func (s *SStorage) IsEmulated() bool {
    63  	return true
    64  }
    65  
    66  func (s *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
    67  	return s.zone.region.getStoragecache()
    68  }
    69  
    70  var ss cloudprovider.ICloudStorage = &SStorage{}
    71  
    72  func (s *SStorage) GetIZone() cloudprovider.ICloudZone {
    73  	return s.zone
    74  }
    75  
    76  func (s *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
    77  	disks := make([]SDisk, 0)
    78  	n := 1
    79  	for {
    80  		parts, total, err := s.zone.region.GetDisks("", s.zone.GetId(), s.storageType, []string{}, n, 100)
    81  		if err != nil {
    82  			return nil, err
    83  		}
    84  		disks = append(disks, parts...)
    85  		if len(disks) >= total {
    86  			break
    87  		}
    88  		n++
    89  	}
    90  	idisk := make([]cloudprovider.ICloudDisk, len(disks))
    91  	for i := range disks {
    92  		disks[i].storage = s
    93  		idisk[i] = &disks[i]
    94  	}
    95  	return idisk, nil
    96  }
    97  
    98  func (s *SStorage) GetStorageType() string {
    99  	return s.storageType
   100  }
   101  
   102  func (s *SStorage) GetMediumType() string {
   103  	if s.storageType == api.STORAGE_JDCLOUD_STD {
   104  		return api.DISK_TYPE_ROTATE
   105  	} else {
   106  		return api.DISK_TYPE_SSD
   107  	}
   108  }
   109  
   110  func (s *SStorage) GetCapacityMB() int64 {
   111  	return 0
   112  }
   113  
   114  func (s *SStorage) GetStorageConf() jsonutils.JSONObject {
   115  	return jsonutils.NewDict()
   116  }
   117  
   118  func (s *SStorage) GetEnabled() bool {
   119  	return true
   120  }
   121  
   122  func (s *SStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
   123  	return nil, cloudprovider.ErrNotImplemented
   124  }
   125  
   126  func (s *SStorage) GetIDiskById(idStr string) (cloudprovider.ICloudDisk, error) {
   127  	disk, err := s.zone.region.GetDiskById(idStr)
   128  	if err != nil {
   129  		return nil, err
   130  	}
   131  	disk.storage = s
   132  	return disk, nil
   133  }
   134  
   135  func (s *SStorage) GetMountPoint() string {
   136  	return ""
   137  }
   138  
   139  func (s *SStorage) IsSysDiskStore() bool {
   140  	return true
   141  }
   142  func (s *SStorage) GetCapacityUsedMB() int64 {
   143  	return 0
   144  }
   145  
   146  func (s *SStorage) DisableSync() bool {
   147  	return false
   148  }