mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: 1. host start works for baremetal server with guest 2. fix
host-syncstatus 3. baremetal may answer pxe request for hypervisors
This commit is contained in:
@@ -25,6 +25,8 @@ func init() {
|
||||
HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv|aliyun|azure|qcloud|aws|huawei"`
|
||||
AnyMac string `help:"Mac matches one of the host's interface"`
|
||||
|
||||
IsBaremetal *bool `help:"filter host list by is_baremetal=true|false"`
|
||||
|
||||
ResourceType string `help:"Resource type" choices:"shared|prepaid|dedicated"`
|
||||
|
||||
Usable *bool `help:"List all zones that is usable"`
|
||||
|
||||
@@ -600,13 +600,18 @@ func (b *SBaremetalInstance) NeedPXEBoot() bool {
|
||||
taskNeedPXEBoot = true
|
||||
}
|
||||
ret := false
|
||||
if taskNeedPXEBoot || (task == nil && len(serverId) == 0) {
|
||||
if taskNeedPXEBoot || (task == nil && len(serverId) == 0 && b.GetHostType() == "baremetal") {
|
||||
ret = true
|
||||
}
|
||||
log.Infof("Check task %s, server %s NeedPXEBoot: %v", taskName, serverId, ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) GetHostType() string {
|
||||
hostType, _ := b.desc.GetString("host_type")
|
||||
return hostType
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) GetIPMINic(cliMac net.HardwareAddr) *types.SNic {
|
||||
nic := b.getNicByType(types.NIC_TYPE_IPMI)
|
||||
if nic == nil {
|
||||
|
||||
@@ -216,6 +216,7 @@ func (h *DHCPHandler) createOrUpdateBaremetal() (jsonutils.JSONObject, error) {
|
||||
session := h.baremetalManager.GetClientSession()
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(h.ClientMac.String()), "any_mac")
|
||||
params.Add(jsonutils.JSONTrue, "is_baremetal")
|
||||
ret, err := modules.Hosts.List(session, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+11
-10
@@ -2461,17 +2461,14 @@ func (self *SHost) PerformStart(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
guest := self.GetBaremetalServer()
|
||||
if guest != nil {
|
||||
if self.HostType != HOST_TYPE_BAREMETAL {
|
||||
if !utils.IsInStringArray(guest.Status, []string{VM_ADMIN}) {
|
||||
return nil, httperrors.NewBadRequestError("Cannot start baremetal with active guest")
|
||||
}
|
||||
} else {
|
||||
if utils.ToBool(guest.GetMetadata("is_fake_baremetal_server", userCred)) {
|
||||
return nil, self.InitializedGuestStart(ctx, userCred, guest)
|
||||
}
|
||||
self.SetStatus(userCred, BAREMETAL_START_MAINTAIN, "")
|
||||
return guest.PerformStart(ctx, userCred, query, data)
|
||||
if self.HostType == HOST_TYPE_BAREMETAL && utils.ToBool(guest.GetMetadata("is_fake_baremetal_server", userCred)) {
|
||||
return nil, self.InitializedGuestStart(ctx, userCred, guest)
|
||||
}
|
||||
// if !utils.IsInStringArray(guest.Status, []string{VM_ADMIN}) {
|
||||
// return nil, httperrors.NewBadRequestError("Cannot start baremetal with active guest")
|
||||
// }
|
||||
self.SetStatus(userCred, BAREMETAL_START_MAINTAIN, "")
|
||||
return guest.PerformStart(ctx, userCred, query, data)
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("force_reboot", jsonutils.NewBool(false))
|
||||
@@ -2633,6 +2630,10 @@ func (self *SHost) BaremetalSyncRequest(ctx context.Context, method httputils.TH
|
||||
}
|
||||
|
||||
func (self *SHost) StartSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
guest := self.GetBaremetalServer()
|
||||
if guest != nil {
|
||||
return guest.StartSyncstatus(ctx, userCred, parentTaskId)
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "BaremetalSyncStatusTask", self, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -23,9 +23,7 @@ func (self *BaremetalServerSyncStatusTask) OnInit(ctx context.Context, obj db.IS
|
||||
guest := obj.(*models.SGuest)
|
||||
baremetal := guest.GetHost()
|
||||
if baremetal == nil {
|
||||
kwargs := jsonutils.NewDict()
|
||||
kwargs.Set("status", jsonutils.NewString(models.VM_INIT))
|
||||
guest.PerformStatus(ctx, self.UserCred, nil, kwargs)
|
||||
guest.SetStatus(self.UserCred, models.VM_INIT, "BaremetalServerSyncStatusTask")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
return
|
||||
}
|
||||
@@ -41,24 +39,31 @@ func (self *BaremetalServerSyncStatusTask) OnInit(ctx context.Context, obj db.IS
|
||||
|
||||
func (self *BaremetalServerSyncStatusTask) OnGuestStatusTaskComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
var status string
|
||||
var hostStatus string
|
||||
if data.Contains("status") {
|
||||
statusStr, _ := data.GetString("status")
|
||||
switch statusStr {
|
||||
case "running":
|
||||
status = models.VM_RUNNING
|
||||
hostStatus = models.HOST_STATUS_RUNNING
|
||||
case "stopped", "ready":
|
||||
status = models.VM_READY
|
||||
hostStatus = models.HOST_STATUS_READY
|
||||
case "admin":
|
||||
status = models.VM_ADMIN
|
||||
hostStatus = models.HOST_STATUS_RUNNING
|
||||
default:
|
||||
status = models.VM_INIT
|
||||
hostStatus = models.HOST_STATUS_UNKNOWN
|
||||
}
|
||||
} else {
|
||||
status = models.VM_UNKNOWN
|
||||
hostStatus = models.HOST_STATUS_UNKNOWN
|
||||
}
|
||||
kwargs := jsonutils.NewDict()
|
||||
kwargs.Set("status", jsonutils.NewString(status))
|
||||
guest.PerformStatus(ctx, self.UserCred, nil, kwargs)
|
||||
guest.SetStatus(self.UserCred, status, "BaremetalServerSyncStatusTask")
|
||||
host := guest.GetHost()
|
||||
host.SetStatus(self.UserCred, hostStatus, "BaremetalServerSyncStatusTask")
|
||||
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user