openstack:避免因disk没有设置volume_type而导致同步磁盘数据不全

This commit is contained in:
屈轩
2019-03-23 17:34:28 +08:00
parent 1dc5c516c0
commit b95e315906
2 changed files with 12 additions and 6 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ package openstack
import (
"context"
"fmt"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -106,7 +107,7 @@ func (disk *SDisk) GetMetadata() *jsonutils.JSONDict {
return data
}
func (region *SRegion) GetDisks(category string) ([]SDisk, error) {
func (region *SRegion) GetDisks(category, volumeBackendName string) ([]SDisk, error) {
_, resp, err := region.CinderList("/volumes/detail", "", nil)
if err != nil {
return nil, err
@@ -117,7 +118,7 @@ func (region *SRegion) GetDisks(category string) ([]SDisk, error) {
}
result := []SDisk{}
for _, disk := range disks {
if len(category) == 0 || disk.VolumeType == category {
if len(category) == 0 || disk.VolumeType == category || strings.HasSuffix(disk.Host, "#"+volumeBackendName) {
result = append(result, disk)
}
}
+9 -4
View File
@@ -11,10 +11,15 @@ import (
"yunion.io/x/onecloud/pkg/compute/models"
)
type SExtraSpecs struct {
VolumeBackendName string
}
type SStorage struct {
zone *SZone
Name string
ID string
zone *SZone
Name string
ExtraSpecs SExtraSpecs
ID string
}
func (storage *SStorage) GetMetadata() *jsonutils.JSONDict {
@@ -42,7 +47,7 @@ func (storage *SStorage) GetIZone() cloudprovider.ICloudZone {
}
func (storage *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
disks, err := storage.zone.region.GetDisks(storage.Name)
disks, err := storage.zone.region.GetDisks(storage.Name, storage.ExtraSpecs.VolumeBackendName)
if err != nil {
return nil, err
}