Code review correction

Inverting code path on CreateTcploadBalancer to avoid branch divergence
Removing useless variable vipAddr as vip have information needed
Renaming 'error' variable on  EnsureTCPLoadBalancerDeleted to be consistent
pull/6/head
Sebastien LAWNICZAK 2015-09-15 14:29:51 +02:00
parent be5f9094d0
commit 4c57053d2c
1 changed files with 14 additions and 20 deletions

View File

@ -677,26 +677,20 @@ func (lb *LoadBalancer) CreateTCPLoadBalancer(name, region string, externalIP ne
status := &api.LoadBalancerStatus{} status := &api.LoadBalancerStatus{}
if lb.opts.FloatingNetworkId == "" { status.Ingress = []api.LoadBalancerIngress{{IP: vip.Address}}
status.Ingress = []api.LoadBalancerIngress{{IP: vip.Address}}
return status, nil if lb.opts.FloatingNetworkId != "" {
} floatIPOpts := floatingips.CreateOpts{
FloatingNetworkID: lb.opts.FloatingNetworkId,
PortID: vip.PortID,
}
floatIP, err := floatingips.Create(lb.network, floatIPOpts).Extract()
if err != nil {
return nil, err
}
vipAddr, err := getVipByName(lb.network, name) status.Ingress = append(status.Ingress, api.LoadBalancerIngress{IP: floatIP.FloatingIP})
if err != nil {
return nil, err
} }
floatIPOpts := floatingips.CreateOpts{
FloatingNetworkID: lb.opts.FloatingNetworkId,
PortID: vipAddr.PortID,
}
floatIP, err := floatingips.Create(lb.network, floatIPOpts).Extract()
if err != nil {
return nil, err
}
status.Ingress = []api.LoadBalancerIngress{{IP: vip.Address}, {IP: floatIP.FloatingIP}}
return status, nil return status, nil
@ -777,9 +771,9 @@ func (lb *LoadBalancer) EnsureTCPLoadBalancerDeleted(name, region string) error
return err return err
} }
if floatingIP != nil { if floatingIP != nil {
error := floatingips.Delete(lb.network, floatingIP.ID).ExtractErr() err = floatingips.Delete(lb.network, floatingIP.ID).ExtractErr()
if error != nil && !isNotFound(error) { if err != nil && !isNotFound(err) {
return error return err
} }
} }
} }