From 9ddf2074417e06f4caa5f5503fbb93c52ea5c4f0 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Tue, 8 Dec 2020 15:41:27 +0800 Subject: [PATCH] fix(region): openstack available zones --- pkg/multicloud/openstack/vpc.go | 4 ++++ pkg/multicloud/openstack/zone.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/multicloud/openstack/vpc.go b/pkg/multicloud/openstack/vpc.go index faabb2a0d9..755ac27fab 100644 --- a/pkg/multicloud/openstack/vpc.go +++ b/pkg/multicloud/openstack/vpc.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" + "yunion.io/x/pkg/utils" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -191,6 +192,9 @@ func (vpc *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) { } iwire := []cloudprovider.ICloudWire{} for i := range vpc.region.zones { + if !utils.IsInStringArray(vpc.region.zones[i].ZoneName, vpc.AvailabilityZones) { + continue + } wire := &SWire{vpc: vpc, zone: &vpc.region.zones[i]} iwire = append(iwire, wire) } diff --git a/pkg/multicloud/openstack/zone.go b/pkg/multicloud/openstack/zone.go index 205cc7c2cc..1731d4aefc 100644 --- a/pkg/multicloud/openstack/zone.go +++ b/pkg/multicloud/openstack/zone.go @@ -39,7 +39,10 @@ type HostState struct { type SZone struct { region *SRegion - ZoneName string + ZoneName string + ZoneState ZoneState + + Hosts map[string]jsonutils.JSONObject hosts []SHypervisor } @@ -65,7 +68,10 @@ func (zone *SZone) IsEmulated() bool { } func (zone *SZone) GetStatus() string { - return api.ZONE_ENABLE + if zone.ZoneState.Available { + return api.ZONE_ENABLE + } + return api.ZONE_DISABLE } func (zone *SZone) Refresh() error { @@ -160,6 +166,9 @@ func (zone *SZone) fetchHosts() error { if strings.Index(hypervisor, "vmware") != -1 { continue } + if _, ok := zone.Hosts[hypervisors[i].GetName()]; !ok { + continue + } zone.hosts = append(zone.hosts, hypervisors[i]) } return nil