mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
1. GetShortDesc()改为GetShortDesc(ctx context.Context)
2. VirtualResource的GetShortDesc()中增加owner_tenant_id和owner_tenant两个字段
This commit is contained in:
@@ -861,7 +861,7 @@ func (dispatcher *DBModelDispatcher) Create(ctx context.Context, query jsonutils
|
||||
log.Errorf("fail to doCreateItem %s", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
OpsLog.LogEvent(model, ACT_CREATE, model.GetShortDesc(), userCred)
|
||||
OpsLog.LogEvent(model, ACT_CREATE, model.GetShortDesc(ctx), userCred)
|
||||
logclient.AddActionLog(model, logclient.ACT_CREATE, "", userCred, true)
|
||||
dispatcher.modelManager.OnCreateComplete(ctx, []IModel{model}, userCred, query, data)
|
||||
return getItemDetails(dispatcher.modelManager, model, ctx, userCred, query)
|
||||
@@ -1210,8 +1210,8 @@ func DeleteModel(ctx context.Context, userCred mcclient.TokenCredential, item IM
|
||||
logclient.AddActionLog(item, logclient.ACT_DELETE, msg, userCred, false)
|
||||
return httperrors.NewGeneralError(err)
|
||||
}
|
||||
OpsLog.LogEvent(item, ACT_DELETE, item.GetShortDesc(), userCred)
|
||||
logclient.AddActionLog(item, logclient.ACT_DELETE, item.GetShortDesc(), userCred, true)
|
||||
OpsLog.LogEvent(item, ACT_DELETE, item.GetShortDesc(ctx), userCred)
|
||||
logclient.AddActionLog(item, logclient.ACT_DELETE, item.GetShortDesc(ctx), userCred, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1271,7 +1271,7 @@ func (dispatcher *DBModelDispatcher) Delete(ctx context.Context, idstr string, q
|
||||
} else if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
log.Debugf("Delete %s", model.GetShortDesc())
|
||||
// log.Debugf("Delete %s", model.GetShortDesc(ctx))
|
||||
|
||||
lockman.LockObject(ctx, model)
|
||||
defer lockman.ReleaseObject(ctx, model)
|
||||
|
||||
@@ -174,7 +174,7 @@ func attachItems(dispatcher *DBJointModelDispatcher, master IStandaloneModel, sl
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
OpsLog.LogAttachEvent(master, slave, userCred, jsonutils.Marshal(item))
|
||||
OpsLog.LogAttachEvent(ctx, master, slave, userCred, jsonutils.Marshal(item))
|
||||
dispatcher.modelManager.OnCreateComplete(ctx, []IModel{item}, userCred, query, data)
|
||||
return getItemDetails(dispatcher.JointModelManager(), item, ctx, userCred, query)
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (dispatcher *DBJointModelDispatcher) Detach(ctx context.Context, id1 string
|
||||
defer lockman.ReleaseJointObject(ctx, master, slave)
|
||||
obj, err := deleteItem(dispatcher.JointModelManager(), item, ctx, userCred, query, data)
|
||||
if err == nil {
|
||||
OpsLog.LogDetachEvent(item.Master(), item.Slave(), userCred, jsonutils.Marshal(item))
|
||||
OpsLog.LogDetachEvent(ctx, item.Master(), item.Slave(), userCred, jsonutils.Marshal(item))
|
||||
}
|
||||
return obj, err
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func DetachJoint(ctx context.Context, userCred mcclient.TokenCredential, item IJ
|
||||
}
|
||||
err = item.Delete(ctx, userCred)
|
||||
if err == nil {
|
||||
OpsLog.LogDetachEvent(item.Master(), item.Slave(), userCred, item.GetShortDesc())
|
||||
OpsLog.LogDetachEvent(ctx, item.Master(), item.Slave(), userCred, item.GetShortDesc(ctx))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ type IModel interface {
|
||||
GetModelManager() IModelManager
|
||||
SetModelManager(IModelManager)
|
||||
|
||||
GetShortDesc() *jsonutils.JSONDict
|
||||
GetShortDesc(ctx context.Context) *jsonutils.JSONDict
|
||||
|
||||
// list hooks
|
||||
GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict
|
||||
|
||||
@@ -194,7 +194,7 @@ func (model *SModelBase) GetModelManager() IModelManager {
|
||||
return model.manager
|
||||
}
|
||||
|
||||
func (model *SModelBase) GetShortDesc() *jsonutils.JSONDict {
|
||||
func (model *SModelBase) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
desc := jsonutils.NewDict()
|
||||
desc.Add(jsonutils.NewString(model.Keyword()), "res_name")
|
||||
return desc
|
||||
|
||||
@@ -242,8 +242,8 @@ func (manager *SOpsLogManager) LogEvent(model IModel, action string, notes inter
|
||||
}
|
||||
}
|
||||
|
||||
func combineNotes(m2 IModel, notes jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
desc := m2.GetShortDesc()
|
||||
func combineNotes(ctx context.Context, m2 IModel, notes jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
desc := m2.GetShortDesc(ctx)
|
||||
if notes != nil {
|
||||
if notesDict, ok := notes.(*jsonutils.JSONDict); ok {
|
||||
notesMap, _ := notesDict.GetMap()
|
||||
@@ -266,22 +266,22 @@ func combineNotes(m2 IModel, notes jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
return desc
|
||||
}
|
||||
|
||||
func (manager *SOpsLogManager) logOneJointEvent(m1, m2 IModel, event string, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
nn := combineNotes(m2, notes)
|
||||
func (manager *SOpsLogManager) logOneJointEvent(ctx context.Context, m1, m2 IModel, event string, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
nn := combineNotes(ctx, m2, notes)
|
||||
manager.LogEvent(m1, event, nn, userCred)
|
||||
}
|
||||
|
||||
func (manager *SOpsLogManager) logJoinEvent(m1, m2 IModel, event string, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
manager.logOneJointEvent(m1, m2, event, userCred, notes)
|
||||
manager.logOneJointEvent(m2, m1, event, userCred, notes)
|
||||
func (manager *SOpsLogManager) logJoinEvent(ctx context.Context, m1, m2 IModel, event string, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
manager.logOneJointEvent(ctx, m1, m2, event, userCred, notes)
|
||||
manager.logOneJointEvent(ctx, m2, m1, event, userCred, notes)
|
||||
}
|
||||
|
||||
func (manager *SOpsLogManager) LogAttachEvent(m1, m2 IModel, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
manager.logJoinEvent(m1, m2, ACT_ATTACH, userCred, notes)
|
||||
func (manager *SOpsLogManager) LogAttachEvent(ctx context.Context, m1, m2 IModel, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
manager.logJoinEvent(ctx, m1, m2, ACT_ATTACH, userCred, notes)
|
||||
}
|
||||
|
||||
func (manager *SOpsLogManager) LogDetachEvent(m1, m2 IModel, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
manager.logJoinEvent(m1, m2, ACT_DETACH, userCred, notes)
|
||||
func (manager *SOpsLogManager) LogDetachEvent(ctx context.Context, m1, m2 IModel, userCred mcclient.TokenCredential, notes jsonutils.JSONObject) {
|
||||
manager.logJoinEvent(ctx, m1, m2, ACT_DETACH, userCred, notes)
|
||||
}
|
||||
|
||||
func (manager *SOpsLogManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
|
||||
@@ -127,8 +127,8 @@ func (model *SStandaloneResourceBase) GetName() string {
|
||||
return model.Name
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) GetShortDesc() *jsonutils.JSONDict {
|
||||
desc := model.SResourceBase.GetShortDesc()
|
||||
func (model *SStandaloneResourceBase) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
desc := model.SResourceBase.GetShortDesc(ctx)
|
||||
desc.Add(jsonutils.NewString(model.GetName()), "name")
|
||||
desc.Add(jsonutils.NewString(model.GetId()), "id")
|
||||
return desc
|
||||
|
||||
@@ -300,3 +300,13 @@ func (model *SVirtualResourceBase) CancelPendingDelete(ctx context.Context, user
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (model *SVirtualResourceBase) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
desc := model.SStatusStandaloneResourceBase.GetShortDesc(ctx)
|
||||
desc.Add(jsonutils.NewString(model.ProjectId), "owner_tenant_id")
|
||||
tc, _ := TenantCacheManager.FetchTenantById(ctx, model.ProjectId)
|
||||
if tc != nil {
|
||||
desc.Add(jsonutils.NewString(tc.GetName()), "owner_tenant")
|
||||
}
|
||||
return desc
|
||||
}
|
||||
Reference in New Issue
Block a user