mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: schedule fail should post actionlog
This commit is contained in:
@@ -1274,7 +1274,7 @@ func fillDiskConfigByImage(ctx context.Context, userCred mcclient.TokenCredentia
|
||||
// diskConfig.ImageDiskFormat = image.DiskFormat
|
||||
CachedimageManager.ImageAddRefCount(image.Id)
|
||||
if diskConfig.SizeMb == 0 {
|
||||
diskConfig.SizeMb = image.MinDisk // MB
|
||||
diskConfig.SizeMb = image.MinDisk * 1024 // MB
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -920,6 +920,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
if rootDiskConfig.SizeMb == 0 {
|
||||
rootDiskConfig.SizeMb = GetDriver(hypervisor).GetMinimalSysDiskSizeGb() * 1024
|
||||
}
|
||||
log.Debugf("ROOT DISK: %#v", rootDiskConfig)
|
||||
data.Set("disk.0", jsonutils.Marshal(rootDiskConfig))
|
||||
|
||||
for i := 0; i < len(dataDiskDefs); i += 1 {
|
||||
|
||||
@@ -44,8 +44,8 @@ func (self *DiskBatchCreateTask) OnInit(ctx context.Context, objs []db.IStandalo
|
||||
StartScheduleObjects(ctx, self, toSchedDisks)
|
||||
}
|
||||
|
||||
func (self *DiskBatchCreateTask) OnScheduleFailCallback(obj IScheduleModel, reason string) {
|
||||
self.SSchedTask.OnScheduleFailCallback(obj, reason)
|
||||
func (self *DiskBatchCreateTask) OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string) {
|
||||
self.SSchedTask.OnScheduleFailCallback(ctx, obj, reason)
|
||||
disk := obj.(*models.SDisk)
|
||||
log.Errorf("Schedule disk %s failed", disk.Name)
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (self *GuestCreateBackupTask) GetSchedParams() *jsonutils.JSONDict {
|
||||
return schedDesc
|
||||
}
|
||||
|
||||
func (self *GuestCreateBackupTask) OnScheduleFailCallback(obj IScheduleModel, reason string) {
|
||||
func (self *GuestCreateBackupTask) OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type GuestBatchCreateTask struct {
|
||||
@@ -24,8 +25,8 @@ func (self *GuestBatchCreateTask) OnInit(ctx context.Context, objs []db.IStandal
|
||||
StartScheduleObjects(ctx, self, objs)
|
||||
}
|
||||
|
||||
func (self *GuestBatchCreateTask) OnScheduleFailCallback(obj IScheduleModel, reason string) {
|
||||
self.SSchedTask.OnScheduleFailCallback(obj, reason)
|
||||
func (self *GuestBatchCreateTask) OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string) {
|
||||
self.SSchedTask.OnScheduleFailCallback(ctx, obj, reason)
|
||||
guest := obj.(*models.SGuest)
|
||||
if guest.DisableDelete.IsTrue() {
|
||||
guest.SetDisableDelete(false)
|
||||
@@ -38,18 +39,12 @@ func (self *GuestBatchCreateTask) SaveScheduleResultWithBackup(ctx context.Conte
|
||||
self.SaveScheduleResult(ctx, obj, master)
|
||||
}
|
||||
|
||||
func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IScheduleModel, hostId string) {
|
||||
var err error
|
||||
guest := obj.(*models.SGuest)
|
||||
func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest *models.SGuest) error {
|
||||
pendingUsage := models.SQuota{}
|
||||
err = self.GetPendingUsage(&pendingUsage)
|
||||
err := self.GetPendingUsage(&pendingUsage)
|
||||
if err != nil {
|
||||
log.Errorf("GetPendingUsage fail %s", err)
|
||||
}
|
||||
if len(guest.HostId) == 0 {
|
||||
guest.OnScheduleToHost(ctx, self.UserCred, hostId)
|
||||
}
|
||||
|
||||
quotaCpuMem := models.SQuota{Cpu: int(guest.VcpuCount), Memory: guest.VmemSize}
|
||||
err = models.QuotaManager.CancelPendingUsage(ctx, self.UserCred, guest.ProjectId, &pendingUsage, "aCpuMem)
|
||||
self.SetPendingUsage(&pendingUsage)
|
||||
@@ -61,10 +56,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS
|
||||
if err != nil {
|
||||
log.Errorf("host.SetGuestCreateNetworkAndDiskParams fail %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_CREATE_FAILED, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
self.Params = params
|
||||
self.SaveParams(params)
|
||||
@@ -76,10 +68,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS
|
||||
if err != nil {
|
||||
log.Errorf("Network failed: %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_NETWORK_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_NETWORK_FAILED, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
guest.GetDriver().PrepareDiskRaidConfig(host, self.Params)
|
||||
@@ -89,10 +78,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS
|
||||
if err != nil {
|
||||
log.Errorf("Disk create failed: %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_DISK_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_DISK_FAILED, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
err = guest.CreateIsolatedDeviceOnHost(ctx, self.UserCred, host, self.Params, &pendingUsage)
|
||||
@@ -101,10 +87,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS
|
||||
if err != nil {
|
||||
log.Errorf("IsolatedDevices create failed: %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_DEVICE_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_DEVICE_FAILED, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
guest.JoinGroups(self.UserCred, self.Params)
|
||||
@@ -114,10 +97,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS
|
||||
if err != nil {
|
||||
log.Errorf("start guest create task fail %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_CREATE_FAILED, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
autoStart := jsonutils.QueryBoolean(self.Params, "auto_start", false)
|
||||
@@ -127,20 +107,33 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS
|
||||
if err != nil {
|
||||
log.Errorf("start guest create task fail %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_CREATE_FAILED, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
err = guest.StartGuestCreateTask(ctx, self.UserCred, self.Params, nil, self.GetId())
|
||||
if err != nil {
|
||||
log.Errorf("start guest create task fail %s", err)
|
||||
guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IScheduleModel, hostId string) {
|
||||
var err error
|
||||
guest := obj.(*models.SGuest)
|
||||
if len(guest.HostId) == 0 {
|
||||
guest.OnScheduleToHost(ctx, self.UserCred, hostId)
|
||||
}
|
||||
|
||||
err = self.allocateGuestOnHost(ctx, guest)
|
||||
if err != nil {
|
||||
db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, obj, logclient.ACT_ALLOCATE, err.Error(), self.GetUserCred(), false)
|
||||
notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_CREATE_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func (self *GuestMigrateTask) OnStartSchedule(obj IScheduleModel) {
|
||||
db.OpsLog.LogEvent(guest, db.ACT_MIGRATING, "", self.UserCred)
|
||||
}
|
||||
|
||||
func (self *GuestMigrateTask) OnScheduleFailCallback(obj IScheduleModel, reason string) {
|
||||
func (self *GuestMigrateTask) OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -38,7 +39,7 @@ type IScheduleTask interface {
|
||||
SetStageFailed(ctx context.Context, reason string)
|
||||
|
||||
OnStartSchedule(obj IScheduleModel)
|
||||
OnScheduleFailCallback(obj IScheduleModel, reason string)
|
||||
OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string)
|
||||
OnScheduleComplete(ctx context.Context, items []db.IStandaloneModel, data *jsonutils.JSONDict)
|
||||
SaveScheduleResult(ctx context.Context, obj IScheduleModel, hostId string)
|
||||
SaveScheduleResultWithBackup(ctx context.Context, obj IScheduleModel, master, slave string)
|
||||
@@ -58,9 +59,10 @@ func (self *SSchedTask) OnStartSchedule(obj IScheduleModel) {
|
||||
obj.SetStatus(self.GetUserCred(), SCHEDULE, "")
|
||||
}
|
||||
|
||||
func (self *SSchedTask) OnScheduleFailCallback(obj IScheduleModel, reason string) {
|
||||
func (self *SSchedTask) OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string) {
|
||||
obj.SetStatus(self.GetUserCred(), SCHEDULE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(obj, db.ACT_ALLOCATE_FAIL, reason, self.GetUserCred())
|
||||
logclient.AddActionLogWithStartable(self, obj, logclient.ACT_ALLOCATE, reason, self.GetUserCred(), false)
|
||||
notifyclient.NotifySystemError(obj.GetId(), obj.GetName(), SCHEDULE_FAILED, reason)
|
||||
}
|
||||
|
||||
@@ -153,7 +155,7 @@ func onObjScheduleFail(
|
||||
if len(msg) > 0 {
|
||||
reason = fmt.Sprintf("%s: %s", reason, msg)
|
||||
}
|
||||
task.OnScheduleFailCallback(obj, reason)
|
||||
task.OnScheduleFailCallback(ctx, obj, reason)
|
||||
}
|
||||
|
||||
func onSchedulerResults(
|
||||
|
||||
@@ -25,6 +25,18 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type ImageShowOptions struct {
|
||||
ID string `help:"image ID"`
|
||||
}
|
||||
shellutils.R(&ImageShowOptions{}, "image-show", "Show image", func(cli *aliyun.SRegion, args *ImageShowOptions) error {
|
||||
img, err := cli.GetImage(args.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(img)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ImageDeleteOptions struct {
|
||||
ID string `help:"ID or Name to delete"`
|
||||
}
|
||||
|
||||
@@ -90,15 +90,12 @@ func (self *SStoragecache) GetIImages() ([]cloudprovider.ICloudImage, error) {
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetIImageById(extId string) (cloudprovider.ICloudImage, error) {
|
||||
parts, _, err := self.region.GetImages(ImageStatusType(""), "", []string{extId}, "", 0, 1)
|
||||
img, err := self.region.GetImage(extId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
parts[0].storageCache = self
|
||||
return &parts[0], nil
|
||||
img.storageCache = self
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetPath() string {
|
||||
|
||||
Reference in New Issue
Block a user