mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): sync public ip convert eip (#20325)
This commit is contained in:
@@ -761,8 +761,6 @@ func getStorageTypes(
|
||||
|
||||
info := []StorageInfo{}
|
||||
|
||||
q.DebugQuery()
|
||||
|
||||
err := q.All(&info)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "q.All")
|
||||
|
||||
@@ -441,7 +441,26 @@ func (manager *SElasticipManager) SyncEips(
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
_, err := manager.newFromCloudEip(ctx, userCred, added[i], provider, region, syncOwnerId)
|
||||
eip := &SElasticip{}
|
||||
eip.SetModelManager(ElasticipManager, eip)
|
||||
err := ElasticipManager.Query().
|
||||
Equals("ip_addr", added[i].GetIpAddr()).
|
||||
Equals("manager_id", provider.Id).
|
||||
Equals("cloudregion_id", region.Id).
|
||||
Equals("mode", api.EIP_MODE_INSTANCE_PUBLICIP).First(eip)
|
||||
|
||||
// 公网IP转弹性IP
|
||||
if err == nil {
|
||||
err = eip.SyncWithCloudEip(ctx, userCred, provider, added[i], syncOwnerId)
|
||||
if err != nil {
|
||||
syncResult.UpdateError(err)
|
||||
continue
|
||||
}
|
||||
syncResult.Update()
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = manager.newFromCloudEip(ctx, userCred, added[i], provider, region, syncOwnerId)
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
} else {
|
||||
|
||||
@@ -5957,75 +5957,76 @@ func (self *SGuest) GetPublicIp() (*SElasticip, error) {
|
||||
func (self *SGuest) SyncVMEip(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extEip cloudprovider.ICloudEIP, syncOwnerId mcclient.IIdentityProvider) compare.SyncResult {
|
||||
result := compare.SyncResult{}
|
||||
|
||||
eip, err := self.GetPublicIp()
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getPublicIp error %s", err))
|
||||
result.Error(fmt.Errorf("GetEipOrPublicIp error %s", err))
|
||||
return result
|
||||
} else if eip == nil {
|
||||
eip, err = self.GetElasticIp()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getEip error %s", err))
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
region, _ := self.getRegion()
|
||||
region, err := self.getRegion()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getRegion error %s", err))
|
||||
return result
|
||||
}
|
||||
if eip == nil && extEip == nil {
|
||||
// do nothing
|
||||
} else if eip == nil && extEip != nil {
|
||||
return result
|
||||
}
|
||||
if eip == nil && extEip != nil {
|
||||
// add
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, syncOwnerId)
|
||||
if err != nil {
|
||||
result.AddError(errors.Wrapf(err, "getEipByExtEip"))
|
||||
} else {
|
||||
err = neip.AssociateInstance(ctx, userCred, api.EIP_ASSOCIATE_TYPE_SERVER, self)
|
||||
if err != nil {
|
||||
result.AddError(errors.Wrapf(err, "neip.AssociateInstance"))
|
||||
} else {
|
||||
result.Add()
|
||||
}
|
||||
return result
|
||||
}
|
||||
} else if eip != nil && extEip == nil {
|
||||
err = neip.AssociateInstance(ctx, userCred, api.EIP_ASSOCIATE_TYPE_SERVER, self)
|
||||
if err != nil {
|
||||
result.AddError(errors.Wrapf(err, "neip.AssociateInstance"))
|
||||
return result
|
||||
}
|
||||
result.Add()
|
||||
return result
|
||||
}
|
||||
if eip != nil && extEip == nil {
|
||||
// remove
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
result.DeleteError(err)
|
||||
} else {
|
||||
result.Delete()
|
||||
}
|
||||
} else {
|
||||
// sync
|
||||
if eip.IpAddr != extEip.GetIpAddr() {
|
||||
// remove then add
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
// fail to remove
|
||||
result.DeleteError(err)
|
||||
} else {
|
||||
result.Delete()
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, syncOwnerId)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
err = neip.AssociateInstance(ctx, userCred, api.EIP_ASSOCIATE_TYPE_SERVER, self)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
result.Add()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
err := eip.SyncWithCloudEip(ctx, userCred, provider, extEip, syncOwnerId)
|
||||
if err != nil {
|
||||
result.UpdateError(err)
|
||||
} else {
|
||||
result.Update()
|
||||
}
|
||||
return result
|
||||
}
|
||||
result.Delete()
|
||||
return result
|
||||
}
|
||||
// sync
|
||||
if eip.IpAddr != extEip.GetIpAddr() {
|
||||
// remove then add
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
// fail to remove
|
||||
result.DeleteError(err)
|
||||
return result
|
||||
}
|
||||
result.Delete()
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, syncOwnerId)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
return result
|
||||
}
|
||||
err = neip.AssociateInstance(ctx, userCred, api.EIP_ASSOCIATE_TYPE_SERVER, self)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
result.Add()
|
||||
}
|
||||
return result
|
||||
}
|
||||
// do nothing
|
||||
err = eip.SyncWithCloudEip(ctx, userCred, provider, extEip, syncOwnerId)
|
||||
if err != nil {
|
||||
result.UpdateError(err)
|
||||
} else {
|
||||
result.Update()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -249,8 +249,6 @@ func (maanger *SStoragecachedimageManager) fetchRefCount(q *sqlchemy.SQuery) (ma
|
||||
StoragecacheId string `json:"storagecache_id"`
|
||||
}{}
|
||||
|
||||
q.DebugQuery()
|
||||
|
||||
err := q.All(&results)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Query")
|
||||
|
||||
Reference in New Issue
Block a user