How to use the ciscoconfparse.local_py.ipaddr.IPv6Address function in ciscoconfparse

To help you get started, we’ve selected a few ciscoconfparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
# which converts into a formatted IP prefix string.
            addr = str(address).split('/')

            if len(addr) > 2:
                raise AddressValueError(address)

            self._ip = self._ip_int_from_string(addr[0])
            self.ip = IPv6Address(self._ip)

            if len(addr) == 2:
                # This may raise NetmaskValueError
                self._prefixlen = self._prefix_from_prefix_string(addr[1])
            else:
                self._prefixlen = self._max_prefixlen

        self.netmask = IPv6Address(self._ip_int_from_prefix(self._prefixlen))

        if strict:
            if self.ip != self.network:
                raise ValueError('%s has host bits set' %
                                 self.ip)
        if self._prefixlen == (self._max_prefixlen - 1):
            self.iterhosts = self.__iter__
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
except ValueError:
                raise AddressValueError(address)
            self.ip = IPv6Address(ip)
            self._ip = self.ip._ip
            self._prefixlen = self._prefix_from_prefix_int(prefixlen)

        else:
            # Assume input argument to be string or any object representation
            # which converts into a formatted IP prefix string.
            addr = str(address).split('/')

            if len(addr) > 2:
                raise AddressValueError(address)

            self._ip = self._ip_int_from_string(addr[0])
            self.ip = IPv6Address(self._ip)

            if len(addr) == 2:
                # This may raise NetmaskValueError
                self._prefixlen = self._prefix_from_prefix_string(addr[1])
            else:
                self._prefixlen = self._max_prefixlen

        self.netmask = IPv6Address(self._ip_int_from_prefix(self._prefixlen))

        if strict:
            if self.ip != self.network:
                raise ValueError('%s has host bits set' %
                                 self.ip)
        if self._prefixlen == (self._max_prefixlen - 1):
            self.iterhosts = self.__iter__
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
# Constructing from a single IP address.
        if isinstance(address, (int, long, Bytes, IPv6Address)):
            self.ip = IPv6Address(address)
            self._ip = self.ip._ip
            self._prefixlen = self._max_prefixlen
            self.netmask = IPv6Address(self._ALL_ONES)
            return

        # Constructing from an (ip, prefixlen) tuple.
        if isinstance(address, tuple):
            try:
                ip, prefixlen = address
            except ValueError:
                raise AddressValueError(address)
            self.ip = IPv6Address(ip)
            self._ip = self.ip._ip
            self._prefixlen = self._prefix_from_prefix_int(prefixlen)

        else:
            # Assume input argument to be string or any object representation
            # which converts into a formatted IP prefix string.
            addr = str(address).split('/')

            if len(addr) > 2:
                raise AddressValueError(address)

            self._ip = self._ip_int_from_string(addr[0])
            self.ip = IPv6Address(self._ip)

            if len(addr) == 2:
                # This may raise NetmaskValueError
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
AddressValueError: If address isn't a valid IPv6 address.
            NetmaskValueError: If the netmask isn't valid for
              an IPv6 address.
            ValueError: If strict was True and a network address was not
              supplied.

        """
        _BaseNet.__init__(self, address)
        _BaseV6.__init__(self, address)

        # Constructing from a single IP address.
        if isinstance(address, (int, long, Bytes, IPv6Address)):
            self.ip = IPv6Address(address)
            self._ip = self.ip._ip
            self._prefixlen = self._max_prefixlen
            self.netmask = IPv6Address(self._ALL_ONES)
            return

        # Constructing from an (ip, prefixlen) tuple.
        if isinstance(address, tuple):
            try:
                ip, prefixlen = address
            except ValueError:
                raise AddressValueError(address)
            self.ip = IPv6Address(ip)
            self._ip = self.ip._ip
            self._prefixlen = self._prefix_from_prefix_int(prefixlen)

        else:
            # Assume input argument to be string or any object representation
            # which converts into a formatted IP prefix string.
            addr = str(address).split('/')
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
like IPAddress(1), which could be IPv4, '0.0.0.1',  or IPv6,
          '::1'.

    Returns:
        An IPv4Address or IPv6Address object.

    Raises:
        ValueError: if the string passed isn't either a v4 or a v6
          address.

    """
    if version:
        if version == 4:
            return IPv4Address(address)
        elif version == 6:
            return IPv6Address(address)

    try:
        return IPv4Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    try:
        return IPv6Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
                     address)
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
IP address on a network, eg, 2001:db8::1/32.

        Raises:
            AddressValueError: If address isn't a valid IPv6 address.
            NetmaskValueError: If the netmask isn't valid for
              an IPv6 address.
            ValueError: If strict was True and a network address was not
              supplied.

        """
        _BaseNet.__init__(self, address)
        _BaseV6.__init__(self, address)

        # Constructing from a single IP address.
        if isinstance(address, (int, long, Bytes, IPv6Address)):
            self.ip = IPv6Address(address)
            self._ip = self.ip._ip
            self._prefixlen = self._max_prefixlen
            self.netmask = IPv6Address(self._ALL_ONES)
            return

        # Constructing from an (ip, prefixlen) tuple.
        if isinstance(address, tuple):
            try:
                ip, prefixlen = address
            except ValueError:
                raise AddressValueError(address)
            self.ip = IPv6Address(ip)
            self._ip = self.ip._ip
            self._prefixlen = self._prefix_from_prefix_int(prefixlen)

        else:
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
address.

    """
    if version:
        if version == 4:
            return IPv4Address(address)
        elif version == 6:
            return IPv6Address(address)

    try:
        return IPv4Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    try:
        return IPv6Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
                     address)
github mpenning / ciscoconfparse / ciscoconfparse / local_py / ipaddr.py View on Github external
Additionally, an integer can be passed, so
              IPv6Address('2001:4860::') ==
                IPv6Address(42541956101370907050197289607612071936L).
              or, more generally
              IPv6Address(IPv6Address('2001:4860::')._ip) ==
                IPv6Address('2001:4860::')

        Raises:
            AddressValueError: If address isn't a valid IPv6 address.

        """
        _BaseV6.__init__(self, address)

        # Efficient copy constructor.
        if isinstance(address, IPv6Address):
            self._ip = address._ip
            return

        # Efficient constructor from integer.
        if isinstance(address, (int, long)):
            self._ip = address
            if address < 0 or address > self._ALL_ONES:
                raise AddressValueError(address)
            return

        # Constructing from a packed address
        if isinstance(address, Bytes):
            try:
                hi, lo = struct.unpack('!QQ', address)
            except struct.error:
                raise AddressValueError(address)  # Wrong length.