yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/nutanix/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 nutanix
    16  
    17  import (
    18  	"yunion.io/x/jsonutils"
    19  	"yunion.io/x/pkg/errors"
    20  
    21  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    22  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    23  	"yunion.io/x/cloudmux/pkg/multicloud"
    24  )
    25  
    26  type DownMigrateTimesInSecs struct {
    27  	SSDSATA int `json:"SSD-SATA"`
    28  	SSDPCIe int `json:"SSD-PCIe"`
    29  	DASSATA int `json:"DAS-SATA"`
    30  }
    31  
    32  type MappedRemoteContainers struct {
    33  }
    34  
    35  type StorageStats struct {
    36  	HypervisorAvgIoLatencyUsecs          string `json:"hypervisor_avg_io_latency_usecs"`
    37  	NumReadIops                          string `json:"num_read_iops"`
    38  	HypervisorWriteIoBandwidthKBps       string `json:"hypervisor_write_io_bandwidth_kBps"`
    39  	TimespanUsecs                        string `json:"timespan_usecs"`
    40  	ControllerNumReadIops                string `json:"controller_num_read_iops"`
    41  	ReadIoPpm                            string `json:"read_io_ppm"`
    42  	ControllerNumIops                    string `json:"controller_num_iops"`
    43  	TotalReadIoTimeUsecs                 string `json:"total_read_io_time_usecs"`
    44  	ControllerTotalReadIoTimeUsecs       string `json:"controller_total_read_io_time_usecs"`
    45  	HypervisorNumIo                      string `json:"hypervisor_num_io"`
    46  	ControllerTotalTransformedUsageBytes string `json:"controller_total_transformed_usage_bytes"`
    47  	ControllerNumWriteIo                 string `json:"controller_num_write_io"`
    48  	AvgReadIoLatencyUsecs                string `json:"avg_read_io_latency_usecs"`
    49  	ControllerTotalIoTimeUsecs           string `json:"controller_total_io_time_usecs"`
    50  	ControllerTotalReadIoSizeKbytes      string `json:"controller_total_read_io_size_kbytes"`
    51  	ControllerNumSeqIo                   string `json:"controller_num_seq_io"`
    52  	ControllerReadIoPpm                  string `json:"controller_read_io_ppm"`
    53  	ControllerTotalIoSizeKbytes          string `json:"controller_total_io_size_kbytes"`
    54  	ControllerNumIo                      string `json:"controller_num_io"`
    55  	HypervisorAvgReadIoLatencyUsecs      string `json:"hypervisor_avg_read_io_latency_usecs"`
    56  	NumWriteIops                         string `json:"num_write_iops"`
    57  	ControllerNumRandomIo                string `json:"controller_num_random_io"`
    58  	NumIops                              string `json:"num_iops"`
    59  	HypervisorNumReadIo                  string `json:"hypervisor_num_read_io"`
    60  	HypervisorTotalReadIoTimeUsecs       string `json:"hypervisor_total_read_io_time_usecs"`
    61  	ControllerAvgIoLatencyUsecs          string `json:"controller_avg_io_latency_usecs"`
    62  	NumIo                                string `json:"num_io"`
    63  	ControllerNumReadIo                  string `json:"controller_num_read_io"`
    64  	HypervisorNumWriteIo                 string `json:"hypervisor_num_write_io"`
    65  	ControllerSeqIoPpm                   string `json:"controller_seq_io_ppm"`
    66  	ControllerReadIoBandwidthKBps        string `json:"controller_read_io_bandwidth_kBps"`
    67  	ControllerIoBandwidthKBps            string `json:"controller_io_bandwidth_kBps"`
    68  	HypervisorTimespanUsecs              string `json:"hypervisor_timespan_usecs"`
    69  	HypervisorNumWriteIops               string `json:"hypervisor_num_write_iops"`
    70  	TotalReadIoSizeKbytes                string `json:"total_read_io_size_kbytes"`
    71  	HypervisorTotalIoSizeKbytes          string `json:"hypervisor_total_io_size_kbytes"`
    72  	AvgIoLatencyUsecs                    string `json:"avg_io_latency_usecs"`
    73  	HypervisorNumReadIops                string `json:"hypervisor_num_read_iops"`
    74  	ControllerWriteIoBandwidthKBps       string `json:"controller_write_io_bandwidth_kBps"`
    75  	ControllerWriteIoPpm                 string `json:"controller_write_io_ppm"`
    76  	HypervisorAvgWriteIoLatencyUsecs     string `json:"hypervisor_avg_write_io_latency_usecs"`
    77  	HypervisorTotalReadIoSizeKbytes      string `json:"hypervisor_total_read_io_size_kbytes"`
    78  	ReadIoBandwidthKBps                  string `json:"read_io_bandwidth_kBps"`
    79  	HypervisorNumIops                    string `json:"hypervisor_num_iops"`
    80  	HypervisorIoBandwidthKBps            string `json:"hypervisor_io_bandwidth_kBps"`
    81  	ControllerNumWriteIops               string `json:"controller_num_write_iops"`
    82  	TotalIoTimeUsecs                     string `json:"total_io_time_usecs"`
    83  	ControllerRandomIoPpm                string `json:"controller_random_io_ppm"`
    84  	ControllerAvgReadIoSizeKbytes        string `json:"controller_avg_read_io_size_kbytes"`
    85  	TotalTransformedUsageBytes           string `json:"total_transformed_usage_bytes"`
    86  	AvgWriteIoLatencyUsecs               string `json:"avg_write_io_latency_usecs"`
    87  	NumReadIo                            string `json:"num_read_io"`
    88  	WriteIoBandwidthKBps                 string `json:"write_io_bandwidth_kBps"`
    89  	HypervisorReadIoBandwidthKBps        string `json:"hypervisor_read_io_bandwidth_kBps"`
    90  	RandomIoPpm                          string `json:"random_io_ppm"`
    91  	TotalUntransformedUsageBytes         string `json:"total_untransformed_usage_bytes"`
    92  	HypervisorTotalIoTimeUsecs           string `json:"hypervisor_total_io_time_usecs"`
    93  	NumRandomIo                          string `json:"num_random_io"`
    94  	ControllerAvgWriteIoSizeKbytes       string `json:"controller_avg_write_io_size_kbytes"`
    95  	ControllerAvgReadIoLatencyUsecs      string `json:"controller_avg_read_io_latency_usecs"`
    96  	NumWriteIo                           string `json:"num_write_io"`
    97  	TotalIoSizeKbytes                    string `json:"total_io_size_kbytes"`
    98  	IoBandwidthKBps                      string `json:"io_bandwidth_kBps"`
    99  	ControllerTimespanUsecs              string `json:"controller_timespan_usecs"`
   100  	NumSeqIo                             string `json:"num_seq_io"`
   101  	SeqIoPpm                             string `json:"seq_io_ppm"`
   102  	WriteIoPpm                           string `json:"write_io_ppm"`
   103  	ControllerAvgWriteIoLatencyUsecs     string `json:"controller_avg_write_io_latency_usecs"`
   104  }
   105  type StorageUsageStats struct {
   106  	StorageUserUnreservedOwnUsageBytes               string `json:"storage.user_unreserved_own_usage_bytes"`
   107  	StorageReservedFreeBytes                         string `json:"storage.reserved_free_bytes"`
   108  	DataReductionOverallSavingRatioPpm               string `json:"data_reduction.overall.saving_ratio_ppm"`
   109  	DataReductionUserSavedBytes                      string `json:"data_reduction.user_saved_bytes"`
   110  	StorageTierDasSataUsageBytes                     string `json:"storage_tier.das-sata.usage_bytes"`
   111  	DataReductionErasureCodingPostReductionBytes     string `json:"data_reduction.erasure_coding.post_reduction_bytes"`
   112  	StorageReservedUsageBytes                        string `json:"storage.reserved_usage_bytes"`
   113  	StorageUserUnreservedSharedUsageBytes            string `json:"storage.user_unreserved_shared_usage_bytes"`
   114  	StorageUserUnreservedUsageBytes                  int64  `json:"storage.user_unreserved_usage_bytes"`
   115  	StorageUsageBytes                                string `json:"storage.usage_bytes"`
   116  	DataReductionCompressionUserSavedBytes           string `json:"data_reduction.compression.user_saved_bytes"`
   117  	DataReductionErasureCodingUserPreReductionBytes  string `json:"data_reduction.erasure_coding.user_pre_reduction_bytes"`
   118  	StorageUserUnreservedCapacityBytes               string `json:"storage.user_unreserved_capacity_bytes"`
   119  	StorageUserCapacityBytes                         int64  `json:"storage.user_capacity_bytes"`
   120  	StorageUserStoragePoolCapacityBytes              string `json:"storage.user_storage_pool_capacity_bytes"`
   121  	DataReductionPreReductionBytes                   string `json:"data_reduction.pre_reduction_bytes"`
   122  	DataReductionUserPreReductionBytes               string `json:"data_reduction.user_pre_reduction_bytes"`
   123  	StorageUserOtherContainersReservedCapacityBytes  string `json:"storage.user_other_containers_reserved_capacity_bytes"`
   124  	DataReductionErasureCodingPreReductionBytes      string `json:"data_reduction.erasure_coding.pre_reduction_bytes"`
   125  	StorageCapacityBytes                             int64  `json:"storage.capacity_bytes"`
   126  	StorageUserUnreservedFreeBytes                   string `json:"storage.user_unreserved_free_bytes"`
   127  	DataReductionCloneUserSavedBytes                 string `json:"data_reduction.clone.user_saved_bytes"`
   128  	DataReductionDedupPostReductionBytes             string `json:"data_reduction.dedup.post_reduction_bytes"`
   129  	DataReductionCloneSavingRatioPpm                 string `json:"data_reduction.clone.saving_ratio_ppm"`
   130  	StorageLogicalUsageBytes                         string `json:"storage.logical_usage_bytes"`
   131  	DataReductionSavedBytes                          string `json:"data_reduction.saved_bytes"`
   132  	StorageUserDiskPhysicalUsageBytes                string `json:"storage.user_disk_physical_usage_bytes"`
   133  	StorageFreeBytes                                 string `json:"storage.free_bytes"`
   134  	DataReductionCompressionPostReductionBytes       string `json:"data_reduction.compression.post_reduction_bytes"`
   135  	DataReductionCompressionUserPostReductionBytes   string `json:"data_reduction.compression.user_post_reduction_bytes"`
   136  	StorageUserFreeBytes                             string `json:"storage.user_free_bytes"`
   137  	StorageUnreservedFreeBytes                       string `json:"storage.unreserved_free_bytes"`
   138  	StorageUserContainerOwnUsageBytes                string `json:"storage.user_container_own_usage_bytes"`
   139  	DataReductionCompressionSavingRatioPpm           string `json:"data_reduction.compression.saving_ratio_ppm"`
   140  	StorageUserUsageBytes                            int64  `json:"storage.user_usage_bytes"`
   141  	DataReductionErasureCodingUserSavedBytes         string `json:"data_reduction.erasure_coding.user_saved_bytes"`
   142  	DataReductionDedupSavingRatioPpm                 string `json:"data_reduction.dedup.saving_ratio_ppm"`
   143  	StorageUnreservedCapacityBytes                   string `json:"storage.unreserved_capacity_bytes"`
   144  	StorageUserReservedUsageBytes                    string `json:"storage.user_reserved_usage_bytes"`
   145  	DataReductionCompressionUserPreReductionBytes    string `json:"data_reduction.compression.user_pre_reduction_bytes"`
   146  	DataReductionUserPostReductionBytes              string `json:"data_reduction.user_post_reduction_bytes"`
   147  	DataReductionOverallUserSavedBytes               string `json:"data_reduction.overall.user_saved_bytes"`
   148  	DataReductionErasureCodingParityBytes            string `json:"data_reduction.erasure_coding.parity_bytes"`
   149  	DataReductionSavingRatioPpm                      string `json:"data_reduction.saving_ratio_ppm"`
   150  	StorageUnreservedOwnUsageBytes                   string `json:"storage.unreserved_own_usage_bytes"`
   151  	DataReductionErasureCodingSavingRatioPpm         string `json:"data_reduction.erasure_coding.saving_ratio_ppm"`
   152  	StorageUserReservedCapacityBytes                 string `json:"storage.user_reserved_capacity_bytes"`
   153  	DataReductionThinProvisionUserSavedBytes         string `json:"data_reduction.thin_provision.user_saved_bytes"`
   154  	StorageDiskPhysicalUsageBytes                    string `json:"storage.disk_physical_usage_bytes"`
   155  	DataReductionErasureCodingUserPostReductionBytes string `json:"data_reduction.erasure_coding.user_post_reduction_bytes"`
   156  	DataReductionCompressionPreReductionBytes        string `json:"data_reduction.compression.pre_reduction_bytes"`
   157  	DataReductionDedupPreReductionBytes              string `json:"data_reduction.dedup.pre_reduction_bytes"`
   158  	DataReductionDedupUserSavedBytes                 string `json:"data_reduction.dedup.user_saved_bytes"`
   159  	StorageUnreservedUsageBytes                      string `json:"storage.unreserved_usage_bytes"`
   160  	StorageTierSsdUsageBytes                         string `json:"storage_tier.ssd.usage_bytes"`
   161  	DataReductionPostReductionBytes                  string `json:"data_reduction.post_reduction_bytes"`
   162  	DataReductionThinProvisionSavingRatioPpm         string `json:"data_reduction.thin_provision.saving_ratio_ppm"`
   163  	StorageReservedCapacityBytes                     string `json:"storage.reserved_capacity_bytes"`
   164  	StorageUserReservedFreeBytes                     string `json:"storage.user_reserved_free_bytes"`
   165  }
   166  
   167  type SStorage struct {
   168  	multicloud.SStorageBase
   169  	multicloud.STagBase
   170  
   171  	zone *SZone
   172  
   173  	StorageContainerUUID          string                 `json:"storage_container_uuid"`
   174  	Name                          string                 `json:"name"`
   175  	ClusterUUID                   string                 `json:"cluster_uuid"`
   176  	MarkedForRemoval              bool                   `json:"marked_for_removal"`
   177  	MaxCapacity                   int64                  `json:"max_capacity"`
   178  	TotalExplicitReservedCapacity int                    `json:"total_explicit_reserved_capacity"`
   179  	TotalImplicitReservedCapacity int                    `json:"total_implicit_reserved_capacity"`
   180  	AdvertisedCapacity            interface{}            `json:"advertised_capacity"`
   181  	ReplicationFactor             int                    `json:"replication_factor"`
   182  	OplogReplicationFactor        int                    `json:"oplog_replication_factor"`
   183  	NfsWhitelist                  []interface{}          `json:"nfs_whitelist"`
   184  	NfsWhitelistInherited         bool                   `json:"nfs_whitelist_inherited"`
   185  	RandomIoPreference            []string               `json:"random_io_preference"`
   186  	SeqIoPreference               []string               `json:"seq_io_preference"`
   187  	IlmPolicy                     interface{}            `json:"ilm_policy"`
   188  	DownMigrateTimesInSecs        DownMigrateTimesInSecs `json:"down_migrate_times_in_secs"`
   189  	ErasureCode                   string                 `json:"erasure_code"`
   190  	InlineEcEnabled               interface{}            `json:"inline_ec_enabled"`
   191  	PreferHigherEcfaultDomain     interface{}            `json:"prefer_higher_ecfault_domain"`
   192  	ErasureCodeDelaySecs          interface{}            `json:"erasure_code_delay_secs"`
   193  	FingerPrintOnWrite            string                 `json:"finger_print_on_write"`
   194  	OnDiskDedup                   string                 `json:"on_disk_dedup"`
   195  	CompressionEnabled            bool                   `json:"compression_enabled"`
   196  	CompressionDelayInSecs        int                    `json:"compression_delay_in_secs"`
   197  	IsNutanixManaged              interface{}            `json:"is_nutanix_managed"`
   198  	EnableSoftwareEncryption      bool                   `json:"enable_software_encryption"`
   199  	VstoreNameList                []string               `json:"vstore_name_list"`
   200  	MappedRemoteContainers        MappedRemoteContainers `json:"mapped_remote_containers"`
   201  	Stats                         StorageStats           `json:"stats"`
   202  	UsageStats                    StorageUsageStats      `json:"usage_stats"`
   203  	Encrypted                     interface{}            `json:"encrypted"`
   204  }
   205  
   206  func (self *SStorage) GetName() string {
   207  	return self.Name
   208  }
   209  
   210  func (self *SStorage) GetId() string {
   211  	return self.StorageContainerUUID
   212  }
   213  
   214  func (self *SStorage) GetGlobalId() string {
   215  	return self.StorageContainerUUID
   216  }
   217  
   218  func (self *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
   219  	disks, err := self.zone.region.GetDisks(self.GetGlobalId(), "")
   220  	if err != nil {
   221  		return nil, errors.Wrapf(err, "GetDisks")
   222  	}
   223  	ret := []cloudprovider.ICloudDisk{}
   224  	for i := range disks {
   225  		disks[i].storage = self
   226  		ret = append(ret, &disks[i])
   227  	}
   228  	return ret, nil
   229  }
   230  
   231  func (self *SStorage) CreateIDisk(conf *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
   232  	return nil, cloudprovider.ErrNotImplemented
   233  }
   234  
   235  func (self *SStorage) GetCapacityMB() int64 {
   236  	return self.UsageStats.StorageUserCapacityBytes / 1024 / 1024
   237  }
   238  
   239  func (self *SStorage) GetCapacityUsedMB() int64 {
   240  	return self.UsageStats.StorageUserUsageBytes / 1024 / 1024
   241  }
   242  
   243  func (self *SStorage) GetEnabled() bool {
   244  	return true
   245  }
   246  
   247  func (self *SStorage) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) {
   248  	disk, err := self.zone.region.GetDisk(id)
   249  	if err != nil {
   250  		return nil, err
   251  	}
   252  	if disk.StorageContainerUUID != self.GetGlobalId() {
   253  		return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
   254  	}
   255  	disk.storage = self
   256  	return disk, nil
   257  }
   258  
   259  func (self *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
   260  	return &SStoragecache{storage: self, region: self.zone.region}
   261  }
   262  
   263  func (self *SRegion) GetStorages() ([]SStorage, error) {
   264  	storages := []SStorage{}
   265  	err := self.listAll("storage_containers", nil, &storages)
   266  	if err != nil {
   267  		return nil, err
   268  	}
   269  	ret := []SStorage{}
   270  	for i := range storages {
   271  		if storages[i].Name == "NutanixManagementShare" { // https://portal.nutanix.com/page/documents/details?targetId=Web-Console-Guide-Prism-v5_15-ZH:wc-container-create-wc-t.html
   272  			continue
   273  		}
   274  		ret = append(ret, storages[i])
   275  	}
   276  	return ret, nil
   277  }
   278  
   279  func (self *SRegion) GetStorage(id string) (*SStorage, error) {
   280  	storage := &SStorage{}
   281  	return storage, self.get("storage_containers", id, nil, storage)
   282  }
   283  
   284  func (self *SStorage) GetIZone() cloudprovider.ICloudZone {
   285  	return self.zone
   286  }
   287  
   288  func (self *SStorage) GetMediumType() string {
   289  	return api.DISK_TYPE_SSD
   290  }
   291  
   292  func (self *SStorage) GetMountPoint() string {
   293  	return ""
   294  }
   295  
   296  func (self *SStorage) GetStatus() string {
   297  	return api.STORAGE_ONLINE
   298  }
   299  
   300  func (self *SStorage) Refresh() error {
   301  	storage, err := self.zone.region.GetStorage(self.GetGlobalId())
   302  	if err != nil {
   303  		return err
   304  	}
   305  	return jsonutils.Update(self, storage)
   306  }
   307  
   308  func (self *SStorage) GetStorageConf() jsonutils.JSONObject {
   309  	return jsonutils.NewDict()
   310  }
   311  
   312  func (self *SStorage) GetStorageType() string {
   313  	return api.STORAGE_LOCAL
   314  }
   315  
   316  func (self *SStorage) IsSysDiskStore() bool {
   317  	return true
   318  }
   319  
   320  func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
   321  	zones, err := self.GetIZones()
   322  	if err != nil {
   323  		return nil, errors.Wrapf(err, "GetIZones")
   324  	}
   325  	for i := range zones {
   326  		storage, err := zones[i].GetIStorageById(id)
   327  		if err == nil && storage != nil {
   328  			return storage, nil
   329  		}
   330  	}
   331  	return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
   332  }