fix: cloud account/provider missing event logs for

delete/enable/disable/change_project
This commit is contained in:
Qiu Jian
2019-04-20 17:05:29 +08:00
parent 8e508b6f31
commit ffbb7e362b
6 changed files with 54 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ import (
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type SEnabledStatusStandaloneResourceBase struct {
@@ -52,6 +53,7 @@ func (self *SEnabledStatusStandaloneResourceBase) PerformEnable(ctx context.Cont
return nil, err
}
OpsLog.LogEvent(self, ACT_ENABLE, "", userCred)
logclient.AddSimpleActionLog(self, logclient.ACT_ENABLE, nil, userCred, true)
}
return nil, nil
}
@@ -71,6 +73,7 @@ func (self *SEnabledStatusStandaloneResourceBase) PerformDisable(ctx context.Con
return nil, err
}
OpsLog.LogEvent(self, ACT_DISABLE, "", userCred)
logclient.AddSimpleActionLog(self, logclient.ACT_DISABLE, nil, userCred, true)
}
return nil, nil
}

View File

@@ -269,6 +269,18 @@ func (model *SVirtualResourceBase) PerformChangeOwner(ctx context.Context, userC
return nil, err
}
OpsLog.SyncOwner(model, former, userCred)
notes := struct {
OldProjectId string
OldProject string
NewProjectId string
NewProject string
}{
OldProjectId: former.Id,
OldProject: former.Name,
NewProjectId: tobj.GetId(),
NewProject: tobj.GetName(),
}
logclient.AddActionLogWithContext(ctx, model, logclient.ACT_CHANGE_OWNER, notes, userCred, true)
return nil, nil
}

View File

@@ -179,6 +179,10 @@ func (self *SCloudaccount) PerformEnable(ctx context.Context, userCred mcclient.
}
func (self *SCloudaccount) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
_, err := self.SEnabledStatusStandaloneResourceBase.PerformDisable(ctx, userCred, query, data)
if err != nil {
return nil, err
}
cloudproviders := self.GetCloudproviders()
for i := 0; i < len(cloudproviders); i++ {
if cloudproviders[i].Enabled {
@@ -194,10 +198,6 @@ func (self *SCloudaccount) PerformDisable(ctx context.Context, userCred mcclient
return nil, err
}
}
_, err := self.SEnabledStatusStandaloneResourceBase.PerformDisable(ctx, userCred, query, data)
if err != nil {
return nil, err
}
return nil, nil
}

View File

@@ -292,7 +292,6 @@ func (self *SCloudprovider) saveProject(userCred mcclient.TokenCredential, proje
return err
}
db.OpsLog.LogEvent(self, db.ACT_UPDATE, diff, userCred)
logclient.AddSimpleActionLog(self, db.ACT_UPDATE, diff, userCred, true)
}
return nil
}
@@ -478,12 +477,24 @@ func (self *SCloudprovider) PerformChangeProject(ctx context.Context, userCred m
return nil, nil
}
notes := struct {
OldProjectId string
NewProjectId string
NewProject string
}{
OldProjectId: self.ProjectId,
NewProjectId: tenant.Id,
NewProject: tenant.Name,
}
err = self.saveProject(userCred, tenant.Id)
if err != nil {
log.Errorf("Update cloudprovider error: %v", err)
return nil, httperrors.NewGeneralError(err)
}
logclient.AddSimpleActionLog(self, logclient.ACT_CHANGE_OWNER, notes, userCred, true)
if self.GetCloudaccount().EnableAutoSync { // no need to sync rightnow, will do it in auto sync
return nil, nil
}
@@ -1029,8 +1040,14 @@ func (self *SCloudprovider) PerformEnable(ctx context.Context, userCred mcclient
}
account := self.GetCloudaccount()
if account != nil {
allEnabled := true
providers := account.GetCloudproviders()
if len(providers) == 1 && !account.Enabled {
for i := range providers {
if !providers[i].Enabled {
allEnabled = false
}
}
if allEnabled && !account.Enabled {
return account.PerformEnable(ctx, userCred, nil, nil)
}
}
@@ -1044,8 +1061,14 @@ func (self *SCloudprovider) PerformDisable(ctx context.Context, userCred mcclien
}
account := self.GetCloudaccount()
if account != nil {
allDisable := true
providers := account.GetCloudproviders()
if len(providers) == 1 && account.Enabled {
for i := range providers {
if providers[i].Enabled {
allDisable = false
}
}
if allDisable && account.Enabled {
return account.PerformDisable(ctx, userCred, nil, nil)
}
}

View File

@@ -9,6 +9,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type CloudAccountDeleteTask struct {
@@ -36,6 +37,7 @@ func (self *CloudAccountDeleteTask) OnInit(ctx context.Context, obj db.IStandalo
for i := range providers {
err := providers[i].StartCloudproviderDeleteTask(ctx, self.UserCred, self.GetTaskId())
if err != nil {
// very unlikely
account.SetStatus(self.UserCred, api.CLOUD_PROVIDER_DELETE_FAILED, err.Error())
self.SetStageFailed(ctx, err.Error())
return
@@ -49,6 +51,8 @@ func (self *CloudAccountDeleteTask) OnAllCloudProviderDeleteComplete(ctx context
account.RealDelete(ctx, self.UserCred)
self.SetStageComplete(ctx, nil)
logclient.AddActionLogWithStartable(self, account, logclient.ACT_DELETE, nil, self.UserCred, true)
}
func (self *CloudAccountDeleteTask) OnAllCloudProviderDeleteCompleteFailed(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
@@ -56,4 +60,6 @@ func (self *CloudAccountDeleteTask) OnAllCloudProviderDeleteCompleteFailed(ctx c
account.SetStatus(self.UserCred, api.CLOUD_PROVIDER_DELETE_FAILED, body.String())
self.SetStageFailed(ctx, body.String())
logclient.AddActionLogWithStartable(self, account, logclient.ACT_DELETE, body, self.UserCred, false)
}

View File

@@ -23,6 +23,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type CloudProviderDeleteTask struct {
@@ -42,10 +43,12 @@ func (self *CloudProviderDeleteTask) OnInit(ctx context.Context, obj db.IStandal
if err != nil {
provider.SetStatus(self.UserCred, api.CLOUD_PROVIDER_DELETE_FAILED, "StartDiskCloudproviderTask")
self.SetStageFailed(ctx, err.Error())
logclient.AddActionLogWithStartable(self, provider, logclient.ACT_DELETE, err.Error(), self.UserCred, false)
return
}
provider.SetStatus(self.UserCred, api.CLOUD_PROVIDER_DELETED, "StartDiskCloudproviderTask")
self.SetStageComplete(ctx, nil)
logclient.AddActionLogWithStartable(self, provider, logclient.ACT_DELETE, nil, self.UserCred, true)
}