fix sync openstack hoststorages issue

This commit is contained in:
ioito
2019-07-02 19:30:38 +08:00
parent ffb22f1d45
commit 0d643aea5e
2 changed files with 56 additions and 1 deletions
+24 -1
View File
@@ -16,6 +16,7 @@ package openstack
import (
"fmt"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/utils"
@@ -108,7 +109,29 @@ func (host *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
}
func (host *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
return host.zone.GetIStorages()
istorages, err := host.zone.GetIStorages()
if err != nil {
return nil, err
}
schedulerPools, err := host.zone.getSchedulerStatsPool()
if err != nil {
return nil, err
}
result := []cloudprovider.ICloudStorage{}
for _, istorage := range istorages {
if storage := istorage.(*SStorage); len(storage.ExtraSpecs.VolumeBackendName) > 0 {
for _, pool := range schedulerPools {
if strings.HasPrefix(pool.Name, fmt.Sprintf("%s@%s", host.GetName(), storage.ExtraSpecs.VolumeBackendName)) {
result = append(result, istorage)
break
}
}
}
}
return result, nil
}
func (host *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
+32
View File
@@ -34,6 +34,14 @@ const (
HYPERVISORS_VERSION = "2.28"
)
type SCapabilities struct {
}
type SPool struct {
Name string
Capabilities SCapabilities
}
type HostState struct {
Available bool
Active bool
@@ -50,6 +58,8 @@ type SZone struct {
cachedHosts map[string][]string
schedulerPools []SPool
Hosts map[string]map[string]HostState
}
@@ -90,6 +100,28 @@ func (zone *SZone) GetIWires() ([]cloudprovider.ICloudWire, error) {
return zone.iwires, nil
}
func (zone *SZone) fetchSchedulerStatsPool() error {
zone.schedulerPools = []SPool{}
for _, service := range []string{"volumev3", "volumev2", "volume"} {
_, resp, err := zone.region.List(service, "/scheduler-stats/get_pools", "", nil)
if err == nil {
if err := resp.Unmarshal(&zone.schedulerPools, "pools"); err != nil {
return err
}
return nil
}
log.Warningf("failed to get scheduler-stats pool by service %s error: %v, try another", service, err)
}
return fmt.Errorf("failed to find scheduler-stats pool by cinder service")
}
func (zone *SZone) getSchedulerStatsPool() ([]SPool, error) {
if len(zone.schedulerPools) == 0 {
return zone.schedulerPools, zone.fetchSchedulerStatsPool()
}
return zone.schedulerPools, nil
}
func (zone *SZone) getStorageByCategory(category string) (*SStorage, error) {
storages, err := zone.GetIStorages()
if err != nil {