Skip to content

Commit 9437ea2

Browse files
benjamreisbernhardkaindl
authored andcommitted
Get field from PIF instead of calling ifconfig/route
Now the field `gateway` and `netmask` are filled even in DHCP. Signed-off-by: BenjiReis <[email protected]>
1 parent 4deeb6f commit 9437ea2

File tree

1 file changed

+6
-42
lines changed

1 file changed

+6
-42
lines changed

XSConsoleData.py

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -965,56 +965,20 @@ def ManagementIP(self, inDefault = None):
965965
def ManagementNetmask(self, inDefault = None):
966966
retVal = inDefault
967967

968-
# FIXME: Address should come from API, but not available at present. For DHCP this is just a guess at the gateway address
969968
for pif in self.derived.managementpifs([]):
970-
if pif['ip_configuration_mode'].lower().startswith('static'):
971-
# For static IP the API address is correct
972-
retVal = pif['netmask']
973-
elif pif['ip_configuration_mode'].lower().startswith('dhcp'):
974-
# For DHCP, find the gateway address by parsing the output from the 'route' command
975-
if 'bridge' in pif['network']:
976-
device = pif['network']['bridge']
977-
else:
978-
device = pif['device']
979-
980-
device = ShellUtils.MakeSafeParam(device)
981-
982-
ipre = r'[0-9a-f.:]+'
983-
ifRE = re.compile(r'\s*inet\s+' + ipre + '\s+netmask\s+(' + ipre + r')\s+broadcast\s+(' + ipre + r')\s*$',
984-
re.IGNORECASE)
985-
986-
ifconfig = commands.getoutput("/sbin/ifconfig '"+device+"'").split("\n")
987-
for line in ifconfig:
988-
match = ifRE.match(line)
989-
if match:
990-
retVal = match.group(1)
991-
break
969+
retVal = pif['netmask']
970+
if retVal:
971+
break
992972

993973
return retVal
994974

995975
def ManagementGateway(self, inDefault = None):
996976
retVal = inDefault
997977

998-
# FIXME: Address should come from API, but not available at present. For DHCP this is just a guess at the gateway address
999978
for pif in self.derived.managementpifs([]):
1000-
if pif['ip_configuration_mode'].lower().startswith('static'):
1001-
# For static IP the API address is correct
1002-
retVal = pif['gateway']
1003-
elif pif['ip_configuration_mode'].lower().startswith('dhcp'):
1004-
# For DHCP, find the gateway address by parsing the output from the 'route' command
1005-
if 'bridge' in pif['network']:
1006-
device = pif['network']['bridge']
1007-
else:
1008-
device = pif['device']
1009-
routeRE = re.compile(r'([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+UG\s+\d+\s+\d+\s+\d+\s+'+device,
1010-
re.IGNORECASE)
1011-
1012-
routes = commands.getoutput("/sbin/route -n").split("\n")
1013-
for line in routes:
1014-
match = routeRE.match(line)
1015-
if match:
1016-
retVal = match.group(2)
1017-
break
979+
retVal = pif['gateway']
980+
if retVal:
981+
break
1018982

1019983
return retVal
1020984

0 commit comments

Comments
 (0)