yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/remotefile/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 remotefile
    16  
    17  import (
    18  	"yunion.io/x/jsonutils"
    19  
    20  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    21  )
    22  
    23  type SStorage struct {
    24  	SResourceBase
    25  
    26  	zone           *SZone
    27  	ZoneId         string
    28  	StorageType    string
    29  	MediumType     string
    30  	CapacityMb     int64
    31  	CapacityUsedMb int64
    32  	Enabled        bool
    33  	SkipSync       bool
    34  }
    35  
    36  func (self *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
    37  	return nil
    38  }
    39  
    40  func (self *SStorage) GetIZone() cloudprovider.ICloudZone {
    41  	return self.zone
    42  }
    43  
    44  func (self *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
    45  	disks, err := self.zone.region.client.GetDisks()
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	ret := []cloudprovider.ICloudDisk{}
    50  	for i := range disks {
    51  		if disks[i].StorageId != self.GetId() {
    52  			continue
    53  		}
    54  		disks[i].storage = self
    55  		ret = append(ret, &disks[i])
    56  	}
    57  	return ret, nil
    58  }
    59  
    60  func (self *SStorage) GetStorageType() string {
    61  	return self.StorageType
    62  }
    63  
    64  func (self *SStorage) GetMediumType() string {
    65  	return self.MediumType
    66  }
    67  
    68  func (self *SStorage) GetCapacityMB() int64 {
    69  	return self.CapacityMb
    70  }
    71  
    72  func (self *SStorage) GetCapacityUsedMB() int64 {
    73  	return self.CapacityUsedMb
    74  }
    75  
    76  func (self *SStorage) GetStorageConf() jsonutils.JSONObject {
    77  	return jsonutils.NewDict()
    78  }
    79  
    80  func (self *SStorage) GetEnabled() bool {
    81  	return self.Enabled
    82  }
    83  
    84  func (self *SStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
    85  	return nil, cloudprovider.ErrNotSupported
    86  }
    87  
    88  func (self *SStorage) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) {
    89  	disks, err := self.GetIDisks()
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  	for i := range disks {
    94  		if disks[i].GetGlobalId() == id {
    95  			return disks[i], nil
    96  		}
    97  	}
    98  	return nil, cloudprovider.ErrNotFound
    99  }
   100  
   101  func (self *SStorage) GetMountPoint() string {
   102  	return ""
   103  }
   104  
   105  func (self *SStorage) IsSysDiskStore() bool {
   106  	return true
   107  }
   108  
   109  func (self *SStorage) DisableSync() bool {
   110  	return self.SkipSync
   111  }