'Takes a netmask as either an IPAddr or a string, and returns the number
of network bits.  e.g., 255.255.255.0 -> 24
Raise exception if subnet mask is not CIDR-compatible.'

@staticmethod
def netmask_to_cidr(dq):

    if isinstance(dq, basestring):
        dq = IPAddr6(dq)
    v = dq.num
    c = 0
    while (v & (1 << 127)):
        c += 1
        v <<= 1
    v = (v & ((1 << 128) - 1))
    if (v != 0):
        raise RuntimeError(('Netmask    %s    is    not    CIDR-compatible' % (dq,)))
    return c
