mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix sync openstack hoststorages issue
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user