From 42589ad68ff78a6bbb6ef59fc1e2135ec9c43229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Sat, 9 Mar 2019 14:37:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BD=E5=8F=AF=E8=83=BD=E7=9A=84=E5=90=8C?= =?UTF-8?q?=E6=AD=A5openstack=20host=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/util/openstack/host.go | 4 ++-- pkg/util/openstack/zone.go | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/pkg/util/openstack/host.go b/pkg/util/openstack/host.go index c7938367c6..49f35a11c1 100644 --- a/pkg/util/openstack/host.go +++ b/pkg/util/openstack/host.go @@ -32,7 +32,7 @@ type SResource struct { type SHost struct { zone *SZone - CpuInfo CpuInfo + CpuInfo string CurrentWorkload int Status string @@ -165,7 +165,7 @@ func (host *SHost) GetNodeCount() int8 { } func (host *SHost) GetCpuDesc() string { - return jsonutils.Marshal(host.CpuInfo).String() + return host.CpuInfo } func (host *SHost) GetCpuMhz() int { diff --git a/pkg/util/openstack/zone.go b/pkg/util/openstack/zone.go index a724046327..e9e5972ed3 100644 --- a/pkg/util/openstack/zone.go +++ b/pkg/util/openstack/zone.go @@ -7,7 +7,6 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/cloudcommon/version" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/models" ) @@ -144,15 +143,12 @@ type SOsHost struct { } func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) { - // 2.28 Hypervisor CPU字段是字符串,会解析失败 ihosts := []cloudprovider.ICloudHost{} hosts := []SHost{} - _, maxVersion, err := zone.region.GetVersion("compute") - if err == nil && version.GE(maxVersion, HYPERVISORS_VERSION) { - _, resp, err := zone.region.Get("compute", "/os-hypervisors/detail", maxVersion, nil) - if err != nil { - return nil, err - } + + // 尽可能的优先使用 os-hypervisor, 里面的信息更全些, 实在不行再使用 os-host + _, resp, err := zone.region.Get("compute", "/os-hypervisors/detail", "", nil) + if err == nil { if err := resp.Unmarshal(&hosts, "hypervisors"); err != nil { return nil, err } @@ -167,8 +163,7 @@ func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) { } return ihosts, nil } - - _, resp, err := zone.region.Get("compute", "/os-hosts", "", nil) + _, resp, err = zone.region.Get("compute", "/os-hosts", "", nil) if err != nil { return nil, err } @@ -188,18 +183,15 @@ func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) { } func (zone *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { - _, maxVersion, err := zone.region.GetVersion("compute") host := &SHost{zone: zone} - if err == nil && version.GE(maxVersion, HYPERVISORS_VERSION) { - _, resp, err := zone.region.Get("compute", "/os-hypervisors/"+id, maxVersion, nil) - if err != nil { - return nil, err - } + _, resp, err := zone.region.Get("compute", "/os-hypervisors/"+id, "", nil) + if err == nil { return host, resp.Unmarshal(&host, "hypervisor") } + host.HostName = id host.Resource = []map[string]SResource{} - _, resp, err := zone.region.Get("compute", "/os-hosts/"+id, maxVersion, nil) + _, resp, err = zone.region.Get("compute", "/os-hosts/"+id, "", nil) if err != nil { return nil, err }