Merge pull request #1214 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-openstack-conflict-k to release/2.6.0

* commit 'c5d7189b1b7e6ecf9a3ed85191f65b1e731dc94c':
  尽可能的同步openstack host信息
This commit is contained in:
邱剑
2019-03-11 18:09:30 +08:00
2 changed files with 11 additions and 20 deletions
+2 -2
View File
@@ -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 {
+9 -18
View File
@@ -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
}