mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
Merge pull request #3329 from zexi/feature/baremetal-cdrom-schedule
baremetal: add cdrom boot schedule
This commit is contained in:
@@ -51,6 +51,7 @@ type ServerConfig struct {
|
||||
Ncpu int `json:"vcpu_count"`
|
||||
Name string `json:"name"`
|
||||
GuestStatus string `json:"guest_status"`
|
||||
Cdrom string `json:"cdrom"`
|
||||
|
||||
// DEPRECATED
|
||||
Metadata map[string]string `json:"__meta__"`
|
||||
|
||||
@@ -22,10 +22,11 @@ import (
|
||||
type SchedulerTestBaseOptions struct {
|
||||
ServerConfigs
|
||||
|
||||
Mem int `help:"Memory size (MB), default 512" metavar:"MEMORY" default:"512"`
|
||||
Ncpu int `help:"#CPU cores of VM server, default 1" default:"1" metavar:"<SERVER_CPU_COUNT>"`
|
||||
Sku string `help:"Server SKU instance type"`
|
||||
Log bool `help:"Record to schedule history"`
|
||||
Mem int `help:"Memory size (MB), default 512" metavar:"MEMORY" default:"512"`
|
||||
Ncpu int `help:"#CPU cores of VM server, default 1" default:"1" metavar:"<SERVER_CPU_COUNT>"`
|
||||
Sku string `help:"Server SKU instance type"`
|
||||
Log bool `help:"Record to schedule history"`
|
||||
Cdrom string `help:"ISO image ID" metavar:"IMAGE_ID"`
|
||||
}
|
||||
|
||||
func (o SchedulerTestBaseOptions) data(s *mcclient.ClientSession) (*scheduler.ServerConfig, error) {
|
||||
@@ -46,6 +47,9 @@ func (o SchedulerTestBaseOptions) data(s *mcclient.ClientSession) (*scheduler.Se
|
||||
if o.Sku != "" {
|
||||
data.InstanceType = o.Sku
|
||||
}
|
||||
if o.Cdrom != "" {
|
||||
data.Cdrom = o.Cdrom
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// 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 baremetal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core"
|
||||
)
|
||||
|
||||
type CdromBootPredicate struct {
|
||||
BasePredicate
|
||||
}
|
||||
|
||||
func (p *CdromBootPredicate) Name() string {
|
||||
return "cdrom_boot"
|
||||
}
|
||||
|
||||
func (p *CdromBootPredicate) Clone() core.FitPredicate {
|
||||
return &CdromBootPredicate{}
|
||||
}
|
||||
|
||||
func (p *CdromBootPredicate) PreExecute(u *core.Unit, _ []core.Candidater) (bool, error) {
|
||||
cdrom := u.SchedData().Cdrom
|
||||
if len(cdrom) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (p *CdromBootPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []core.PredicateFailureReason, error) {
|
||||
h := predicates.NewPredicateHelper(p, u, c)
|
||||
info := c.Getter().GetIpmiInfo()
|
||||
if !info.CdromBoot {
|
||||
h.Exclude(fmt.Sprintf("ipmi not support cdrom boot"))
|
||||
}
|
||||
return h.GetResult()
|
||||
}
|
||||
@@ -39,5 +39,6 @@ func baremetalPredicates() sets.String {
|
||||
factory.RegisterFitPredicate("h-DiskschedtagFilter", &predicates.DiskSchedtagPredicate{}),
|
||||
factory.RegisterFitPredicate("i-NetschedtagFilter", &predicates.NetworkSchedtagPredicate{}),
|
||||
factory.RegisterFitPredicate("k-NetBondingFilter", &predicatebm.NetBondingPredicate{}),
|
||||
factory.RegisterFitPredicate("l-CdromFilter", &predicatebm.CdromBootPredicate{}),
|
||||
)
|
||||
}
|
||||
|
||||
+21
-2
@@ -22,11 +22,11 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/scheduler/api"
|
||||
|
||||
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
computedb "yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
computemodels "yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/api"
|
||||
schedmodels "yunion.io/x/onecloud/pkg/scheduler/models"
|
||||
)
|
||||
|
||||
@@ -43,6 +43,7 @@ type BaseHostDesc struct {
|
||||
HostSchedtags []computemodels.SSchedtag `json:"schedtags"`
|
||||
|
||||
InstanceGroups map[string]*api.CandidateGroup `json:"instance_groups"`
|
||||
IpmiInfo types.SIPMIInfo `json:"ipmi_info"`
|
||||
}
|
||||
|
||||
type baseHostGetter struct {
|
||||
@@ -192,6 +193,10 @@ func (b baseHostGetter) GetFreePort(netId string) int {
|
||||
return b.h.GetFreePort(netId)
|
||||
}
|
||||
|
||||
func (b baseHostGetter) GetIpmiInfo() types.SIPMIInfo {
|
||||
return b.h.IpmiInfo
|
||||
}
|
||||
|
||||
func reviseResourceType(resType string) string {
|
||||
if resType == "" {
|
||||
return computeapi.HostResourceTypeDefault
|
||||
@@ -232,10 +237,15 @@ func newBaseHostDesc(host *computemodels.SHost) (*BaseHostDesc, error) {
|
||||
if err := desc.fillSchedtags(); err != nil {
|
||||
return nil, fmt.Errorf("Fill schedtag error: %v", err)
|
||||
}
|
||||
|
||||
if err := desc.fillInstanceGroups(host); err != nil {
|
||||
return nil, fmt.Errorf("Fill instance group error: %v", err)
|
||||
}
|
||||
|
||||
if err := desc.fillIpmiInfo(host); err != nil {
|
||||
return nil, fmt.Errorf("Fill ipmi info error: %v", err)
|
||||
}
|
||||
|
||||
return desc, nil
|
||||
}
|
||||
|
||||
@@ -384,6 +394,15 @@ func (b *BaseHostDesc) fillInstanceGroups(host *computemodels.SHost) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BaseHostDesc) fillIpmiInfo(host *computemodels.SHost) error {
|
||||
info, err := host.GetIpmiInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.IpmiInfo = info
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *BaseHostDesc) GetEnableStatus() string {
|
||||
if h.Enabled {
|
||||
return "enable"
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
schedapi "yunion.io/x/onecloud/pkg/apis/scheduler"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
"yunion.io/x/onecloud/pkg/compute/baremetal"
|
||||
computemodels "yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/api"
|
||||
@@ -89,6 +90,8 @@ type CandidatePropertyGetter interface {
|
||||
|
||||
InstanceGroups() map[string]*api.CandidateGroup
|
||||
GetFreeGroupCount(groupId string) (int, error)
|
||||
|
||||
GetIpmiInfo() types.SIPMIInfo
|
||||
}
|
||||
|
||||
// Candidater replace host Candidate resource info
|
||||
|
||||
Reference in New Issue
Block a user