@@ -94,8 +94,10 @@ def isPreConfiged(self):
9494 if not self .netcfg .isNetworkDev (br ):
9595 logging .debug ("%s is not a network device, is it down?" % br )
9696 return False
97- if not self .netcfg .isBridge (br ):
98- raise CloudInternalException ("%s is not a bridge" % br )
97+ if self .syscfg .env .bridgeType == "openvswitch" and not self .netcfg .isOvsBridge (br ):
98+ raise CloudInternalException ("%s is not an openvswitch bridge" % br )
99+ if self .syscfg .env .bridgeType == "native" and not self .netcfg .isBridge (br ):
100+ raise CloudInternalException ("%s is not a bridge" % br )
99101 preCfged = True
100102
101103 return preCfged
@@ -153,11 +155,28 @@ def addBridge(self, br, dev):
153155 match = re .match ("^ *iface %s.*" % dev .name , line )
154156 if match is not None :
155157 dev .method = self .getNetworkMethod (match .group (0 ))
156- bridgeCfg = "\n iface %s inet manual\n \
157- auto %s\n \
158- iface %s inet %s\n \
159- bridge_ports %s\n "% (dev .name , br , br , dev .method , dev .name )
160158 cfo = configFileOps (self .netCfgFile , self )
159+ if self .syscfg .env .bridgeType == "openvswitch" :
160+ bridgeCfg = "\n " .join (("" ,
161+ "iface {device} inet manual" ,
162+ " ovs_type OVSPort" ,
163+ " ovs_bridge {bridge}" ,
164+ "" ,
165+ "auto {bridge}" ,
166+ "allow-ovs {bridge}" ,
167+ "iface {bridge} inet {device_method}" ,
168+ " ovs_type OVSBridge" ,
169+ " ovs_ports {device}" ,
170+ "" )).format (bridge = br , device = dev .name , device_method = dev .method )
171+ cfo .replace_line ("^ *auto %s.*" % dev .name ,
172+ "allow-{bridge} {device}" .format (bridge = br , device = dev .name ))
173+ elif self .syscfg .env .bridgeType == "native" :
174+ bridgeCfg = "\n iface %s inet manual\n \
175+ auto %s\n \
176+ iface %s inet %s\n \
177+ bridge_ports %s\n "% (dev .name , br , br , dev .method , dev .name )
178+ else :
179+ raise CloudInternalException ("Unknown network.bridge.type %s" % self .syscfg .env .bridgeType )
161180 cfo .replace_line ("^ *iface %s.*" % dev .name , bridgeCfg )
162181
163182 def addDev (self , br , dev ):
@@ -193,8 +212,9 @@ def config(self):
193212 self .syscfg .svo .stopService ("network-manager" )
194213 self .syscfg .svo .disableService ("network-manager" )
195214
196- if not bash ("ifup %s" % self .brName ).isSuccess ():
197- raise CloudInternalException ("Can't start network:%s" % self .brName , bash .getErrMsg (self ))
215+ ifup_op = bash ("ifup %s" % self .brName )
216+ if not ifup_op .isSuccess ():
217+ raise CloudInternalException ("Can't start network:%s %s" % (self .brName , ifup_op .getErrMsg ()))
198218
199219 self .syscfg .env .nics .append (self .brName )
200220 self .syscfg .env .nics .append (self .brName )
@@ -222,8 +242,8 @@ def __init__(self, syscfg):
222242 networkConfigBase .__init__ (self , syscfg )
223243
224244 def writeToCfgFile (self , brName , dev ):
225- self .devCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % dev .name
226- self .brCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % brName
245+ self .devCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % dev .name
246+ self .brCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % brName
227247
228248 isDevExist = os .path .exists (self .devCfgFile )
229249 isBrExist = os .path .exists (self .brCfgFile )
@@ -241,7 +261,7 @@ def writeToCfgFile(self, brName, dev):
241261
242262
243263 def addBridge (self , brName , dev ):
244- bash ("ifdown %s" % dev .name )
264+ bash ("ifdown %s" % dev .name )
245265
246266 if not os .path .exists (self .brCfgFile ):
247267 shutil .copy (self .devCfgFile , self .brCfgFile )
@@ -250,14 +270,34 @@ def addBridge(self, brName, dev):
250270 cfo = configFileOps (self .devCfgFile , self )
251271 cfo .addEntry ("NM_CONTROLLED" , "no" )
252272 cfo .addEntry ("ONBOOT" , "yes" )
253- cfo .addEntry ("BRIDGE" , brName )
273+ if self .syscfg .env .bridgeType == "openvswitch" :
274+ if cfo .getEntry ("IPADDR" ):
275+ cfo .rmEntry ("IPADDR" , cfo .getEntry ("IPADDR" ))
276+ cfo .addEntry ("DEVICETYPE" , "ovs" )
277+ cfo .addEntry ("TYPE" , "OVSPort" )
278+ cfo .addEntry ("OVS_BRIDGE" , brName )
279+ elif self .syscfg .env .bridgeType == "native" :
280+ cfo .addEntry ("BRIDGE" , brName )
281+ else :
282+ raise CloudInternalException ("Unknown network.bridge.type %s" % self .syscfg .env .bridgeType )
254283 cfo .save ()
255284
256285 cfo = configFileOps (self .brCfgFile , self )
257286 cfo .addEntry ("NM_CONTROLLED" , "no" )
258287 cfo .addEntry ("ONBOOT" , "yes" )
259288 cfo .addEntry ("DEVICE" , brName )
260- cfo .addEntry ("TYPE" , "Bridge" )
289+ if self .syscfg .env .bridgeType == "openvswitch" :
290+ if cfo .getEntry ("HWADDR" ):
291+ cfo .rmEntry ("HWADDR" , cfo .getEntry ("HWADDR" ))
292+ if cfo .getEntry ("UUID" ):
293+ cfo .rmEntry ("UUID" , cfo .getEntry ("UUID" ))
294+ cfo .addEntry ("STP" , "yes" )
295+ cfo .addEntry ("DEVICETYPE" , "ovs" )
296+ cfo .addEntry ("TYPE" , "OVSBridge" )
297+ elif self .syscfg .env .bridgeType == "native" :
298+ cfo .addEntry ("TYPE" , "Bridge" )
299+ else :
300+ raise CloudInternalException ("Unknown network.bridge.type %s" % self .syscfg .env .bridgeType )
261301 cfo .save ()
262302
263303 def config (self ):
0 commit comments