From 2583b4ed8389efce6543ae4ba546422cb5c11f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Fri, 29 Mar 2019 13:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E7=BB=AD=E8=B4=B9=E6=97=B6?= =?UTF-8?q?=E6=9C=AA=E5=88=B7=E6=96=B0=E8=99=9A=E6=8B=9F=E6=9C=BA=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/apis/compute/guest_const.go | 2 ++ pkg/cloudcommon/db/opslog.go | 1 + pkg/compute/models/guest_actions.go | 1 + pkg/compute/models/guests.go | 2 ++ pkg/compute/tasks/guest_renew_task.go | 7 +++++++ pkg/util/logclient/logclient.go | 1 + 6 files changed, 14 insertions(+) diff --git a/pkg/apis/compute/guest_const.go b/pkg/apis/compute/guest_const.go index c1e4497eb0..dd6774e584 100644 --- a/pkg/apis/compute/guest_const.go +++ b/pkg/apis/compute/guest_const.go @@ -36,6 +36,8 @@ const ( VM_START_STOP = "start_stop" VM_STOPPING = "stopping" VM_STOP_FAILED = "stop_fail" // # = running + VM_RENEWING = "renewing" + VM_RENEW_FAILED = "renew_failed" VM_BACKUP_STARTING = "backup_starting" VM_BACKUP_CREATING = "backup_creating" diff --git a/pkg/cloudcommon/db/opslog.go b/pkg/cloudcommon/db/opslog.go index 4a81cfa97e..3a3907f0c6 100644 --- a/pkg/cloudcommon/db/opslog.go +++ b/pkg/cloudcommon/db/opslog.go @@ -99,6 +99,7 @@ const ( ACT_BACKUP_ALLOCATE = "backup_allocate" ACT_ALLOCATE_FAIL = "alloc_fail" ACT_BACKUP_ALLOCATE_FAIL = "backup_alloc_fail" + ACT_REW_FAIL = "renew_fail" ACT_DELOCATING = "delocating" ACT_DELOCATE = "delocate" diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 8d7e7156b8..948ace9b50 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -2711,6 +2711,7 @@ func (self *SGuest) PerformRenew(ctx context.Context, userCred mcclient.TokenCre } func (self *SGuest) startGuestRenewTask(ctx context.Context, userCred mcclient.TokenCredential, duration string, parentTaskId string) error { + self.SetStatus(userCred, VM_RENEWING, "") data := jsonutils.NewDict() data.Add(jsonutils.NewString(duration), "duration") task, err := taskman.TaskManager.NewTask(ctx, "GuestRenewTask", self, userCred, data, parentTaskId, "", nil) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 06142f36e7..0ea01d9e7e 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -77,6 +77,8 @@ const ( VM_START_STOP = api.VM_START_STOP VM_STOPPING = api.VM_STOPPING VM_STOP_FAILED = api.VM_STOP_FAILED // # = running + VM_RENEWING = api.VM_RENEWING + VM_RENEW_FAILED = api.VM_RENEW_FAILED VM_BACKUP_STARTING = api.VM_BACKUP_STARTING VM_BACKUP_CREATING = api.VM_BACKUP_CREATING diff --git a/pkg/compute/tasks/guest_renew_task.go b/pkg/compute/tasks/guest_renew_task.go index 6f4ed25dfa..ea2d246fff 100644 --- a/pkg/compute/tasks/guest_renew_task.go +++ b/pkg/compute/tasks/guest_renew_task.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" + "yunion.io/x/onecloud/pkg/util/logclient" ) type GuestRenewTask struct { @@ -46,6 +47,9 @@ func (self *GuestRenewTask) OnInit(ctx context.Context, obj db.IStandaloneModel, if err != nil { msg := fmt.Sprintf("RequestRenewInstance failed %s", err) log.Errorf(msg) + db.OpsLog.LogEvent(guest, db.ACT_REW_FAIL, msg, self.UserCred) + logclient.AddActionLogWithStartable(self, guest, logclient.ACT_RENEW, msg, self.UserCred, false) + guest.SetStatus(self.GetUserCred(), models.VM_RENEW_FAILED, msg) self.SetStageFailed(ctx, msg) return } @@ -58,6 +62,9 @@ func (self *GuestRenewTask) OnInit(ctx context.Context, obj db.IStandaloneModel, return } + logclient.AddActionLogWithStartable(self, guest, logclient.ACT_RENEW, nil, self.UserCred, true) + + guest.StartSyncstatus(ctx, self.UserCred, "") self.SetStageComplete(ctx, nil) } diff --git a/pkg/util/logclient/logclient.go b/pkg/util/logclient/logclient.go index b5025a727d..8b48542404 100644 --- a/pkg/util/logclient/logclient.go +++ b/pkg/util/logclient/logclient.go @@ -103,6 +103,7 @@ const ( ACT_SYNC_CONF = "同步配置" ACT_CREATE_BACKUP = "创建备份机" ACT_SWITCH_TO_BACKUP = "主备切换" + ACT_RENEW = "续费" ACT_IMAGE_SAVE = "上传镜像"