MCPcopy Create free account
hub / github.com/apache/cloudstack / addBridge

Method addBridge

python/lib/cloudutils/serviceConfig.py:153–181  ·  view source on GitHub ↗
(self, br, dev)

Source from the content-addressed store, hash-verified

151 raise CloudInternalException("Failed to find the network method from /etc/network/interfaces")
152
153 def addBridge(self, br, dev):
154 bash("ifdown %s"%dev.name)
155 for line in open(self.netCfgFile).readlines():
156 match = re.match("^ *iface %s.*"%dev.name, line)
157 if match is not None:
158 dev.method = self.getNetworkMethod(match.group(0))
159 cfo = configFileOps(self.netCfgFile, self)
160 if self.syscfg.env.bridgeType == "openvswitch":
161 bridgeCfg = "\n".join(("",
162 "iface {device} inet manual",
163 " ovs_type OVSPort",
164 " ovs_bridge {bridge}",
165 "",
166 "auto {bridge}",
167 "allow-ovs {bridge}",
168 "iface {bridge} inet {device_method}",
169 " ovs_type OVSBridge",
170 " ovs_ports {device}",
171 "")).format(bridge=br, device=dev.name, device_method=dev.method)
172 cfo.replace_line("^ *auto %s.*" % dev.name,
173 "allow-{bridge} {device}".format(bridge=br, device=dev.name))
174 elif self.syscfg.env.bridgeType == "native":
175 bridgeCfg = "\niface %s inet manual\n \
176 auto %s\n \
177 iface %s inet %s\n \
178 bridge_ports %s\n"%(dev.name, br, br, dev.method, dev.name)
179 else:
180 raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType)
181 cfo.replace_line("^ *iface %s.*"%dev.name, bridgeCfg)
182
183 def addDev(self, br, dev):
184 logging.debug("Haven't implement yet")

Callers 1

writeToCfgFileMethod · 0.95

Calls 10

getNetworkMethodMethod · 0.95
configFileOpsClass · 0.90
bashClass · 0.85
readlinesMethod · 0.80
formatMethod · 0.80
matchMethod · 0.45
groupMethod · 0.45
joinMethod · 0.45
replace_lineMethod · 0.45

Tested by

no test coverage detected