summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.server.scripts
diff options
context:
space:
mode:
authorTim <timothyasir@gluster.com>2011-07-28 15:49:27 +0530
committerTim <timothyasir@gluster.com>2011-07-28 15:49:27 +0530
commitace768b5aee1202fb7c0cf6564b9dd8f9a5e00e4 (patch)
treeceaf16c95c7108d98add5e31bd28495000bc3cfa /src/com.gluster.storage.management.server.scripts
parentfeae2588975a7f9f800e194d0e979654e405b024 (diff)
Added function to get ipaddress, netmask and gateway in case of DHCP is used
Diffstat (limited to 'src/com.gluster.storage.management.server.scripts')
-rwxr-xr-xsrc/com.gluster.storage.management.server.scripts/src/NetworkUtils.py42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/com.gluster.storage.management.server.scripts/src/NetworkUtils.py b/src/com.gluster.storage.management.server.scripts/src/NetworkUtils.py
index da212a9b..1463ed72 100755
--- a/src/com.gluster.storage.management.server.scripts/src/NetworkUtils.py
+++ b/src/com.gluster.storage.management.server.scripts/src/NetworkUtils.py
@@ -176,15 +176,34 @@ def writeIfcfgConfFile(deviceName, conf, root="", deviceFile=None):
return False
return True
-
-def getNetModel(deviceName):
+def getNetDeviceDetail(deviceName):
+ deviceDetail = {}
+ deviceDetail['Name'] = deviceName
rv = runCommandFG("ifconfig %s" % deviceName, stdout=True, root=True)
if rv["Status"] != 0:
return False
for line in rv["Stdout"].split():
tokens = line.strip().split(":")
if tokens[0].upper() == "ENCAP":
- return tokens[1].strip().upper()
+ deviceDetail['Model'] = tokens[1].strip().upper()
+ if tokens[0].upper() == "ADDR":
+ deviceDetail['Ip'] = tokens[1].strip()
+ if tokens[0].upper() == "MASK":
+ deviceDetail['Mask'] = tokens[1].strip()
+ return deviceDetail
+
+def getNetDeviceGateway(deviceName):
+ rv = runCommand("route -n", output=True, root=True)
+ if rv["Status"] != 0:
+ return None
+ if not rv["Stdout"]:
+ return None
+ lines = [line for line in rv["Stdout"].split("\n") if line.find("UG") != -1 and line.find(deviceName)]
+ if not lines:
+ return None
+ line = lines[-1].split()
+ if line and len(line) > 1:
+ return line[1]
return None
def getNetSpeed(deviceName):
@@ -272,8 +291,6 @@ def getNetDeviceList(root=""):
netDevice["type"] = None
netDevice["onboot"] = None
netDevice["bootproto"] = None
- netDevice["ipaddr"] = None
- netDevice["netmask"] = None
netDevice["gateway"] = None
netDevice["peerdns"] = None
netDevice["autodns"] = None
@@ -294,7 +311,10 @@ def getNetDeviceList(root=""):
netDevice["type"] = None
netDevice["link"] = getLinkStatus(deviceName)
netDevice["mode"] = getBondMode(deviceName, root + Globals.MODPROBE_CONF_FILE)
- netDevice["model"] = getNetModel(deviceName)
+ deviceDetail = getNetDeviceDetail(deviceName)
+ netDevice["model"] = deviceDetail['Model']
+ netDevice["ipaddr"] = deviceDetail['Ip']
+ netDevice["netmask"] = deviceDetail['Mask']
netDevice["speed"] = getNetSpeed(deviceName)
try:
netDevice["hwaddr"] = open("/sys/class/net/%s/address" % deviceName).read().strip()
@@ -314,18 +334,16 @@ def getNetDeviceList(root=""):
netDevice["bootproto"] = conf["bootproto"]
except KeyError:
pass
- try:
+ if conf.has_key("ipaddr") and conf["ipaddr"]:
netDevice["ipaddr"] = conf["ipaddr"]
- except KeyError:
- pass
try:
netDevice["netmask"] = conf["netmask"]
except KeyError:
pass
- try:
+ if conf.has_key("gateway") and conf["gateway"]:
netDevice["gateway"] = conf["gateway"]
- except KeyError:
- pass
+ else:
+ netDevice["gateway"] = getNetDeviceGateway(deviceName)
try:
netDevice["peerdns"] = conf["peerdns"]
except KeyError: