From e8377a870954a50cfb17a305b1681e06a8357f2f Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 23 Oct 2019 11:16:35 +0800 Subject: [PATCH] baremetal: add cdrom boot schedule --- pkg/apis/scheduler/api.go | 1 + pkg/mcclient/options/schedulers.go | 12 +++-- .../baremetal/cdrom_boot_predicate.go | 51 +++++++++++++++++++ pkg/scheduler/algorithmprovider/baremetal.go | 1 + pkg/scheduler/cache/candidate/base.go | 23 ++++++++- pkg/scheduler/core/types.go | 3 ++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 pkg/scheduler/algorithm/predicates/baremetal/cdrom_boot_predicate.go diff --git a/pkg/apis/scheduler/api.go b/pkg/apis/scheduler/api.go index d900406f48..cdd335e6e8 100644 --- a/pkg/apis/scheduler/api.go +++ b/pkg/apis/scheduler/api.go @@ -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__"` diff --git a/pkg/mcclient/options/schedulers.go b/pkg/mcclient/options/schedulers.go index 041517af59..ac9f4e515e 100644 --- a/pkg/mcclient/options/schedulers.go +++ b/pkg/mcclient/options/schedulers.go @@ -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:""` - 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:""` + 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 } diff --git a/pkg/scheduler/algorithm/predicates/baremetal/cdrom_boot_predicate.go b/pkg/scheduler/algorithm/predicates/baremetal/cdrom_boot_predicate.go new file mode 100644 index 0000000000..942add940a --- /dev/null +++ b/pkg/scheduler/algorithm/predicates/baremetal/cdrom_boot_predicate.go @@ -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() +} diff --git a/pkg/scheduler/algorithmprovider/baremetal.go b/pkg/scheduler/algorithmprovider/baremetal.go index 3f580790dd..f4088c5695 100644 --- a/pkg/scheduler/algorithmprovider/baremetal.go +++ b/pkg/scheduler/algorithmprovider/baremetal.go @@ -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{}), ) } diff --git a/pkg/scheduler/cache/candidate/base.go b/pkg/scheduler/cache/candidate/base.go index 4afa5b3be7..83e1441c8d 100644 --- a/pkg/scheduler/cache/candidate/base.go +++ b/pkg/scheduler/cache/candidate/base.go @@ -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" diff --git a/pkg/scheduler/core/types.go b/pkg/scheduler/core/types.go index 3e4f1249cf..6842ce95e5 100644 --- a/pkg/scheduler/core/types.go +++ b/pkg/scheduler/core/types.go @@ -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