yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/openstack/novastorage.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 openstack
    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  type SNovaStorage struct {
    28  	multicloud.SStorageBase
    29  	OpenStackTags
    30  	host *SHypervisor
    31  	zone *SZone
    32  }
    33  
    34  func (storage *SNovaStorage) GetId() string {
    35  	return fmt.Sprintf("%s-%s-%s", storage.zone.GetGlobalId(), storage.host.GetId(), storage.GetName())
    36  }
    37  
    38  func (storage *SNovaStorage) GetName() string {
    39  	return api.STORAGE_OPENSTACK_NOVA
    40  }
    41  
    42  func (storage *SNovaStorage) GetGlobalId() string {
    43  	return storage.GetId()
    44  }
    45  
    46  func (storage *SNovaStorage) IsEmulated() bool {
    47  	return true
    48  }
    49  
    50  func (storage *SNovaStorage) GetIZone() cloudprovider.ICloudZone {
    51  	return storage.zone
    52  }
    53  
    54  func (storage *SNovaStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
    55  	return []cloudprovider.ICloudDisk{}, nil
    56  }
    57  
    58  func (storage *SNovaStorage) GetStorageType() string {
    59  	return api.STORAGE_OPENSTACK_NOVA
    60  }
    61  
    62  func (storage *SNovaStorage) GetMediumType() string {
    63  	return api.DISK_TYPE_ROTATE
    64  }
    65  
    66  func (storage *SNovaStorage) GetCapacityMB() int64 {
    67  	return int64(storage.host.GetStorageSizeMB())
    68  }
    69  
    70  func (storage *SNovaStorage) GetCapacityUsedMB() int64 {
    71  	return 0
    72  }
    73  
    74  func (storage *SNovaStorage) GetStorageConf() jsonutils.JSONObject {
    75  	conf := jsonutils.NewDict()
    76  	return conf
    77  }
    78  
    79  func (storage *SNovaStorage) GetStatus() string {
    80  	return api.STORAGE_ONLINE
    81  }
    82  
    83  func (storage *SNovaStorage) Refresh() error {
    84  	// do nothing
    85  	return nil
    86  }
    87  
    88  func (storage *SNovaStorage) GetEnabled() bool {
    89  	return true
    90  }
    91  
    92  func (storage *SNovaStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
    93  	return storage.zone.region.getStoragecache()
    94  }
    95  
    96  func (storage *SNovaStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
    97  	return nil, cloudprovider.ErrNotSupported
    98  }
    99  
   100  func (storage *SNovaStorage) GetIDiskById(idStr string) (cloudprovider.ICloudDisk, error) {
   101  	return &SNovaDisk{region: storage.zone.region, storage: storage, instanceId: idStr}, nil
   102  }
   103  
   104  func (storage *SNovaStorage) GetMountPoint() string {
   105  	return ""
   106  }
   107  
   108  func (storage *SNovaStorage) IsSysDiskStore() bool {
   109  	return true
   110  }
   111  
   112  func (self *SNovaStorage) DisableSync() bool {
   113  	return true
   114  }