diff --git a/pkg/util/openstack/host.go b/pkg/util/openstack/host.go index a9b69c6096..b66e219c71 100644 --- a/pkg/util/openstack/host.go +++ b/pkg/util/openstack/host.go @@ -39,7 +39,7 @@ type SResource struct { type SHost struct { zone *SZone - CpuInfo CpuInfo + CpuInfo string CurrentWorkload int Status string @@ -294,7 +294,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 8638c9616b..efa9368635 100644 --- a/pkg/util/openstack/zone.go +++ b/pkg/util/openstack/zone.go @@ -7,10 +7,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/models" - "yunion.io/x/onecloud/pkg/util/version" ) type ZoneState struct { @@ -145,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.List("compute", "/os-hypervisors/detail", maxVersion, nil) - if err != nil { - return nil, err - } + + // 尽可能的优先使用 os-hypervisor, 里面的信息更全些, 实在不行再使用 os-host + _, resp, err := zone.region.List("compute", "/os-hypervisors/detail", "", nil) + if err == nil { if err := resp.Unmarshal(&hosts, "hypervisors"); err != nil { return nil, err } @@ -168,8 +163,7 @@ func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) { } return ihosts, nil } - - _, resp, err := zone.region.List("compute", "/os-hosts", "", nil) + _, resp, err = zone.region.List("compute", "/os-hosts", "", nil) if err != nil { return nil, err } @@ -189,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 }