diff --git a/cmd/climc/shell/notification.go b/cmd/climc/shell/notification.go index 03c3f7a4fb..5322cf969a 100644 --- a/cmd/climc/shell/notification.go +++ b/cmd/climc/shell/notification.go @@ -22,7 +22,6 @@ func init() { MSG string `help:"The content of the notification"` Remark string `help:"Remark or description of the notification"` Group bool `help:"Send to group"` - Channel string `help:"User's contacts type, cloud be email|mobile|dingtalk|webconsole" choices:"email|mobile|dingtalk|webconsole"` } R(&NotificationCreateOptions{}, "notify", "Send a notification to sb", func(s *mcclient.ClientSession, args *NotificationCreateOptions) error { msg := notify.SNotifyMessage{} @@ -32,10 +31,7 @@ func init() { msg.Uid = args.UID } - msg.ContactType = []notify.TNotifyChannel{notify.TNotifyChannel(args.CONTACTTYPE)} - for _, c := range args.Channel { - msg.ContactType = append(msg.ContactType, notify.TNotifyChannel(c)) - } + msg.ContactType = notify.TNotifyChannel(args.CONTACTTYPE) msg.Topic = args.TOPIC msg.Priority = notify.TNotifyPriority(args.PRIORITY) msg.Msg = args.MSG diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index bca0c4255f..15af820b6e 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -348,16 +348,34 @@ func (self *SImage) GetPath(format string) string { } func (self *SImage) OnSaveFailed(ctx context.Context, userCred mcclient.TokenCredential, msg string) { - log.Errorf(msg) - self.SetStatus(userCred, IMAGE_STATUS_QUEUED, msg) - db.OpsLog.LogEvent(self, db.ACT_SAVE_FAIL, msg, userCred) - logclient.AddActionLog(self, logclient.ACT_IMAGE_SAVE, nil, userCred, false) + self.saveFailed(userCred, msg) + logclient.AddActionLogWithContext(ctx, self, logclient.ACT_IMAGE_SAVE, nil, userCred, false) +} + +func (self *SImage) OnSaveTaskFailed(task taskman.ITask, userCred mcclient.TokenCredential, msg string) { + self.saveFailed(userCred, msg) + logclient.AddActionLogWithStartable(task, self, logclient.ACT_IMAGE_SAVE, nil, userCred, false) } func (self *SImage) OnSaveSuccess(ctx context.Context, userCred mcclient.TokenCredential, msg string) { + self.saveSuccess(userCred, msg) + logclient.AddActionLogWithContext(ctx, self, logclient.ACT_IMAGE_SAVE, nil, userCred, true) +} + +func (self *SImage) OnSaveTaskSuccess(task taskman.ITask, userCred mcclient.TokenCredential, msg string) { + self.saveSuccess(userCred, msg) + logclient.AddActionLogWithStartable(task, self, logclient.ACT_IMAGE_SAVE, nil, userCred, true) +} + +func (self *SImage) saveSuccess(userCred mcclient.TokenCredential, msg string) { self.SetStatus(userCred, IMAGE_STATUS_ACTIVE, msg) db.OpsLog.LogEvent(self, db.ACT_SAVE, msg, userCred) - logclient.AddActionLog(self, logclient.ACT_IMAGE_SAVE, nil, userCred, true) +} + +func (self *SImage) saveFailed(userCred mcclient.TokenCredential, msg string) { + log.Errorf(msg) + self.SetStatus(userCred, IMAGE_STATUS_QUEUED, msg) + db.OpsLog.LogEvent(self, db.ACT_SAVE_FAIL, msg, userCred) } func (self *SImage) saveImageFromStream(localPath string, reader io.Reader) (*streamutils.SStreamProperty, error) { diff --git a/pkg/image/tasks/image_copy_from_url_task.go b/pkg/image/tasks/image_copy_from_url_task.go index 2960d1daa4..c53fa43d4b 100644 --- a/pkg/image/tasks/image_copy_from_url_task.go +++ b/pkg/image/tasks/image_copy_from_url_task.go @@ -46,6 +46,7 @@ func (self *ImageCopyFromUrlTask) OnInit(ctx context.Context, obj db.IStandalone func (self *ImageCopyFromUrlTask) OnImageImportComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { image := obj.(*models.SImage) + image.OnSaveTaskSuccess(self, self.UserCred, "create upload success") image.StartImageConvertTask(ctx, self.UserCred, "") self.SetStageComplete(ctx, nil) } @@ -54,6 +55,6 @@ func (self *ImageCopyFromUrlTask) OnImageImportCompleteFailed(ctx context.Contex image := obj.(*models.SImage) copyFrom, _ := self.Params.GetString("copy_from") msg := fmt.Sprintf("copy from url %s request fail %s", copyFrom, err) - image.OnSaveFailed(ctx, self.UserCred, msg) + image.OnSaveTaskFailed(self, self.UserCred, msg) self.SetStageFailed(ctx, msg) } diff --git a/pkg/util/huawei/shell/instance.go b/pkg/util/huawei/shell/instance.go index 26e814d112..e11bad7abd 100644 --- a/pkg/util/huawei/shell/instance.go +++ b/pkg/util/huawei/shell/instance.go @@ -2,6 +2,7 @@ package shell import ( "context" + "fmt" "yunion.io/x/onecloud/pkg/util/huawei" "yunion.io/x/onecloud/pkg/util/shellutils" @@ -108,11 +109,11 @@ func init() { shellutils.R(&InstanceRebuildRootOptions{}, "instance-rebuild-root", "Reinstall virtual server system image", func(cli *huawei.SRegion, args *InstanceRebuildRootOptions) error { ctx := context.Background() - err := cli.ChangeRoot(ctx, args.ID, args.Image, args.Password, args.PublicKey) + jobId, err := cli.ChangeRoot(ctx, args.ID, args.Image, args.Password, args.PublicKey) if err != nil { return err } - // fmt.Printf("New diskID is %s", diskID) + fmt.Printf("ChangeRoot jobID is %s", jobId) return nil })