@@ -64,10 +64,15 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
64
64
// empty parent and --internal are handled the same. Set here to update k/v
65
65
config .Internal = true
66
66
}
67
- err = d .createNetwork (config )
67
+ foundExisting , err : = d .createNetwork (config )
68
68
if err != nil {
69
69
return err
70
70
}
71
+
72
+ if foundExisting {
73
+ return types .InternalMaskableErrorf ("restoring existing network %s" , config .ID )
74
+ }
75
+
71
76
// update persistent db, rollback on fail
72
77
err = d .storeUpdate (config )
73
78
if err != nil {
@@ -80,22 +85,32 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
80
85
}
81
86
82
87
// createNetwork is used by new network callbacks and persistent network cache
83
- func (d * driver ) createNetwork (config * configuration ) error {
88
+ func (d * driver ) createNetwork (config * configuration ) (bool , error ) {
89
+ foundExisting := false
84
90
networkList := d .getNetworks ()
85
91
for _ , nw := range networkList {
86
92
if config .Parent == nw .config .Parent {
87
- return fmt .Errorf ("network %s is already using parent interface %s" ,
88
- getDummyName (stringid .TruncateID (nw .config .ID )), config .Parent )
93
+ if config .ID != nw .config .ID {
94
+ return false , fmt .Errorf ("network %s is already using parent interface %s" ,
95
+ getDummyName (stringid .TruncateID (nw .config .ID )), config .Parent )
96
+ }
97
+ logrus .Debugf ("Create Network for the same ID %s\n " , config .ID )
98
+ foundExisting = true
99
+ break
89
100
}
90
101
}
91
102
if ! parentExists (config .Parent ) {
92
103
// if the --internal flag is set, create a dummy link
93
104
if config .Internal {
94
- err := createDummyLink (config .Parent , getDummyName (stringid .TruncateID (config .ID )))
95
- if err != nil {
96
- return err
105
+ if ! dummyLinkExists (getDummyName (stringid .TruncateID (config .ID ))) {
106
+ err := createDummyLink (config .Parent , getDummyName (stringid .TruncateID (config .ID )))
107
+ if err != nil {
108
+ return false , err
109
+ }
110
+ config .CreatedSlaveLink = true
111
+ } else {
112
+ logrus .Debugf ("Dummy Link %s for Mac Vlan already exists" , getDummyName (stringid .TruncateID (config .ID )))
97
113
}
98
- config .CreatedSlaveLink = true
99
114
// notify the user in logs they have limited communications
100
115
if config .Parent == getDummyName (stringid .TruncateID (config .ID )) {
101
116
logrus .Debugf ("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s" ,
@@ -104,24 +119,33 @@ func (d *driver) createNetwork(config *configuration) error {
104
119
} else {
105
120
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
106
121
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
107
- err := createVlanLink (config .Parent )
108
- if err != nil {
109
- return err
122
+
123
+ if ! vlanLinkExists (config .Parent ) {
124
+ // if the subinterface parent_iface.vlan_id checks do not pass, return err.
125
+ // a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
126
+ err := createVlanLink (config .Parent )
127
+ if err != nil {
128
+ return false , err
129
+ }
130
+ // if driver created the networks slave link, record it for future deletion
131
+ config .CreatedSlaveLink = true
132
+ } else {
133
+ logrus .Debugf ("Parent Sub Interface %s already Exists NetID %s" , config .Parent , config .ID )
110
134
}
111
- // if driver created the networks slave link, record it for future deletion
112
- config .CreatedSlaveLink = true
113
135
}
114
136
}
115
- n := & network {
116
- id : config .ID ,
117
- driver : d ,
118
- endpoints : endpointTable {},
119
- config : config ,
137
+ if ! foundExisting {
138
+ n := & network {
139
+ id : config .ID ,
140
+ driver : d ,
141
+ endpoints : endpointTable {},
142
+ config : config ,
143
+ }
144
+ // add the network
145
+ d .addNetwork (n )
120
146
}
121
- // add the *network
122
- d .addNetwork (n )
123
147
124
- return nil
148
+ return foundExisting , nil
125
149
}
126
150
127
151
// DeleteNetwork deletes the network for the specified driver type
0 commit comments