From 8c33cc9445eb682927f69a63526fd667b61e3f2e Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Fri, 31 Jul 2020 22:17:55 +0800 Subject: [PATCH] fix: sync share mode between vpc and wire --- pkg/compute/models/cloudsync.go | 20 +++++++++++--------- pkg/compute/models/storagecaches.go | 1 + pkg/compute/models/wires.go | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/pkg/compute/models/cloudsync.go b/pkg/compute/models/cloudsync.go index 61af46c6b4..b3de998fdf 100644 --- a/pkg/compute/models/cloudsync.go +++ b/pkg/compute/models/cloudsync.go @@ -1176,15 +1176,17 @@ func syncOnPremiseCloudProviderInfo( } } - log.Debugf("storageCachePairs count %d", len(storageCachePairs)) - for i := range storageCachePairs { - // alway sync on-premise cached images - // if storageCachePairs[i].isNew || syncRange.DeepSync { - result := storageCachePairs[i].syncCloudImages(ctx, userCred) - syncResults.Add(StoragecachedimageManager, result) - msg := result.Result() - log.Infof("syncCloudImages result: %s", msg) - // } + if cloudprovider.IsSupportCompute(driver) { + log.Debugf("storageCachePairs count %d", len(storageCachePairs)) + for i := range storageCachePairs { + // alway sync on-premise cached images + // if storageCachePairs[i].isNew || syncRange.DeepSync { + result := storageCachePairs[i].syncCloudImages(ctx, userCred) + syncResults.Add(StoragecachedimageManager, result) + msg := result.Result() + log.Infof("syncCloudImages result: %s", msg) + // } + } } return nil diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 7fa02981fc..729424236d 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -599,6 +599,7 @@ func (cache *SStoragecache) SyncCloudImages( syncResult := compare.SyncResult{} + log.Debugln("localCachedImages started") localCachedImages := cache.getCachedImages() log.Debugf("localCachedImages %d", len(localCachedImages)) diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index b33d349d78..db40716bb9 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -309,7 +309,7 @@ func (manager *SWireManager) SyncWires(ctx context.Context, userCred mcclient.To } } for i := 0; i < len(commondb); i += 1 { - err = commondb[i].syncWithCloudWire(ctx, userCred, commonext[i], provider) + err = commondb[i].syncWithCloudWire(ctx, userCred, commonext[i], vpc, provider) if err != nil { syncResult.UpdateError(err) } else { @@ -353,13 +353,19 @@ func (self *SWire) syncRemoveCloudWire(ctx context.Context, userCred mcclient.To return err } -func (self *SWire) syncWithCloudWire(ctx context.Context, userCred mcclient.TokenCredential, extWire cloudprovider.ICloudWire, provider *SCloudprovider) error { +func (self *SWire) syncWithCloudWire(ctx context.Context, userCred mcclient.TokenCredential, extWire cloudprovider.ICloudWire, vpc *SVpc, provider *SCloudprovider) error { diff, err := db.UpdateWithLock(ctx, self, func() error { // self.Name = extWire.GetName() self.Bandwidth = extWire.GetBandwidth() // 10G self.IsEmulated = extWire.IsEmulated() + if self.IsEmulated { + self.DomainId = vpc.DomainId + self.IsPublic = vpc.IsPublic + self.PublicScope = vpc.PublicScope + } + return nil }) if err != nil { @@ -409,13 +415,17 @@ func (manager *SWireManager) newFromCloudWire(ctx context.Context, userCred mccl wire.IsEmulated = extWire.IsEmulated() + wire.DomainId = vpc.DomainId + wire.IsPublic = vpc.IsPublic + wire.PublicScope = vpc.PublicScope + err = manager.TableSpec().Insert(&wire) if err != nil { log.Errorf("newFromCloudWire fail %s", err) return nil, err } - if provider != nil { + if provider != nil && !wire.IsEmulated { SyncCloudDomain(userCred, &wire, provider.GetOwnerId()) wire.SyncShareState(ctx, userCred, provider.getAccountShareInfo()) }