def _to_mac_range(val):
cidr_parts = val.split("/")
prefix = cidr_parts[0]
# FIXME(anyone): replace is slow, but this doesn't really
# get called ever. Fix maybe?
prefix = prefix.replace(':', '')
prefix = prefix.replace('-', '')
prefix_length = len(prefix)
if prefix_length < 6 or prefix_length > 12:
raise q_exc.InvalidMacAddressRange(cidr=val)
diff = 12 - len(prefix)
if len(cidr_parts) > 1:
mask = int(cidr_parts[1])
else:
mask = 48 - diff * 4
mask_size = 1 << (48 - mask)
prefix = "%s%s" % (prefix, "0" * diff)
try:
cidr = "%s/%s" % (str(netaddr.EUI(prefix)).replace("-", ":"), mask)
except netaddr.AddrFormatError:
raise q_exc.InvalidMacAddressRange(cidr=val)
prefix_int = int(prefix, base=16)
return cidr, prefix_int, prefix_int + mask_size
评论列表
文章目录