improved netaddr mac dialect usage to leverage constructor parameter
This commit is contained in:
parent
4ae5936bdc
commit
686026d9f2
4 changed files with 6 additions and 12 deletions
|
@ -350,8 +350,7 @@ class CoreTlvDataMacAddr(CoreTlvDataObj):
|
||||||
"""
|
"""
|
||||||
# only use 48 bits
|
# only use 48 bits
|
||||||
value = binascii.hexlify(value[2:]).decode()
|
value = binascii.hexlify(value[2:]).decode()
|
||||||
mac = netaddr.EUI(value)
|
mac = netaddr.EUI(value, dialect=netaddr.mac_unix_expanded)
|
||||||
mac.dialect = netaddr.mac_unix
|
|
||||||
return str(mac)
|
return str(mac)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -354,8 +354,7 @@ class NodeConfigDialog(Dialog):
|
||||||
error = True
|
error = True
|
||||||
break
|
break
|
||||||
elif not auto_mac:
|
elif not auto_mac:
|
||||||
mac = netaddr.EUI(mac)
|
mac = netaddr.EUI(mac, dialect=netaddr.mac_unix_expanded)
|
||||||
mac.dialect = netaddr.mac_unix_expanded
|
|
||||||
interface.mac = str(mac)
|
interface.mac = str(mac)
|
||||||
|
|
||||||
# redraw
|
# redraw
|
||||||
|
|
|
@ -52,7 +52,7 @@ class InterfaceManager:
|
||||||
self.ip4_subnets = IPNetwork(f"{ip4}/{self.ip4_mask}")
|
self.ip4_subnets = IPNetwork(f"{ip4}/{self.ip4_mask}")
|
||||||
self.ip6_subnets = IPNetwork(f"{ip6}/{self.ip6_mask}")
|
self.ip6_subnets = IPNetwork(f"{ip6}/{self.ip6_mask}")
|
||||||
mac = self.app.guiconfig.get("mac", appconfig.DEFAULT_MAC)
|
mac = self.app.guiconfig.get("mac", appconfig.DEFAULT_MAC)
|
||||||
self.mac = EUI(mac)
|
self.mac = EUI(mac, dialect=netaddr.mac_unix_expanded)
|
||||||
self.current_mac = None
|
self.current_mac = None
|
||||||
self.current_subnets = None
|
self.current_subnets = None
|
||||||
self.used_subnets = {}
|
self.used_subnets = {}
|
||||||
|
@ -64,13 +64,11 @@ class InterfaceManager:
|
||||||
|
|
||||||
def reset_mac(self) -> None:
|
def reset_mac(self) -> None:
|
||||||
self.current_mac = self.mac
|
self.current_mac = self.mac
|
||||||
self.current_mac.dialect = netaddr.mac_unix_expanded
|
|
||||||
|
|
||||||
def next_mac(self) -> str:
|
def next_mac(self) -> str:
|
||||||
mac = str(self.current_mac)
|
mac = str(self.current_mac)
|
||||||
value = self.current_mac.value + 1
|
value = self.current_mac.value + 1
|
||||||
self.current_mac = EUI(value)
|
self.current_mac = EUI(value, dialect=netaddr.mac_unix_expanded)
|
||||||
self.current_mac.dialect = netaddr.mac_unix_expanded
|
|
||||||
return mac
|
return mac
|
||||||
|
|
||||||
def next_subnets(self) -> Subnets:
|
def next_subnets(self) -> Subnets:
|
||||||
|
|
|
@ -437,8 +437,7 @@ def random_mac() -> str:
|
||||||
"""
|
"""
|
||||||
value = random.randint(0, 0xFFFFFF)
|
value = random.randint(0, 0xFFFFFF)
|
||||||
value |= 0x00163E << 24
|
value |= 0x00163E << 24
|
||||||
mac = netaddr.EUI(value)
|
mac = netaddr.EUI(value, dialect=netaddr.mac_unix_expanded)
|
||||||
mac.dialect = netaddr.mac_unix_expanded
|
|
||||||
return str(mac)
|
return str(mac)
|
||||||
|
|
||||||
|
|
||||||
|
@ -450,8 +449,7 @@ def validate_mac(value: str) -> str:
|
||||||
:return: unix formatted mac
|
:return: unix formatted mac
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
mac = netaddr.EUI(value)
|
mac = netaddr.EUI(value, dialect=netaddr.mac_unix_expanded)
|
||||||
mac.dialect = netaddr.mac_unix_expanded
|
|
||||||
return str(mac)
|
return str(mac)
|
||||||
except netaddr.AddrFormatError as e:
|
except netaddr.AddrFormatError as e:
|
||||||
raise CoreError(f"invalid mac address {value}: {e}")
|
raise CoreError(f"invalid mac address {value}: {e}")
|
||||||
|
|
Loading…
Add table
Reference in a new issue