mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #1843 from wanyaoqi/bugfix/wyq/minor-fix0723
bugfix: baremetal import , guest panic notify
This commit is contained in:
@@ -0,0 +1 @@
|
||||
您的{{ .brand }}主机{{ .name }}系统崩溃了: {{ .reason }}
|
||||
@@ -0,0 +1 @@
|
||||
您的{{ .brand }}主机{{ .name }}系统崩溃了
|
||||
+36
-28
@@ -258,7 +258,14 @@ func (i *BmRegisterInput) isTimeout() bool {
|
||||
|
||||
// delay task
|
||||
func (m *SBaremetalManager) RegisterBaremetal(input *BmRegisterInput) {
|
||||
err := m.checkNetworkFromIps(input.RemoteIp, input.IpAddr)
|
||||
adminWire, err := m.checkNetworkFromIp(input.RemoteIp)
|
||||
if input.isTimeout() {
|
||||
return
|
||||
} else if err != nil {
|
||||
input.responseErr(httperrors.NewBadRequestError("Verify network failed: %s", err))
|
||||
return
|
||||
}
|
||||
ipmiWire, err := m.checkNetworkFromIp(input.IpAddr)
|
||||
if input.isTimeout() {
|
||||
return
|
||||
} else if err != nil {
|
||||
@@ -266,7 +273,7 @@ func (m *SBaremetalManager) RegisterBaremetal(input *BmRegisterInput) {
|
||||
return
|
||||
}
|
||||
|
||||
err = m.checkIpmiInfo(input.Username, input.Password, input.IpAddr)
|
||||
ipmiMac, err := m.checkIpmiInfo(input.Username, input.Password, input.IpAddr)
|
||||
if input.isTimeout() {
|
||||
return
|
||||
} else if err != nil {
|
||||
@@ -293,6 +300,7 @@ func (m *SBaremetalManager) RegisterBaremetal(input *BmRegisterInput) {
|
||||
registerTask := tasks.NewBaremetalRegisterTask(
|
||||
m, sshCli, input.Hostname, input.RemoteIp,
|
||||
input.Username, input.Password, input.IpAddr,
|
||||
ipmiMac, adminWire, ipmiWire,
|
||||
)
|
||||
err = registerTask.CreateBaremetal()
|
||||
if input.isTimeout() {
|
||||
@@ -306,20 +314,18 @@ func (m *SBaremetalManager) RegisterBaremetal(input *BmRegisterInput) {
|
||||
registerTask.DoPrepare(sshCli)
|
||||
}
|
||||
|
||||
func (m *SBaremetalManager) checkNetworkFromIps(ips ...string) error {
|
||||
// TODO ip search
|
||||
for _, ip := range ips {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("ip", jsonutils.NewString(ip))
|
||||
res, err := modules.Networks.List(m.GetClientSession(), params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Fetch network by ip %s failed: %s", ip, err)
|
||||
}
|
||||
if len(res.Data) == 0 {
|
||||
return fmt.Errorf("Can't find network from ip %s", ip)
|
||||
}
|
||||
func (m *SBaremetalManager) checkNetworkFromIp(ip string) (string, error) {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("ip", jsonutils.NewString(ip))
|
||||
params.Set("is_on_premise", jsonutils.JSONTrue)
|
||||
res, err := modules.Networks.List(m.GetClientSession(), params)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fetch network by ip %s failed: %s", ip, err)
|
||||
}
|
||||
return nil
|
||||
if len(res.Data) != 1 {
|
||||
return "", fmt.Errorf("Can't find network from ip %s", ip)
|
||||
}
|
||||
return res.Data[0].GetString("wire_id")
|
||||
}
|
||||
|
||||
func (m *SBaremetalManager) verifyMacAddr(sshCli *ssh.Client) error {
|
||||
@@ -371,11 +377,11 @@ func (m *SBaremetalManager) checkSshInfo(input *BmRegisterInput) (*ssh.Client, e
|
||||
return sshCLi, nil
|
||||
}
|
||||
|
||||
func (m *SBaremetalManager) checkIpmiInfo(username, password, ipAddr string) error {
|
||||
func (m *SBaremetalManager) checkIpmiInfo(username, password, ipAddr string) (net.HardwareAddr, error) {
|
||||
lanPlusTool := ipmitool.NewLanPlusIPMI(ipAddr, username, password)
|
||||
sysInfo, err := ipmitool.GetSysInfo(lanPlusTool)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, lanChannel := range ipmitool.GetLanChannels(sysInfo) {
|
||||
@@ -387,9 +393,9 @@ func (m *SBaremetalManager) checkIpmiInfo(username, password, ipAddr string) err
|
||||
if len(config.Mac) == 0 {
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
return config.Mac, nil
|
||||
}
|
||||
return fmt.Errorf("Ipmi can't fetch lan config")
|
||||
return nil, fmt.Errorf("Ipmi can't fetch lan config")
|
||||
}
|
||||
|
||||
func (m *SBaremetalManager) Stop() {
|
||||
@@ -970,13 +976,14 @@ func (b *SBaremetalInstance) SetTask(task tasks.ITask) {
|
||||
|
||||
func (b *SBaremetalInstance) InitAdminNetif(
|
||||
cliMac net.HardwareAddr,
|
||||
netConf *types.SNetworkConfig,
|
||||
wireId string,
|
||||
nicType string,
|
||||
netType string,
|
||||
isDoImport bool,
|
||||
) error {
|
||||
// start prepare task
|
||||
// sync status to PREPARE
|
||||
if nicType == types.NIC_TYPE_ADMIN &&
|
||||
if !isDoImport && nicType == types.NIC_TYPE_ADMIN &&
|
||||
utils.IsInStringArray(b.GetStatus(),
|
||||
[]string{baremetalstatus.INIT,
|
||||
baremetalstatus.PREPARE,
|
||||
@@ -989,7 +996,7 @@ func (b *SBaremetalInstance) InitAdminNetif(
|
||||
|
||||
nic := b.GetNicByMac(cliMac)
|
||||
if nic == nil || nic.WireId == "" {
|
||||
_, err := b.attachWire(cliMac, netConf.WireId, nicType)
|
||||
_, err := b.attachWire(cliMac, wireId, nicType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1000,13 +1007,14 @@ func (b *SBaremetalInstance) InitAdminNetif(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) RegisterNetif(
|
||||
cliMac net.HardwareAddr,
|
||||
netConf *types.SNetworkConfig,
|
||||
) error {
|
||||
func (b *SBaremetalInstance) RegisterNetif(cliMac net.HardwareAddr, wireId string) error {
|
||||
var nicType string
|
||||
nic := b.GetNicByMac(cliMac)
|
||||
if nic == nil || nic.WireId == "" || nic.WireId != netConf.WireId {
|
||||
desc, err := b.attachWire(cliMac, netConf.WireId, nic.Type)
|
||||
if nic != nil {
|
||||
nicType = nic.Type
|
||||
}
|
||||
if nic == nil || nic.WireId == "" || nic.WireId != wireId {
|
||||
desc, err := b.attachWire(cliMac, wireId, nicType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -189,12 +189,13 @@ func (req *dhcpRequest) fetchConfig(session *mcclient.ClientSession) (*dhcp.Resp
|
||||
req.baremetalInstance = bmInstance
|
||||
ipmiNic := req.baremetalInstance.GetIPMINic(req.ClientMac)
|
||||
if ipmiNic != nil && ipmiNic.Mac == req.ClientMac.String() {
|
||||
err = req.baremetalInstance.InitAdminNetif(req.ClientMac, req.netConfig, types.NIC_TYPE_IPMI, api.NETWORK_TYPE_IPMI)
|
||||
err = req.baremetalInstance.InitAdminNetif(
|
||||
req.ClientMac, req.netConfig.WireId, types.NIC_TYPE_IPMI, api.NETWORK_TYPE_IPMI, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
err = req.baremetalInstance.RegisterNetif(req.ClientMac, req.netConfig)
|
||||
err = req.baremetalInstance.RegisterNetif(req.ClientMac, req.netConfig.WireId)
|
||||
if err != nil {
|
||||
log.Errorf("RegisterNetif error: %v", err)
|
||||
return nil, err
|
||||
@@ -311,7 +312,8 @@ func (req *dhcpRequest) doInitBaremetalAdminNetif(desc jsonutils.JSONObject) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = req.baremetalInstance.InitAdminNetif(req.ClientMac, req.netConfig, types.NIC_TYPE_ADMIN, api.NETWORK_TYPE_PXE)
|
||||
err = req.baremetalInstance.InitAdminNetif(
|
||||
req.ClientMac, req.netConfig.WireId, types.NIC_TYPE_ADMIN, api.NETWORK_TYPE_PXE, false)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ type IBaremetalInstance interface {
|
||||
GetIPMINic(cliMac net.HardwareAddr) *types.SNic
|
||||
GetPXEDHCPConfig(arch uint16) (*dhcp.ResponseConfig, error)
|
||||
GetDHCPConfig(cliMac net.HardwareAddr) (*dhcp.ResponseConfig, error)
|
||||
InitAdminNetif(cliMac net.HardwareAddr, netConf *types.SNetworkConfig, nicType string, netType string) error
|
||||
RegisterNetif(cliMac net.HardwareAddr, netConf *types.SNetworkConfig) error
|
||||
InitAdminNetif(cliMac net.HardwareAddr, wireId, nicType, netType string, isDoImport bool) error
|
||||
RegisterNetif(cliMac net.HardwareAddr, wireId string) error
|
||||
GetTFTPResponse() string
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@ package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
o "yunion.io/x/onecloud/pkg/baremetal/options"
|
||||
"yunion.io/x/onecloud/pkg/baremetal/utils/ipmitool"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
@@ -41,11 +43,16 @@ type sBaremetalRegisterTask struct {
|
||||
IpmiUsername string
|
||||
IpmiPassword string
|
||||
IpmiIpAddr string
|
||||
IpmiMac net.HardwareAddr
|
||||
AdminWire string
|
||||
IpmiWire string
|
||||
|
||||
accessNic *types.SNicDevInfo
|
||||
}
|
||||
|
||||
func NewBaremetalRegisterTask(bmManager IBmManager, sshCli *ssh.Client, hostname, remoteIp, ipmiUsername, ipmiPassword, ipmiIpAddr string) *sBaremetalRegisterTask {
|
||||
func NewBaremetalRegisterTask(bmManager IBmManager, sshCli *ssh.Client,
|
||||
hostname, remoteIp, ipmiUsername, ipmiPassword, ipmiIpAddr string,
|
||||
ipmiMac net.HardwareAddr, adminWire, ipmiWire string) *sBaremetalRegisterTask {
|
||||
return &sBaremetalRegisterTask{
|
||||
BmManager: bmManager,
|
||||
SshCli: sshCli,
|
||||
@@ -54,6 +61,9 @@ func NewBaremetalRegisterTask(bmManager IBmManager, sshCli *ssh.Client, hostname
|
||||
IpmiUsername: ipmiUsername,
|
||||
IpmiPassword: ipmiPassword,
|
||||
IpmiIpAddr: ipmiIpAddr,
|
||||
IpmiMac: ipmiMac,
|
||||
AdminWire: adminWire,
|
||||
IpmiWire: ipmiWire,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,15 +73,22 @@ func (s *sBaremetalRegisterTask) CreateBaremetal() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("Register baremeatl failed on lsnic: %s", err)
|
||||
}
|
||||
|
||||
nicinfo := sysutils.ParseNicInfo(ret)
|
||||
for _, nic := range nicinfo {
|
||||
if nic.Up {
|
||||
ret, err := s.SshCli.RawRun("/sbin/ip a show " + nic.Dev)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Register baremeatl failed on ip command: %s", err)
|
||||
}
|
||||
if strings.Index(ret[0], s.RemoteIp) >= 0 {
|
||||
s.accessNic = nic
|
||||
break
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if s.accessNic == nil {
|
||||
return fmt.Errorf("Register baremeatl failed: NO nic up ???")
|
||||
return fmt.Errorf("Register baremeatl failed: access nic not found ???")
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
@@ -88,6 +105,19 @@ func (s *sBaremetalRegisterTask) CreateBaremetal() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("BmManager add baremetal failed: %s", err)
|
||||
}
|
||||
err = pxeBm.InitAdminNetif(s.accessNic.Mac, s.AdminWire, types.NIC_TYPE_ADMIN, api.NETWORK_TYPE_PXE, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("BmManager add admin netif failed: %s", err)
|
||||
}
|
||||
err = pxeBm.InitAdminNetif(s.IpmiMac, s.IpmiWire, types.NIC_TYPE_IPMI, api.NETWORK_TYPE_IPMI, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("BmManager add ipmi netif failed: %s", err)
|
||||
}
|
||||
for _, nic := range nicinfo {
|
||||
if nic.Dev != s.accessNic.Dev {
|
||||
pxeBm.RegisterNetif(nic.Mac, s.AdminWire)
|
||||
}
|
||||
}
|
||||
s.baremetal = pxeBm.(IBaremetal)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -113,14 +113,16 @@ func (self *SGuest) PerformEvent(ctx context.Context, userCred mcclient.TokenCre
|
||||
}
|
||||
if event == "GUEST_PANICKED" {
|
||||
kwargs := jsonutils.NewDict()
|
||||
kwargs.Set("name", jsonutils.NewString(self.Name))
|
||||
kwargs.Set("id", jsonutils.NewString(self.Id))
|
||||
kwargs.Set("event", jsonutils.NewString(event))
|
||||
kwargs.Set("reason", data)
|
||||
|
||||
db.OpsLog.LogEvent(self, db.ACT_GUEST_PANICKED, data.String(), userCred)
|
||||
logclient.AddSimpleActionLog(self, logclient.ACT_GUEST_PANICKED, data.String(), userCred, true)
|
||||
notifyclient.SystemNotify(notify.NotifyPriorityNormal, notifyclient.SERVER_PANICKED, kwargs)
|
||||
self.NotifyServerEvent(
|
||||
userCred,
|
||||
notifyclient.SERVER_PANICKED,
|
||||
notify.NotifyPriorityNormal,
|
||||
false, kwargs, true,
|
||||
)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -678,12 +680,18 @@ func (self *SGuest) StartGuestDeployTask(ctx context.Context, userCred mcclient.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuest) NotifyServerEvent(userCred mcclient.TokenCredential, event string, priority notify.TNotifyPriority, loginInfo bool) {
|
||||
func (self *SGuest) NotifyServerEvent(
|
||||
userCred mcclient.TokenCredential, event string, priority notify.TNotifyPriority,
|
||||
loginInfo bool, kwargs *jsonutils.JSONDict, notifyAdmin bool,
|
||||
) {
|
||||
meta, err := self.GetAllMetadata(nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
kwargs := jsonutils.NewDict()
|
||||
if kwargs == nil {
|
||||
kwargs = jsonutils.NewDict()
|
||||
}
|
||||
|
||||
kwargs.Add(jsonutils.NewString(self.Name), "name")
|
||||
kwargs.Add(jsonutils.NewString(self.Hypervisor), "hypervisor")
|
||||
host := self.GetHost()
|
||||
@@ -714,6 +722,9 @@ func (self *SGuest) NotifyServerEvent(userCred mcclient.TokenCredential, event s
|
||||
}
|
||||
}
|
||||
notifyclient.Notify(userCred.GetUserId(), false, priority, event, kwargs)
|
||||
if notifyAdmin {
|
||||
notifyclient.SystemNotify(priority, event, kwargs)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SGuest) NotifyAdminServerEvent(ctx context.Context, event string, priority notify.TNotifyPriority) {
|
||||
|
||||
@@ -116,7 +116,10 @@ func (self *GuestCreateTask) OnDeployGuestDescComplete(ctx context.Context, obj
|
||||
}
|
||||
|
||||
func (self *GuestCreateTask) notifyServerCreated(ctx context.Context, guest *models.SGuest) {
|
||||
guest.NotifyServerEvent(self.UserCred, notifyclient.SERVER_CREATED, notify.NotifyPriorityImportant, true)
|
||||
guest.NotifyServerEvent(
|
||||
self.UserCred, notifyclient.SERVER_CREATED,
|
||||
notify.NotifyPriorityImportant, true, nil, false,
|
||||
)
|
||||
guest.NotifyAdminServerEvent(ctx, notifyclient.SERVER_CREATED_ADMIN, notify.NotifyPriorityImportant)
|
||||
}
|
||||
|
||||
|
||||
@@ -278,6 +278,11 @@ func (self *GuestDeleteTask) DeleteGuest(ctx context.Context, guest *models.SGue
|
||||
}
|
||||
|
||||
func (self *GuestDeleteTask) NotifyServerDeleted(ctx context.Context, guest *models.SGuest) {
|
||||
guest.NotifyServerEvent(self.UserCred, notifyclient.SERVER_DELETED, notify.NotifyPriorityImportant, false)
|
||||
guest.NotifyServerEvent(
|
||||
self.UserCred,
|
||||
notifyclient.SERVER_DELETED,
|
||||
notify.NotifyPriorityImportant,
|
||||
false, nil, false,
|
||||
)
|
||||
guest.NotifyAdminServerEvent(ctx, notifyclient.SERVER_DELETED_ADMIN, notify.NotifyPriorityImportant)
|
||||
}
|
||||
|
||||
@@ -164,7 +164,12 @@ func (self *GuestRebuildRootTask) OnRebuildAllDisksComplete(ctx context.Context,
|
||||
}
|
||||
}
|
||||
db.OpsLog.LogEvent(guest, db.ACT_REBUILD_ROOT, "", self.UserCred)
|
||||
guest.NotifyServerEvent(self.UserCred, notifyclient.SERVER_REBUILD_ROOT, notify.NotifyPriorityImportant, true)
|
||||
guest.NotifyServerEvent(
|
||||
self.UserCred,
|
||||
notifyclient.SERVER_REBUILD_ROOT,
|
||||
notify.NotifyPriorityImportant,
|
||||
true, nil, false,
|
||||
)
|
||||
self.SetStage("OnSyncStatusComplete", nil)
|
||||
guest.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user