make sure the interfaces is cleared on error

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
This commit is contained in:
Shijiang Wei 2015-07-29 20:15:02 +08:00
parent 3b55f33ec8
commit d6685f61a7

View file

@ -596,21 +596,18 @@ func (d *driver) CreateNetwork(id types.UUID, option map[string]interface{}) err
// networks. This step is needed now because driver might have now set the bridge // networks. This step is needed now because driver might have now set the bridge
// name on this config struct. And because we need to check for possible address // name on this config struct. And because we need to check for possible address
// conflicts, so we need to check against operationa lnetworks. // conflicts, so we need to check against operationa lnetworks.
if err := config.conflictsWithNetworks(id, networkList); err != nil { if err = config.conflictsWithNetworks(id, networkList); err != nil {
return err return err
} }
setupNetworkIsolationRules := func(config *networkConfiguration, i *bridgeInterface) error { setupNetworkIsolationRules := func(config *networkConfiguration, i *bridgeInterface) error {
defer func() { if err := network.isolateNetwork(networkList, true); err != nil {
if err != nil { if err := network.isolateNetwork(networkList, false); err != nil {
if err := network.isolateNetwork(networkList, false); err != nil { logrus.Warnf("Failed on removing the inter-network iptables rules on cleanup: %v", err)
logrus.Warnf("Failed on removing the inter-network iptables rules on cleanup: %v", err)
}
} }
}() return err
}
err := network.isolateNetwork(networkList, true) return nil
return err
} }
// Prepare the bridge setup configuration // Prepare the bridge setup configuration
@ -955,7 +952,7 @@ func (d *driver) CreateEndpoint(nid, eid types.UUID, epInfo driverapi.EndpointIn
ipv4Addr := &net.IPNet{IP: ip4, Mask: n.bridge.bridgeIPv4.Mask} ipv4Addr := &net.IPNet{IP: ip4, Mask: n.bridge.bridgeIPv4.Mask}
// Down the interface before configuring mac address. // Down the interface before configuring mac address.
if err := netlink.LinkSetDown(sbox); err != nil { if err = netlink.LinkSetDown(sbox); err != nil {
return fmt.Errorf("could not set link down for container interface %s: %v", containerIfName, err) return fmt.Errorf("could not set link down for container interface %s: %v", containerIfName, err)
} }
@ -968,7 +965,7 @@ func (d *driver) CreateEndpoint(nid, eid types.UUID, epInfo driverapi.EndpointIn
endpoint.macAddress = mac endpoint.macAddress = mac
// Up the host interface after finishing all netlink configuration // Up the host interface after finishing all netlink configuration
if err := netlink.LinkSetUp(host); err != nil { if err = netlink.LinkSetUp(host); err != nil {
return fmt.Errorf("could not set link up for host interface %s: %v", hostIfName, err) return fmt.Errorf("could not set link up for host interface %s: %v", hostIfName, err)
} }