@@ -980,21 +980,58 @@ def ManagementIP(self, inDefault = None):
980
980
981
981
def ManagementNetmask (self , inDefault = None ):
982
982
retVal = inDefault
983
-
984
983
for pif in self .derived .managementpifs ([]):
985
- retVal = pif ['netmask' ]
986
- if retVal :
987
- break
984
+ ipv6 = pif ['primary_address_type' ].lower () == 'ipv6'
985
+ configuration_mode = pif ['ipv6_configuration_mode' ] if ipv6 else pif ['ip_configuration_mode' ]
986
+ if configuration_mode .lower ().startswith ('static' ):
987
+ # For static IP the API address is correct
988
+ retVal = pif ['IPv6' ][0 ].split ('/' )[1 ] if ipv6 else pif ['netmask' ]
989
+ elif configuration_mode .lower ().startswith ('dhcp' ):
990
+ # For DHCP, find the gateway address by parsing the output from the 'route' command
991
+ if 'bridge' in pif ['network' ]:
992
+ device = pif ['network' ]['bridge' ]
993
+ else :
994
+ device = pif ['device' ]
995
+
996
+ device = ShellUtils .MakeSafeParam (device )
997
+
998
+ ipre = r'[0-9a-f.:]+'
999
+ ifRE = re .compile (r'\s*inet\s+' + ipre + '\s+netmask\s+(' + ipre + r')\s+broadcast\s+(' + ipre + r')\s*$' ,
1000
+ re .IGNORECASE )
1001
+
1002
+ ifconfig = commands .getoutput ("/sbin/ifconfig '" + device + "'" ).split ("\n " )
1003
+ for line in ifconfig :
1004
+ match = ifRE .match (line )
1005
+ if match :
1006
+ retVal = match .group (1 )
1007
+ break
988
1008
989
1009
return retVal
990
1010
991
1011
def ManagementGateway (self , inDefault = None ):
992
1012
retVal = inDefault
993
1013
994
1014
for pif in self .derived .managementpifs ([]):
995
- retVal = pif ['gateway' ]
996
- if retVal :
997
- break
1015
+ ipv6 = pif ['primary_address_type' ].lower () == 'ipv6'
1016
+ configuration_mode = pif ['ipv6_configuration_mode' ] if ipv6 else pif ['ip_configuration_mode' ]
1017
+ if configuration_mode .lower ().startswith ('static' ):
1018
+ # For static IP the API address is correct
1019
+ retVal = pif ['ipv6_gateway' ] if ipv6 else pif ['gateway' ]
1020
+ elif configuration_mode .lower ().startswith ('dhcp' ):
1021
+ # For DHCP, find the gateway address by parsing the output from the 'route' command
1022
+ if 'bridge' in pif ['network' ]:
1023
+ device = pif ['network' ]['bridge' ]
1024
+ else :
1025
+ device = pif ['device' ]
1026
+ routeRE = re .compile (r'([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+UG\s+\d+\s+\d+\s+\d+\s+' + device ,
1027
+ re .IGNORECASE )
1028
+
1029
+ routes = commands .getoutput ("/sbin/route -n" ).split ("\n " )
1030
+ for line in routes :
1031
+ match = routeRE .match (line )
1032
+ if match :
1033
+ retVal = match .group (2 )
1034
+ break
998
1035
999
1036
return retVal
1000
1037
0 commit comments