|
@@ -60,10 +60,14 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
|
|
// empty parent and --internal are handled the same. Set here to update k/v
|
|
// empty parent and --internal are handled the same. Set here to update k/v
|
|
config.Internal = true
|
|
config.Internal = true
|
|
}
|
|
}
|
|
- err = d.createNetwork(config)
|
|
|
|
|
|
+ foundExisting, err := d.createNetwork(config)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if foundExisting {
|
|
|
|
+ return types.InternalMaskableErrorf("restoring existing network %s", config.ID)
|
|
|
|
+ }
|
|
// update persistent db, rollback on fail
|
|
// update persistent db, rollback on fail
|
|
err = d.storeUpdate(config)
|
|
err = d.storeUpdate(config)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -76,12 +80,18 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
|
|
}
|
|
}
|
|
|
|
|
|
// createNetwork is used by new network callbacks and persistent network cache
|
|
// createNetwork is used by new network callbacks and persistent network cache
|
|
-func (d *driver) createNetwork(config *configuration) error {
|
|
|
|
|
|
+func (d *driver) createNetwork(config *configuration) (bool, error) {
|
|
|
|
+ foundExisting := false
|
|
networkList := d.getNetworks()
|
|
networkList := d.getNetworks()
|
|
for _, nw := range networkList {
|
|
for _, nw := range networkList {
|
|
if config.Parent == nw.config.Parent {
|
|
if config.Parent == nw.config.Parent {
|
|
- return fmt.Errorf("network %s is already using parent interface %s",
|
|
|
|
- getDummyName(stringid.TruncateID(nw.config.ID)), config.Parent)
|
|
|
|
|
|
+ if config.ID != nw.config.ID {
|
|
|
|
+ return false, fmt.Errorf("network %s is already using parent interface %s",
|
|
|
|
+ getDummyName(stringid.TruncateID(nw.config.ID)), config.Parent)
|
|
|
|
+ }
|
|
|
|
+ logrus.Debugf("Create Network for the same ID %s\n", config.ID)
|
|
|
|
+ foundExisting = true
|
|
|
|
+ break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !parentExists(config.Parent) {
|
|
if !parentExists(config.Parent) {
|
|
@@ -89,9 +99,10 @@ func (d *driver) createNetwork(config *configuration) error {
|
|
if config.Internal {
|
|
if config.Internal {
|
|
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
|
|
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return false, err
|
|
}
|
|
}
|
|
config.CreatedSlaveLink = true
|
|
config.CreatedSlaveLink = true
|
|
|
|
+
|
|
// notify the user in logs they have limited communications
|
|
// notify the user in logs they have limited communications
|
|
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
|
|
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
|
|
logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s",
|
|
logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s",
|
|
@@ -102,22 +113,24 @@ func (d *driver) createNetwork(config *configuration) error {
|
|
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
|
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
|
err := createVlanLink(config.Parent)
|
|
err := createVlanLink(config.Parent)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return false, err
|
|
}
|
|
}
|
|
// if driver created the networks slave link, record it for future deletion
|
|
// if driver created the networks slave link, record it for future deletion
|
|
config.CreatedSlaveLink = true
|
|
config.CreatedSlaveLink = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- n := &network{
|
|
|
|
- id: config.ID,
|
|
|
|
- driver: d,
|
|
|
|
- endpoints: endpointTable{},
|
|
|
|
- config: config,
|
|
|
|
|
|
+ if !foundExisting {
|
|
|
|
+ n := &network{
|
|
|
|
+ id: config.ID,
|
|
|
|
+ driver: d,
|
|
|
|
+ endpoints: endpointTable{},
|
|
|
|
+ config: config,
|
|
|
|
+ }
|
|
|
|
+ // add the network
|
|
|
|
+ d.addNetwork(n)
|
|
}
|
|
}
|
|
- // add the *network
|
|
|
|
- d.addNetwork(n)
|
|
|
|
|
|
|
|
- return nil
|
|
|
|
|
|
+ return foundExisting, nil
|
|
}
|
|
}
|
|
|
|
|
|
// DeleteNetwork the network for the specified driver type
|
|
// DeleteNetwork the network for the specified driver type
|