mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(cloudcommon): missing set_meta opslog (#9915)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -461,17 +461,17 @@ func (manager *SMetadataManager) SetValue(ctx context.Context, obj IModel, key s
|
||||
}
|
||||
|
||||
func (manager *SMetadataManager) SetValuesWithLog(ctx context.Context, obj IModel, store map[string]interface{}, userCred mcclient.TokenCredential) error {
|
||||
changes, err := manager.SetValues(ctx, obj, store, userCred)
|
||||
changes, err := manager.setValues(ctx, obj, store, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(changes) > 0 {
|
||||
OpsLog.LogEvent(obj, ACT_SET_METADATA, jsonutils.Marshal(changes), userCred)
|
||||
OpsLog.LogEvent(obj.GetIModel(), ACT_SET_METADATA, jsonutils.Marshal(changes), userCred)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SMetadataManager) SetValues(ctx context.Context, obj IModel, store map[string]interface{}, userCred mcclient.TokenCredential) ([]sMetadataChange, error) {
|
||||
func (manager *SMetadataManager) setValues(ctx context.Context, obj IModel, store map[string]interface{}, userCred mcclient.TokenCredential) ([]sMetadataChange, error) {
|
||||
idStr := GetObjectIdstr(obj)
|
||||
|
||||
// no need to lock
|
||||
@@ -548,9 +548,9 @@ func (manager *SMetadataManager) SetValues(ctx context.Context, obj IModel, stor
|
||||
}
|
||||
|
||||
func (manager *SMetadataManager) SetAll(ctx context.Context, obj IModel, store map[string]interface{}, userCred mcclient.TokenCredential, delRange string) error {
|
||||
changes, err := manager.SetValues(ctx, obj, store, userCred)
|
||||
changes, err := manager.setValues(ctx, obj, store, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "setValues")
|
||||
}
|
||||
|
||||
idStr := GetObjectIdstr(obj)
|
||||
@@ -567,11 +567,11 @@ func (manager *SMetadataManager) SetAll(ctx context.Context, obj IModel, store m
|
||||
q := manager.Query().Equals("id", idStr).NotLike("key", `\_\_%`) //避免删除系统内置的metadata, _ 在mysql里面有特殊含义,需要转义
|
||||
switch delRange {
|
||||
case USER_TAG_PREFIX:
|
||||
q = q.Like("key", USER_TAG_PREFIX+"%")
|
||||
q = q.Startswith("key", USER_TAG_PREFIX)
|
||||
case CLOUD_TAG_PREFIX:
|
||||
q = q.Like("key", CLOUD_TAG_PREFIX+"%")
|
||||
q = q.Startswith("key", CLOUD_TAG_PREFIX)
|
||||
case SYS_CLOUD_TAG_PREFIX:
|
||||
q = q.Like("key", SYS_CLOUD_TAG_PREFIX+"%")
|
||||
q = q.Startswith("key", SYS_CLOUD_TAG_PREFIX)
|
||||
}
|
||||
q = q.Filter(sqlchemy.NOT(sqlchemy.In(q.Field("key"), keys)))
|
||||
if err := FetchModelObjects(manager, q, &records); err != nil {
|
||||
@@ -585,7 +585,7 @@ func (manager *SMetadataManager) SetAll(ctx context.Context, obj IModel, store m
|
||||
changes = append(changes, sMetadataChange{Key: rec.Key, OValue: rec.Value})
|
||||
}
|
||||
if len(changes) > 0 {
|
||||
OpsLog.LogEvent(obj, ACT_SET_METADATA, jsonutils.Marshal(changes), userCred)
|
||||
OpsLog.LogEvent(obj.GetIModel(), ACT_SET_METADATA, jsonutils.Marshal(changes), userCred)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,7 +126,8 @@ func (manager *SOpsLogManager) LogEvent(model IModel, action string, notes inter
|
||||
if !consts.OpsLogEnabled() {
|
||||
return
|
||||
}
|
||||
if len(model.GetId()) == 0 || len(model.GetName()) == 0 {
|
||||
if len(model.GetId()) == 0 {
|
||||
log.Errorf("logevent for an object without ID???")
|
||||
return
|
||||
}
|
||||
if action == ACT_UPDATE {
|
||||
|
||||
Reference in New Issue
Block a user