changes to replace MacAddress usage and remove ipaddress module altogether
This commit is contained in:
parent
4db7f845a5
commit
de493c810a
11 changed files with 43 additions and 83 deletions
|
@ -725,14 +725,14 @@ class CoreNode(CoreNodeBase):
|
|||
Set hardware addres for an interface.
|
||||
|
||||
:param int ifindex: index of interface to set hardware address for
|
||||
:param core.nodes.ipaddress.MacAddress addr: hardware address to set
|
||||
:param str addr: hardware address to set
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
interface = self._netif[ifindex]
|
||||
interface.sethwaddr(addr)
|
||||
if self.up:
|
||||
self.node_net_client.device_mac(interface.name, str(addr))
|
||||
self.node_net_client.device_mac(interface.name, addr)
|
||||
|
||||
def addaddr(self, ifindex, addr):
|
||||
"""
|
||||
|
@ -787,7 +787,7 @@ class CoreNode(CoreNodeBase):
|
|||
|
||||
:param core.nodes.base.CoreNetworkBase net: network to associate with
|
||||
:param list addrlist: addresses to add on the interface
|
||||
:param core.nodes.ipaddress.MacAddress hwaddr: hardware address to set for interface
|
||||
:param str hwaddr: hardware address to set for interface
|
||||
:param int ifindex: index of interface to create
|
||||
:param str ifname: name for interface
|
||||
:return: interface index
|
||||
|
|
|
@ -130,7 +130,7 @@ class CoreInterface:
|
|||
"""
|
||||
Set hardware address.
|
||||
|
||||
:param core.nodes.ipaddress.MacAddress addr: hardware address to set to.
|
||||
:param str addr: hardware address to set to.
|
||||
:return: nothing
|
||||
"""
|
||||
self.hwaddr = addr
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
"""
|
||||
Helper objects for dealing with IPv4/v6 addresses.
|
||||
"""
|
||||
|
||||
import random
|
||||
import struct
|
||||
|
||||
|
||||
class MacAddress:
|
||||
"""
|
||||
Provides mac address utilities for use within core.
|
||||
"""
|
||||
|
||||
def __init__(self, address):
|
||||
"""
|
||||
Creates a MacAddress instance.
|
||||
|
||||
:param bytes address: mac address
|
||||
"""
|
||||
self.addr = address
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Create a string representation of a MacAddress.
|
||||
|
||||
:return: string representation
|
||||
:rtype: str
|
||||
"""
|
||||
return ":".join(f"{x:02x}" for x in bytearray(self.addr))
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, s):
|
||||
"""
|
||||
Create a mac address object from a string.
|
||||
|
||||
:param s: string representation of a mac address
|
||||
:return: mac address class
|
||||
:rtype: MacAddress
|
||||
"""
|
||||
addr = b"".join(bytes([int(x, 16)]) for x in s.split(":"))
|
||||
return cls(addr)
|
||||
|
||||
@classmethod
|
||||
def random(cls):
|
||||
"""
|
||||
Create a random mac address.
|
||||
|
||||
:return: random mac address
|
||||
:rtype: MacAddress
|
||||
"""
|
||||
tmp = random.randint(0, 0xFFFFFF)
|
||||
# use the Xen OID 00:16:3E
|
||||
tmp |= 0x00163E << 24
|
||||
tmpbytes = struct.pack("!Q", tmp)
|
||||
return cls(tmpbytes[2:])
|
Loading…
Add table
Add a link
Reference in a new issue