Python netaddr 模块,mac_unix() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用netaddr.mac_unix()

项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def _unix_query(v):
    v.dialect = netaddr.mac_unix
    return str(v)
项目:quark    作者:openstack    | 项目源码 | 文件源码
def test_to_mac_range_cidr_format(self):
        cidr, first, last = mac_address_ranges._to_mac_range("AA:BB:CC/24")
        first_mac = str(netaddr.EUI(first, dialect=netaddr.mac_unix))
        last_mac = str(netaddr.EUI(last, dialect=netaddr.mac_unix))
        self.assertEqual(cidr, "AA:BB:CC:00:00:00/24")
        self.assertEqual(first_mac, "aa:bb:cc:0:0:0")
        self.assertEqual(last_mac, "aa:bb:cd:0:0:0")
项目:quark    作者:openstack    | 项目源码 | 文件源码
def test_to_mac_range_just_prefix(self):
        cidr, first, last = mac_address_ranges._to_mac_range("AA:BB:CC")
        first_mac = str(netaddr.EUI(first, dialect=netaddr.mac_unix))
        last_mac = str(netaddr.EUI(last, dialect=netaddr.mac_unix))
        self.assertEqual(cidr, "AA:BB:CC:00:00:00/24")
        self.assertEqual(first_mac, "aa:bb:cc:0:0:0")
        self.assertEqual(last_mac, "aa:bb:cd:0:0:0")
项目:quark    作者:openstack    | 项目源码 | 文件源码
def test_to_mac_range_unix_format(self):
        cidr, first, last = mac_address_ranges._to_mac_range("AA-BB-CC")
        first_mac = str(netaddr.EUI(first, dialect=netaddr.mac_unix))
        last_mac = str(netaddr.EUI(last, dialect=netaddr.mac_unix))
        self.assertEqual(cidr, "AA:BB:CC:00:00:00/24")
        self.assertEqual(first_mac, "aa:bb:cc:0:0:0")
        self.assertEqual(last_mac, "aa:bb:cd:0:0:0")
项目:quark    作者:openstack    | 项目源码 | 文件源码
def test_to_mac_range_unix_cidr_format(self):
        cidr, first, last = mac_address_ranges._to_mac_range("AA-BB-CC/24")
        first_mac = str(netaddr.EUI(first, dialect=netaddr.mac_unix))
        last_mac = str(netaddr.EUI(last, dialect=netaddr.mac_unix))
        self.assertEqual(cidr, "AA:BB:CC:00:00:00/24")
        self.assertEqual(first_mac, "aa:bb:cc:0:0:0")
        self.assertEqual(last_mac, "aa:bb:cd:0:0:0")
项目:quark    作者:openstack    | 项目源码 | 文件源码
def test_to_mac_range_unix_cidr_format_normal_length(self):
        cidr, first, last = mac_address_ranges._to_mac_range("aabbcc000000/29")
        first_mac = str(netaddr.EUI(first, dialect=netaddr.mac_unix))
        last_mac = str(netaddr.EUI(last, dialect=netaddr.mac_unix))
        self.assertEqual(cidr, "AA:BB:CC:00:00:00/29")
        self.assertEqual(first_mac, "aa:bb:cc:0:0:0")
        self.assertEqual(last_mac, "aa:bb:cc:8:0:0")
项目:f5-aws-vpn    作者:f5devcentral    | 项目源码 | 文件源码
def _unix_query(v):
    v.dialect = netaddr.mac_unix
    return str(v)
项目:ansible-provider-docs    作者:alibaba    | 项目源码 | 文件源码
def _unix_query(v):
    v.dialect = netaddr.mac_unix
    return str(v)
项目:ansible-skel    作者:mrjk    | 项目源码 | 文件源码
def hwaddr(value, query = '', alias = 'hwaddr'):
    ''' Check if string is a HW/MAC address and filter it '''

    try:
        v = netaddr.EUI(value)
    except:
        if query and query not in [ 'bool' ]:
            raise errors.AnsibleFilterError(alias + ': not a hardware address: %s' % value)

    if not query:
        if v:
            return value

    elif query == 'bool':
        if v:
            return True

    elif query in [ 'win', 'eui48' ]:
        v.dialect = netaddr.mac_eui48
        return str(v)

    elif query == 'unix':
        v.dialect = netaddr.mac_unix
        return str(v)

    elif query in [ 'pgsql', 'postgresql', 'psql' ]:
        v.dialect = netaddr.mac_pgsql
        return str(v)

    elif query == 'cisco':
        v.dialect = netaddr.mac_cisco
        return str(v)

    elif query == 'bare':
        v.dialect = netaddr.mac_bare
        return str(v)

    elif query == 'linux':
        v.dialect = mac_linux
        return str(v)

    else:
        raise errors.AnsibleFilterError(alias + ': unknown filter type: %s' % query)

    return False