mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
补充同步lb network
This commit is contained in:
@@ -352,21 +352,40 @@ func (man *SLoadbalancerManager) newFromCloudLoadbalancer(ctx context.Context, u
|
||||
log.Errorf("newFromCloudRegion fail %s", err)
|
||||
return nil, err
|
||||
}
|
||||
lb.syncLoadbalancerNetwork(ctx, userCred)
|
||||
return &lb, nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) syncLoadbalancerNetwork(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(lb.NetworkId) > 0 {
|
||||
lbNetReq := &SLoadbalancerNetworkRequestData{
|
||||
loadbalancer: lb,
|
||||
networkId: lb.NetworkId,
|
||||
address: lb.Address,
|
||||
}
|
||||
_, err := LoadbalancernetworkManager.NewLoadbalancerNetwork(ctx, userCred, lbNetReq)
|
||||
if err != nil {
|
||||
log.Errorf("failed to create loadbalancer network: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) SyncWithCloudLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, extLb cloudprovider.ICloudLoadbalancer, projectId string, projectSync bool) error {
|
||||
_, err := lb.GetModelManager().TableSpec().Update(lb, func() error {
|
||||
lb.Address = extLb.GetAddress()
|
||||
lb.Status = extLb.GetStatus()
|
||||
lb.Name = extLb.GetName()
|
||||
|
||||
if networkId := extLb.GetNetworkId(); len(networkId) > 0 {
|
||||
if network, err := NetworkManager.FetchByExternalId(networkId); err == nil && network != nil {
|
||||
lb.NetworkId = network.GetId()
|
||||
}
|
||||
}
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lb.ProjectId = projectId
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
lb.syncLoadbalancerNetwork(ctx, userCred)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func (lb *SLoadbalancer) GetNetworkType() string {
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetNetworkId() string {
|
||||
return ""
|
||||
return lb.VSwitchId
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetZoneId() string {
|
||||
|
||||
Reference in New Issue
Block a user