Revision 7df2c4f0 lib/netutils.py

b/lib/netutils.py
362 362
      return False
363 363

  
364 364
  @classmethod
365
  def ValidateNetmask(cls, netmask):
366
    """Validate a netmask suffix in CIDR notation.
367

  
368
    @type netmask: int
369
    @param netmask: netmask suffix to validate
370
    @rtype: bool
371
    @return: True if valid, False otherwise
372

  
373
    """
374
    assert (isinstance(netmask, (int, long)))
375

  
376
    return 0 < netmask <= cls.iplen
377

  
378
  @classmethod
365 379
  def Own(cls, address):
366 380
    """Check if the current host has the the given IP address.
367 381

  
......
487 501

  
488 502
    raise errors.ProgrammerError("%s is not a valid IP version" % version)
489 503

  
504
  @staticmethod
505
  def GetClassFromIpVersion(version):
506
    """Return the IPAddress subclass for the given IP version.
507

  
508
    @type version: int
509
    @param version: IP version, one of L{constants.IP4_VERSION} or
510
                    L{constants.IP6_VERSION}
511
    @return: a subclass of L{netutils.IPAddress}
512
    @raise errors.ProgrammerError: for unknowo IP versions
513

  
514
    """
515
    if version == constants.IP4_VERSION:
516
      return IP4Address
517
    elif version == constants.IP6_VERSION:
518
      return IP6Address
519

  
520
    raise errors.ProgrammerError("%s is not a valid IP version" % version)
521

  
522
  @staticmethod
523
  def GetClassFromIpFamily(family):
524
    """Return the IPAddress subclass for the given IP family.
525

  
526
    @param family: IP family (one of C{socket.AF_INET} or C{socket.AF_INET6}
527
    @return: a subclass of L{netutils.IPAddress}
528
    @raise errors.ProgrammerError: for unknowo IP versions
529

  
530
    """
531
    return IPAddress.GetClassFromIpVersion(
532
              IPAddress.GetVersionFromAddressFamily(family))
533

  
490 534
  @classmethod
491 535
  def IsLoopback(cls, address):
492 536
    """Determine whether it is a loopback address.

Also available in: Unified diff