mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-29 17:58:36 +08:00
Merge pull request #10400 from ioito/automated-cherry-pick-of-#10399-upstream-release-3.7
Automated cherry pick of #10399: fix: optimzed tag update and sync
This commit is contained in:
@@ -1229,26 +1229,39 @@ func (self *SManagedVirtualizedGuestDriver) RequestRemoteUpdate(ctx context.Cont
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "guest.GetIVM")
|
||||
}
|
||||
oldTags, err := iVM.GetTags()
|
||||
|
||||
err = func() error {
|
||||
oldTags, err := iVM.GetTags()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "iVM.GetTags()")
|
||||
}
|
||||
tags, err := guest.GetAllUserMetadata()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetAllUserMetadata")
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = iVM.SetTags(tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil
|
||||
}
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, err, userCred, false)
|
||||
return errors.Wrap(err, "iVM.SetTags")
|
||||
}
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, userCred, true)
|
||||
// sync back cloud metadata
|
||||
iVM.Refresh()
|
||||
err = models.SyncVirtualResourceMetadata(ctx, userCred, guest, iVM)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "syncVirtualResourceMetadata")
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "iVM.GetTags()")
|
||||
}
|
||||
tags, err := guest.GetAllUserMetadata()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetAllUserMetadata")
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = iVM.SetTags(tags, replaceTags)
|
||||
if err != nil {
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, err, userCred, false)
|
||||
return errors.Wrap(err, "iVM.SetTags")
|
||||
}
|
||||
logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, userCred, true)
|
||||
// sync back cloud metadata
|
||||
iVM.Refresh()
|
||||
err = models.SyncVirtualResourceMetadata(ctx, userCred, guest, iVM)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "syncVirtualResourceMetadata")
|
||||
return err
|
||||
}
|
||||
|
||||
err = iVM.UpdateVM(ctx, guest.Name)
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -42,7 +41,7 @@ func syncMetadata(ctx context.Context, userCred mcclient.TokenCredential, model
|
||||
model.SetSysCloudMetadataAll(ctx, sysStore, userCred)
|
||||
|
||||
tags, err := remote.GetTags()
|
||||
if err == nil || errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
if err == nil {
|
||||
store := make(map[string]interface{}, 0)
|
||||
for key, value := range tags {
|
||||
store[db.CLOUD_TAG_PREFIX+key] = value
|
||||
@@ -71,7 +70,7 @@ func syncVirtualResourceMetadata(ctx context.Context, userCred mcclient.TokenCre
|
||||
model.SetSysCloudMetadataAll(ctx, sysStore, userCred)
|
||||
|
||||
tags, err := remote.GetTags()
|
||||
if err == nil || errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
if err == nil {
|
||||
store := make(map[string]interface{}, 0)
|
||||
for key, value := range tags {
|
||||
store[db.CLOUD_TAG_PREFIX+key] = value
|
||||
|
||||
@@ -332,6 +332,9 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateLoadbalancer(
|
||||
}
|
||||
oldTags, err := iLoadbalancer.GetTags()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "iLoadbalancer.GetTags()")
|
||||
}
|
||||
tags, err := lb.GetAllUserMetadata()
|
||||
@@ -341,6 +344,9 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateLoadbalancer(
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = iLoadbalancer.SetTags(tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil, nil
|
||||
}
|
||||
logclient.AddActionLogWithStartable(task, lb, logclient.ACT_UPDATE_TAGS, err, userCred, false)
|
||||
return nil, errors.Wrap(err, "iLoadbalancer.SetMetadata")
|
||||
}
|
||||
@@ -2509,7 +2515,10 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateDBInstance(ct
|
||||
return nil, errors.Wrap(err, "instance.GetIDBInstance")
|
||||
}
|
||||
oldTags, err := iRds.GetTags()
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotFound {
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "iRds.GetTags()")
|
||||
}
|
||||
tags, err := instance.GetAllUserMetadata()
|
||||
@@ -2519,6 +2528,9 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateDBInstance(ct
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = iRds.SetTags(tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil, nil
|
||||
}
|
||||
logclient.AddActionLogWithStartable(task, instance, logclient.ACT_UPDATE_TAGS, err, userCred, false)
|
||||
return nil, errors.Wrap(err, "iRds.SetTags")
|
||||
}
|
||||
@@ -2907,8 +2919,15 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateElasticcache(
|
||||
}
|
||||
|
||||
iElasticcache, err := iRegion.GetIElasticcacheById(elasticcache.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetIElasticcacheById(%s)", elasticcache.ExternalId)
|
||||
}
|
||||
|
||||
oldTags, err := iElasticcache.GetTags()
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotFound {
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "iElasticcache.GetTags()")
|
||||
}
|
||||
tags, err := elasticcache.GetAllUserMetadata()
|
||||
@@ -2918,6 +2937,10 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateElasticcache(
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = iElasticcache.SetTags(tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
logclient.AddActionLogWithStartable(task, elasticcache, logclient.ACT_UPDATE_TAGS, err, userCred, false)
|
||||
return nil, errors.Wrap(err, "iElasticcache.SetTags")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user