fix: qcloud sync unavailable storages

This commit is contained in:
ioito
2019-08-22 20:36:35 +08:00
parent 09cf7531fc
commit 7d25a44b4e
3 changed files with 21 additions and 7 deletions
+5 -1
View File
@@ -27,6 +27,7 @@ import (
type SLocalStorage struct {
zone *SZone
storageType string
available bool
}
func (self *SLocalStorage) GetMetadata() *jsonutils.JSONDict {
@@ -84,6 +85,9 @@ func (self *SLocalStorage) GetStorageConf() jsonutils.JSONObject {
}
func (self *SLocalStorage) GetStatus() string {
if !self.available {
return api.STORAGE_OFFLINE
}
return api.STORAGE_ONLINE
}
@@ -93,7 +97,7 @@ func (self *SLocalStorage) Refresh() error {
}
func (self *SLocalStorage) GetEnabled() bool {
return true
return self.available == true
}
func (self *SLocalStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
+5 -1
View File
@@ -29,6 +29,7 @@ import (
type SStorage struct {
zone *SZone
storageType string
available bool
}
func (self *SStorage) GetMetadata() *jsonutils.JSONDict {
@@ -97,6 +98,9 @@ func (self *SStorage) GetStorageConf() jsonutils.JSONObject {
}
func (self *SStorage) GetStatus() string {
if !self.available {
return api.STORAGE_OFFLINE
}
return api.STORAGE_ONLINE
}
@@ -106,7 +110,7 @@ func (self *SStorage) Refresh() error {
}
func (self *SStorage) GetEnabled() bool {
return true
return self.available == true
}
func (self *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
+11 -5
View File
@@ -141,14 +141,20 @@ func (self *SZone) fetchStorages() error {
}
storageTypes := []string{}
for _, diskConfig := range diskConfigSet {
if diskConfig.Available && !utils.IsInStringArray(diskConfig.DiskType, storageTypes) {
storageTypes = append(storageTypes, diskConfig.DiskType)
storage := SStorage{zone: self, storageType: diskConfig.DiskType}
if !utils.IsInStringArray(strings.ToUpper(diskConfig.DiskType), storageTypes) {
storageTypes = append(storageTypes, strings.ToUpper(diskConfig.DiskType))
storage := SStorage{zone: self, storageType: diskConfig.DiskType, available: diskConfig.Available}
self.istorages = append(self.istorages, &storage)
}
}
for _, storageType := range []string{"CLOUD_PREMIUM", "CLOUD_SSD", "CLOUD_BASIC"} {
if !utils.IsInStringArray(storageType, storageTypes) {
storage := SStorage{zone: self, storageType: storageType, available: false}
self.istorages = append(self.istorages, &storage)
}
}
for _, localstorageType := range []string{"LOCAL_BASIC", "LOCAL_SSD"} {
storage := SLocalStorage{zone: self, storageType: localstorageType}
storage := SLocalStorage{zone: self, storageType: localstorageType, available: self.region.GetId() == "ap-hongkong"} //仅有香港本地存储可用
self.istorages = append(self.istorages, &storage)
}
return nil
@@ -186,7 +192,7 @@ func (self *SZone) getStorageByCategory(category string) (*SStorage, error) {
//return &SStorage{zone: self, storageType: strings.ToUpper(storages[i].GetStorageType())}, nil
}
storage := storages[i].(*SStorage)
if storage.storageType == category {
if strings.ToLower(storage.storageType) == strings.ToLower(category) {
return storage, nil
}
}