mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #3548 from swordqiu/hotfix/qj-unify-baremetal-sys-manufacture
fix: normalize baremetal sysinfo manufacture
This commit is contained in:
@@ -1210,7 +1210,7 @@ func (b *SBaremetalInstance) GetIPMIConfig() *types.SIPMIInfo {
|
||||
return nil
|
||||
}
|
||||
if conf.Username == "" {
|
||||
sysInfo := types.SIPMISystemInfo{}
|
||||
sysInfo := types.SSystemInfo{}
|
||||
err := b.desc.Unmarshal(&sysInfo, "sys_info")
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal get sys_info error: %v", err)
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
package profiles
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
)
|
||||
|
||||
@@ -97,26 +95,26 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func GetProfile(sysinfo *types.SIPMISystemInfo) IPMIProfile {
|
||||
profile, ok := PROFILES[strings.ToLower(sysinfo.Manufacture)]
|
||||
func GetProfile(sysinfo *types.SSystemInfo) IPMIProfile {
|
||||
profile, ok := PROFILES[sysinfo.OemName]
|
||||
if ok {
|
||||
return profile
|
||||
}
|
||||
return DefaultProfile()
|
||||
}
|
||||
|
||||
func GetLanChannel(sysinfo *types.SIPMISystemInfo) []int {
|
||||
func GetLanChannel(sysinfo *types.SSystemInfo) []int {
|
||||
return GetProfile(sysinfo).LanChannel
|
||||
}
|
||||
|
||||
func GetRootId(sysinfo *types.SIPMISystemInfo) int {
|
||||
func GetRootId(sysinfo *types.SSystemInfo) int {
|
||||
return GetProfile(sysinfo).RootId
|
||||
}
|
||||
|
||||
func GetRootName(sysinfo *types.SIPMISystemInfo) string {
|
||||
func GetRootName(sysinfo *types.SSystemInfo) string {
|
||||
return GetProfile(sysinfo).RootName
|
||||
}
|
||||
|
||||
func IsStrongPass(sysinfo *types.SIPMISystemInfo) bool {
|
||||
func IsStrongPass(sysinfo *types.SSystemInfo) bool {
|
||||
return GetProfile(sysinfo).StrongPass
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func newBaremetalPrepareTask(baremetal IBaremetal, userCred mcclient.TokenCreden
|
||||
}
|
||||
|
||||
type baremetalPrepareInfo struct {
|
||||
sysInfo *types.SDMISystemInfo
|
||||
sysInfo *types.SSystemInfo
|
||||
cpuInfo *types.SCPUInfo
|
||||
dmiCpuInfo *types.SDMICPUInfo
|
||||
memInfo *types.SDMIMemInfo
|
||||
@@ -156,15 +156,13 @@ func (task *sBaremetalPrepareTask) configIPMISetting(cli *ssh.Client, i *baremet
|
||||
ipmiInfo = i.ipmiInfo
|
||||
)
|
||||
sshIPMI := ipmitool.NewSSHIPMI(cli)
|
||||
// ipmitool.SetSysInfo
|
||||
ipmiSysInfo := sysInfo.ToIPMISystemInfo()
|
||||
setIPMILanPortShared(sshIPMI, ipmiSysInfo)
|
||||
ipmiUser, ipmiPasswd, ipmiIpAddr := task.getIPMIUserPasswd(i.ipmiInfo, ipmiSysInfo)
|
||||
setIPMILanPortShared(sshIPMI, sysInfo)
|
||||
ipmiUser, ipmiPasswd, ipmiIpAddr := task.getIPMIUserPasswd(i.ipmiInfo, sysInfo)
|
||||
ipmiInfo.Username = ipmiUser
|
||||
ipmiInfo.Password = ipmiPasswd
|
||||
|
||||
var ipmiLanChannel int = -1
|
||||
for _, lanChannel := range ipmitool.GetLanChannels(ipmiSysInfo) {
|
||||
for _, lanChannel := range ipmitool.GetLanChannels(sysInfo) {
|
||||
log.Infof("Try lan channel %d ...", lanChannel)
|
||||
conf, err := ipmitool.GetLanConfig(sshIPMI, lanChannel)
|
||||
if err != nil {
|
||||
@@ -186,7 +184,7 @@ func (task *sBaremetalPrepareTask) configIPMISetting(cli *ssh.Client, i *baremet
|
||||
// ignore the error
|
||||
log.Errorf("Send IPMI nic %#v info: %v", ipmiNic, err)
|
||||
}
|
||||
rootId := ipmitool.GetRootId(ipmiSysInfo)
|
||||
rootId := ipmitool.GetRootId(sysInfo)
|
||||
err = ipmitool.CreateOrSetAdminUser(sshIPMI, lanChannel, rootId, ipmiUser, ipmiPasswd)
|
||||
if err != nil {
|
||||
// ignore the error
|
||||
@@ -521,7 +519,7 @@ func (task *sBaremetalPrepareTask) tryLocalIpmiAddr(sshIPMI *ipmitool.SSHIPMI, i
|
||||
return false
|
||||
}
|
||||
|
||||
func (task *sBaremetalPrepareTask) getIPMIUserPasswd(oldIPMIConf *types.SIPMIInfo, sysInfo *types.SIPMISystemInfo) (string, string, string) {
|
||||
func (task *sBaremetalPrepareTask) getIPMIUserPasswd(oldIPMIConf *types.SIPMIInfo, sysInfo *types.SSystemInfo) (string, string, string) {
|
||||
var (
|
||||
ipmiUser string
|
||||
ipmiPasswd string
|
||||
@@ -580,7 +578,7 @@ func (task *sBaremetalPrepareTask) getClientSession() *mcclient.ClientSession {
|
||||
return task.baremetal.GetClientSession()
|
||||
}
|
||||
|
||||
func getDMISysinfo(cli *ssh.Client) (*types.SDMISystemInfo, error) {
|
||||
func getDMISysinfo(cli *ssh.Client) (*types.SSystemInfo, error) {
|
||||
ret, err := cli.Run("/usr/sbin/dmidecode -t 1")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -728,15 +726,16 @@ func (task *sBaremetalPrepareTask) collectDiskInfo(diskInfo []*baremetal.Baremet
|
||||
return size, diskType
|
||||
}
|
||||
|
||||
func setIPMILanPortShared(cli ipmitool.IPMIExecutor, sysInfo *types.SIPMISystemInfo) {
|
||||
func setIPMILanPortShared(cli ipmitool.IPMIExecutor, sysInfo *types.SSystemInfo) {
|
||||
if !o.Options.IpmiLanPortShared {
|
||||
return
|
||||
}
|
||||
oemName := strings.ToLower(sysInfo.Manufacture)
|
||||
var err error
|
||||
if strings.Contains(oemName, "huawei") {
|
||||
switch sysInfo.OemName {
|
||||
case types.OEM_NAME_HUAWEI:
|
||||
err = ipmitool.SetHuaweiIPMILanPortShared(cli)
|
||||
} else if strings.Contains(oemName, "dell") {
|
||||
case types.OEM_NAME_DELL:
|
||||
err = ipmitool.SetDellIPMILanPortShared(cli)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -104,10 +104,11 @@ func (self *SBaremetalIpmiProbeTask) doRedfishIpmiProbe(ctx context.Context, drv
|
||||
updateInfo["mem_size"] = sysInfo.MemoryGB * 1024
|
||||
updateInfo["sn"] = sysInfo.SerialNumber
|
||||
updateInfo["uuid"] = sysInfo.UUID
|
||||
dmiSysInfo := &types.SDMISystemInfo{
|
||||
dmiSysInfo := &types.SSystemInfo{
|
||||
Manufacture: sysInfo.Manufacturer,
|
||||
Model: sysInfo.Model,
|
||||
SN: sysInfo.SerialNumber,
|
||||
OemName: types.ManufactureOemName(sysInfo.Manufacturer),
|
||||
}
|
||||
updateInfo["sys_info"] = dmiSysInfo
|
||||
updateInfo["is_baremetal"] = true
|
||||
@@ -200,11 +201,12 @@ func (self *SBaremetalIpmiProbeTask) doRawIpmiProbe(ctx context.Context, cli ipm
|
||||
updateInfo := make(map[string]interface{})
|
||||
if len(sysInfo.SN) > 0 {
|
||||
updateInfo["sn"] = sysInfo.SN
|
||||
dmiSysInfo := &types.SDMISystemInfo{
|
||||
dmiSysInfo := &types.SSystemInfo{
|
||||
Manufacture: sysInfo.Manufacture,
|
||||
Model: sysInfo.Model,
|
||||
Version: sysInfo.Version,
|
||||
SN: sysInfo.SN,
|
||||
OemName: types.ManufactureOemName(sysInfo.Manufacture),
|
||||
}
|
||||
updateInfo["sys_info"] = dmiSysInfo
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func GetSysGuid(exector IPMIExecutor) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func GetSysInfo(exector IPMIExecutor) (*types.SIPMISystemInfo, error) {
|
||||
func GetSysInfo(exector IPMIExecutor) (*types.SSystemInfo, error) {
|
||||
// TODO: do cache
|
||||
args := []string{"fru", "print", "0"}
|
||||
lines, err := exector.ExecuteCommand(args...)
|
||||
@@ -190,20 +190,21 @@ func GetSysInfo(exector IPMIExecutor) (*types.SIPMISystemInfo, error) {
|
||||
// no product serial
|
||||
ret["sn"] = bsn
|
||||
}
|
||||
info := types.SIPMISystemInfo{}
|
||||
info := types.SSystemInfo{}
|
||||
err = sysutils.DumpMapToObject(ret, &info)
|
||||
info.OemName = types.ManufactureOemName(info.Manufacture)
|
||||
return &info, err
|
||||
}
|
||||
|
||||
func GetLanChannels(sysinfo *types.SIPMISystemInfo) []int {
|
||||
func GetLanChannels(sysinfo *types.SSystemInfo) []int {
|
||||
return profiles.GetLanChannel(sysinfo)
|
||||
}
|
||||
|
||||
func GetDefaultLanChannel(sysinfo *types.SIPMISystemInfo) int {
|
||||
func GetDefaultLanChannel(sysinfo *types.SSystemInfo) int {
|
||||
return GetLanChannels(sysinfo)[0]
|
||||
}
|
||||
|
||||
func GetRootId(sysinfo *types.SIPMISystemInfo) int {
|
||||
func GetRootId(sysinfo *types.SSystemInfo) int {
|
||||
return profiles.GetRootId(sysinfo)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestGetSysInfo(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *types.SIPMISystemInfo
|
||||
want *types.SSystemInfo
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
|
||||
package types
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SSHConfig struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
@@ -22,20 +25,50 @@ type SSHConfig struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type SDMISystemInfo struct {
|
||||
Manufacture string `json:"manufacture"`
|
||||
Model string `json:"model"`
|
||||
Version string `json:"version,omitempty"`
|
||||
SN string `json:"sn"`
|
||||
const (
|
||||
OEM_NAME_DELL = "dell"
|
||||
OEM_NAME_HPE = "hpe"
|
||||
OEM_NAME_HP = "hp"
|
||||
OEM_NAME_HUAWEI = "huawei"
|
||||
OEM_NAME_INSPUR = "inspur"
|
||||
OEM_NAME_LENOVO = "lenovo"
|
||||
OEM_NAME_FOXCONN = "foxconn"
|
||||
OEM_NAME_QEMU = "qemu"
|
||||
OEM_NAME_SUPERMICRO = "supermicro"
|
||||
)
|
||||
|
||||
var (
|
||||
OEM_NAMES = []string{
|
||||
OEM_NAME_DELL,
|
||||
OEM_NAME_HPE,
|
||||
OEM_NAME_HP,
|
||||
OEM_NAME_HUAWEI,
|
||||
OEM_NAME_INSPUR,
|
||||
OEM_NAME_LENOVO,
|
||||
OEM_NAME_FOXCONN,
|
||||
OEM_NAME_QEMU,
|
||||
OEM_NAME_SUPERMICRO,
|
||||
}
|
||||
)
|
||||
|
||||
func ManufactureOemName(manufacture string) string {
|
||||
manufacture = strings.ToLower(strings.TrimSpace(manufacture))
|
||||
for _, oem := range OEM_NAMES {
|
||||
if strings.Contains(manufacture, oem) {
|
||||
return oem
|
||||
}
|
||||
}
|
||||
return manufacture
|
||||
}
|
||||
|
||||
func (info *SDMISystemInfo) ToIPMISystemInfo() *SIPMISystemInfo {
|
||||
return &SIPMISystemInfo{
|
||||
Manufacture: info.Manufacture,
|
||||
Model: info.Model,
|
||||
Version: info.Version,
|
||||
SN: info.SN,
|
||||
}
|
||||
type SSystemInfo struct {
|
||||
Manufacture string `json:"manufacture"`
|
||||
Model string `json:"model"`
|
||||
SN string `json:"sn"`
|
||||
Version string `json:"version,omitempty"`
|
||||
BSN string `json:"bsn"`
|
||||
|
||||
OemName string `json:"oem_name"`
|
||||
}
|
||||
|
||||
type SCPUInfo struct {
|
||||
@@ -79,14 +112,6 @@ type SDiskInfo struct {
|
||||
Driver string `json:"driver"`
|
||||
}
|
||||
|
||||
type SIPMISystemInfo struct {
|
||||
Manufacture string `json:"manufacture"`
|
||||
Model string `json:"model"`
|
||||
SN string `json:"sn"`
|
||||
Version string `json:"version"`
|
||||
BSN string `json:"bsn"`
|
||||
}
|
||||
|
||||
type SIPMILanConfig struct {
|
||||
IPSrc string `json:"ipsrc"`
|
||||
IPAddr string `json:"ipaddr"`
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type BaremetalIpmiProbeTask struct {
|
||||
@@ -47,12 +48,13 @@ func (self *BaremetalIpmiProbeTask) OnInit(ctx context.Context, obj db.IStandalo
|
||||
}
|
||||
|
||||
func (self *BaremetalIpmiProbeTask) OnFailure(ctx context.Context, baremetal *models.SHost, reason string) {
|
||||
logclient.AddActionLogWithStartable(self, baremetal, logclient.ACT_PROBE, reason, self.UserCred, false)
|
||||
baremetal.SetStatus(self.UserCred, api.BAREMETAL_PROBE_FAIL, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *BaremetalIpmiProbeTask) OnSyncConfigComplete(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) {
|
||||
// baremetal.ClearSchedDescCache()
|
||||
logclient.AddActionLogWithStartable(self, baremetal, logclient.ACT_PROBE, baremetal.GetShortDesc(ctx), self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ func (h *SHostInfo) detectHostInfo() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.sysinfo.SDMISystemInfo = sysinfo
|
||||
h.sysinfo.SSystemInfo = sysinfo
|
||||
|
||||
h.detectKvmModuleSupport()
|
||||
h.detectNestSupport()
|
||||
@@ -452,7 +452,7 @@ func (h *SHostInfo) detectiveKernelVersion() {
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
h.sysinfo.KernelVersion = string(out)
|
||||
h.sysinfo.KernelVersion = strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
func (h *SHostInfo) detectiveSyssoftwareInfo() error {
|
||||
|
||||
@@ -311,7 +311,7 @@ func NewNIC(desc string) (*SNIC, error) {
|
||||
}
|
||||
|
||||
type SSysInfo struct {
|
||||
*types.SDMISystemInfo
|
||||
*types.SSystemInfo
|
||||
|
||||
Nest string `json:"nest,omitempty"`
|
||||
OsDistribution string `json:"os_distribution"`
|
||||
|
||||
@@ -173,6 +173,7 @@ const (
|
||||
ACT_SUBIMAGE_UPDATE = "更新子镜像"
|
||||
|
||||
ACT_PREPARE = "同步硬件配置"
|
||||
ACT_PROBE = "检测配置"
|
||||
|
||||
ACT_INSTANCE_GROUP_BIND = "绑定主机组"
|
||||
ACT_INSTANCE_GROUP_UNBIND = "解绑主机组"
|
||||
|
||||
@@ -45,7 +45,7 @@ func DumpMapToObject(data map[string]string, obj interface{}) error {
|
||||
return jsonutils.Marshal(data).Unmarshal(obj)
|
||||
}
|
||||
|
||||
func ParseDMISysinfo(lines []string) (*types.SDMISystemInfo, error) {
|
||||
func ParseDMISysinfo(lines []string) (*types.SSystemInfo, error) {
|
||||
if len(lines) == 0 {
|
||||
return nil, fmt.Errorf("Empty input")
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func ParseDMISysinfo(lines []string) (*types.SDMISystemInfo, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
info := types.SDMISystemInfo{}
|
||||
info := types.SSystemInfo{}
|
||||
err := DumpMapToObject(ret, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -72,6 +72,7 @@ func ParseDMISysinfo(lines []string) (*types.SDMISystemInfo, error) {
|
||||
if strings.ToLower(info.Version) == "none" {
|
||||
info.Version = ""
|
||||
}
|
||||
info.OemName = types.ManufactureOemName(info.Manufacture)
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestParseDMISysinfo(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *types.SDMISystemInfo
|
||||
want *types.SSystemInfo
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -94,11 +94,12 @@ func TestParseDMISysinfo(t *testing.T) {
|
||||
" UUID: bca177cc-2bce-11b2-a85c-e98996f19d2f",
|
||||
" SKU Number: LENOVO_MT_20J6_BU_Think_FM_ThinkPad T470p",
|
||||
}},
|
||||
want: &types.SDMISystemInfo{
|
||||
want: &types.SSystemInfo{
|
||||
Manufacture: "LENOVO",
|
||||
Model: "20J6CTO1WW",
|
||||
Version: "ThinkPad T470p",
|
||||
SN: "PF112JKK",
|
||||
OemName: "lenovo",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
@@ -109,7 +110,7 @@ func TestParseDMISysinfo(t *testing.T) {
|
||||
" Version: None",
|
||||
" Serial Number: PF112JKK",
|
||||
}},
|
||||
want: &types.SDMISystemInfo{
|
||||
want: &types.SSystemInfo{
|
||||
Model: "20J6CTO1WW",
|
||||
Version: "",
|
||||
SN: "PF112JKK",
|
||||
|
||||
Reference in New Issue
Block a user