hotfix: sync openstack cup and memory cmtbound

This commit is contained in:
ioito
2019-08-07 17:55:58 +08:00
parent 35dc5b7e0f
commit 47f7357cae
14 changed files with 145 additions and 0 deletions
+2
View File
@@ -218,7 +218,9 @@ type ICloudHost interface {
GetNodeCount() int8
GetCpuDesc() string
GetCpuMhz() int
GetCpuCmtbound() float32
GetMemSizeMB() int
GetMemCmtbound() float32
GetStorageSizeMB() int
GetStorageType() string
GetHostType() string
+14
View File
@@ -1394,6 +1394,14 @@ func (self *SHost) syncWithCloudHost(ctx context.Context, userCred mcclient.Toke
self.StorageType = extHost.GetStorageType()
self.HostType = extHost.GetHostType()
if cpuCmt := extHost.GetCpuCmtbound(); cpuCmt > 0 {
self.CpuCmtbound = cpuCmt
}
if memCmt := extHost.GetMemCmtbound(); memCmt > 0 {
self.MemCmtbound = memCmt
}
self.IsEmulated = extHost.IsEmulated()
self.Enabled = extHost.GetEnabled()
@@ -1481,7 +1489,13 @@ func (manager *SHostManager) newFromCloudHost(ctx context.Context, userCred mccl
host.StorageSize = extHost.GetStorageSizeMB()
host.StorageType = extHost.GetStorageType()
host.CpuCmtbound = 8.0
if cpuCmt := extHost.GetCpuCmtbound(); cpuCmt > 0 {
host.CpuCmtbound = cpuCmt
}
host.MemCmtbound = 1.0
if memCmt := extHost.GetMemCmtbound(); memCmt > 0 {
host.MemCmtbound = memCmt
}
host.ManagerId = provider.Id
host.IsEmulated = extHost.IsEmulated()
+2
View File
@@ -19,6 +19,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/multicloud"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
@@ -26,6 +27,7 @@ import (
)
type SHost struct {
multicloud.SHostBase
zone *SZone
}
+2
View File
@@ -22,9 +22,11 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
)
type SHost struct {
multicloud.SHostBase
zone *SZone
}
+2
View File
@@ -22,9 +22,11 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
)
type SClassicHost struct {
multicloud.SHostBase
zone *SZone
}
+2
View File
@@ -27,10 +27,12 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
"yunion.io/x/onecloud/pkg/util/seclib2"
)
type SHost struct {
multicloud.SHostBase
zone *SZone
}
+2
View File
@@ -31,6 +31,7 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
)
var HOST_SYSTEM_PROPS = []string{"name", "parent", "summary", "config", "hardware", "vm", "datastore"}
@@ -77,6 +78,7 @@ type SHostStorageInfo struct {
}
type SHost struct {
multicloud.SHostBase
SManagedObject
nicInfo []SHostNicInfo
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package multicloud
type SHostBase struct {
}
func (self *SHostBase) GetCpuCmtbound() float32 {
return 0.0
}
func (self *SHostBase) GetMemCmtbound() float32 {
return 0.0
}
+2
View File
@@ -22,10 +22,12 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
"yunion.io/x/onecloud/pkg/util/billing"
)
type SHost struct {
multicloud.SHostBase
zone *SZone
projectId string
+73
View File
@@ -16,7 +16,11 @@ package openstack
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/utils"
@@ -56,6 +60,7 @@ type SHost struct {
CpuInfo string
Aggregates []string
CurrentWorkload int
Status string
State string
@@ -316,6 +321,50 @@ func (host *SHost) GetSN() string {
return ""
}
func (host *SHost) GetCpuCmtbound() float32 {
aggregates, err := host.zone.region.GetAggregates()
if err != nil || len(aggregates) == 0 {
return 16.0
}
CpuCmtbound := 1000000.0
for _, aggregate := range aggregates {
if utils.IsInStringArray(host.GetName(), aggregate.Hosts) {
if _cmtbound, ok := aggregate.Metadata["cpu_allocation_ratio"]; ok {
cmtbound, err := strconv.ParseFloat(_cmtbound, 32)
if err == nil && CpuCmtbound > cmtbound {
CpuCmtbound = cmtbound
}
}
}
}
if CpuCmtbound >= 1000000.0 {
return 16.0
}
return float32(CpuCmtbound)
}
func (host *SHost) GetMemCmtbound() float32 {
aggregates, err := host.zone.region.GetAggregates()
if err != nil || len(aggregates) == 0 {
return 1.5
}
MemCmtbound := 1000000.0
for _, aggregate := range aggregates {
if utils.IsInStringArray(host.GetName(), aggregate.Hosts) {
if _cmtbound, ok := aggregate.Metadata["ram_allocation_ratio"]; ok {
cmtbound, err := strconv.ParseFloat(_cmtbound, 32)
if err == nil && MemCmtbound > cmtbound {
MemCmtbound = cmtbound
}
}
}
}
if MemCmtbound >= 1000000.0 {
return 1.5
}
return float32(MemCmtbound)
}
func (host *SHost) GetCpuCount() int {
if host.Vcpus > 0 {
return host.Vcpus
@@ -428,3 +477,27 @@ func (host *SHost) Refresh() error {
}
return nil
}
type SAggregate struct {
AvailabilityZone string
CreatedAt time.Time
Deleted bool
Hosts []string
Id string
Metadata map[string]string
Name string
Uuid string
}
func (region *SRegion) GetAggregates() ([]SAggregate, error) {
_, resp, err := region.List("compute", "/os-aggregates", "", nil)
if err != nil {
return nil, err
}
aggregates := []SAggregate{}
err = resp.Unmarshal(&aggregates, "aggregates")
if err != nil {
return nil, errors.Wrap(err, `resp.Unmarshal(&aggregates, "aggregates")`)
}
return aggregates, nil
}
+12
View File
@@ -51,4 +51,16 @@ func init() {
return nil
})
type AggregateListOption struct {
}
shellutils.R(&AggregateListOption{}, "aggregate-list", "List os-aggregates", func(cli *openstack.SRegion, args *AggregateListOption) error {
aggregates, err := cli.GetAggregates()
if err != nil {
return err
}
printList(aggregates, 0, 0, 0, []string{})
return nil
})
}
+2
View File
@@ -23,10 +23,12 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
"yunion.io/x/onecloud/pkg/util/billing"
)
type SHost struct {
multicloud.SHostBase
zone *SZone
}
+2
View File
@@ -27,9 +27,11 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
)
type SHost struct {
multicloud.SHostBase
zone *SZone
projectId string
+2
View File
@@ -22,11 +22,13 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
api "yunion.io/x/onecloud/pkg/apis/compute"
)
type SHost struct {
multicloud.SHostBase
zone *SZone
ZStackBasic