mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): avoid set multi resources tags failed
This commit is contained in:
@@ -840,7 +840,7 @@ func DeleteBucketCORS(ibucket ICloudBucket, id []string) ([]SBucketCORSRule, err
|
||||
return deletedRules, nil
|
||||
}
|
||||
|
||||
func SetBucketTags(iBucket ICloudBucket, tags map[string]string) (TagsUpdateInfo, error) {
|
||||
func SetBucketTags(ctx context.Context, iBucket ICloudBucket, mangerId string, tags map[string]string) (TagsUpdateInfo, error) {
|
||||
ret := TagsUpdateInfo{}
|
||||
old, err := iBucket.GetTags()
|
||||
if err != nil {
|
||||
@@ -853,5 +853,5 @@ func SetBucketTags(iBucket ICloudBucket, tags map[string]string) (TagsUpdateInfo
|
||||
if !ret.IsChanged() {
|
||||
return ret, nil
|
||||
}
|
||||
return ret, iBucket.SetTags(tags, true)
|
||||
return ret, SetTags(ctx, iBucket, mangerId, tags, true)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,16 @@
|
||||
|
||||
package cloudprovider
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
)
|
||||
|
||||
const (
|
||||
SET_TAGS = "set-tags"
|
||||
)
|
||||
|
||||
type TagsUpdateInfo struct {
|
||||
OldTags map[string]string
|
||||
@@ -24,3 +33,12 @@ type TagsUpdateInfo struct {
|
||||
func (t TagsUpdateInfo) IsChanged() bool {
|
||||
return !reflect.DeepEqual(t.OldTags, t.NewTags)
|
||||
}
|
||||
|
||||
func SetTags(ctx context.Context, res ICloudResource, managerId string, tags map[string]string, replace bool) error {
|
||||
// 避免同时设置多个资源标签出现以下错误
|
||||
// Code=ResourceInUse.TagDuplicate, Message=tagKey-tagValue have exists., RequestId=e87714c0-e50b-4241-b79d-32897437174d
|
||||
lockman.LockRawObject(ctx, SET_TAGS, managerId)
|
||||
defer lockman.ReleaseRawObject(ctx, SET_TAGS, managerId)
|
||||
|
||||
return res.SetTags(tags, replace)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user