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

Method getDevInfo

python/lib/cloudutils/networkConfig.py:138–168  ·  view source on GitHub ↗
(dev)

Source from the content-addressed store, hash-verified

136
137 @staticmethod
138 def getDevInfo(dev):
139 if not networkConfig.isNetworkDev(dev):
140 logging.debug("dev: " + dev + " is not a network device")
141 raise CloudInternalException("dev: " + dev + " is not a network device")
142
143 netmask = None
144 ipAddr = None
145 macAddr = None
146
147 cmd = bash("ifconfig " + dev)
148 if not cmd.isSuccess():
149 logging.debug("Failed to get address from ifconfig")
150 raise CloudInternalException("Failed to get network info by ifconfig %s"%dev)
151
152 for line in cmd.getLines():
153 if line.find("HWaddr") != -1:
154 macAddr = line.split("HWaddr ")[1].strip(" ")
155 elif line.find("inet ") != -1:
156 m = re.search(r"addr:([^\s]+)\s*Bcast:([^\s]+)\s*Mask:([^\s]+)", line)
157 if m is not None:
158 ipAddr = m.group(1).strip()
159 netmask = m.group(3).strip()
160
161 if networkConfig.isBridgePort(dev):
162 type = "brport"
163 elif networkConfig.isBridge(dev) or networkConfig.isOvsBridge(dev):
164 type = "bridge"
165 else:
166 type = "dev"
167
168 return networkConfig.devInfo(macAddr, ipAddr, netmask, None, type, dev)

Callers 2

getDefaultNetworkMethod · 0.80
cfgNetworkMethod · 0.80

Calls 12

bashClass · 0.85
isNetworkDevMethod · 0.80
debugMethod · 0.80
isBridgePortMethod · 0.80
isBridgeMethod · 0.80
isOvsBridgeMethod · 0.80
isSuccessMethod · 0.65
findMethod · 0.65
searchMethod · 0.65
getLinesMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected