class documentation

class IPAddress(object):

Known subclasses: ganeti.netutils.IP4Address, ganeti.netutils.IP6Address

View In Hierarchy

Class that represents an IP address.

Class Method InNetwork Determine whether an address is within a network.
Class Method IsLoopback Determine whether it is a loopback address.
Class Method IsValid Validate a IP address.
Class Method Own Check if the current host has the the given IP address.
Class Method ValidateNetmask Validate a netmask suffix in CIDR notation.
Static Method GetAddressFamily Get the address family of the given address.
Static Method GetAddressFamilyFromVersion Convert an IP version to the corresponding IP address family.
Static Method GetClassFromIpFamily Return the IPAddress subclass for the given IP family.
Static Method GetClassFromIpVersion Return the IPAddress subclass for the given IP version.
Static Method GetVersionFromAddressFamily Convert an IP address family to the corresponding IP version.
Class Variable family Undocumented
Class Variable iplen Undocumented
Class Variable loopback_cidr Undocumented
Static Method _GetIPIntFromString Abstract method to please pylint.
@classmethod
def InNetwork(cls, cidr, address):

Determine whether an address is within a network.

Parameters
cidr:stringNetwork in CIDR notation, e.g. '192.0.2.0/24', '2001:db8::/64'
address:strIP address
Returns
boolTrue if address is in cidr, False otherwise
@classmethod
def IsLoopback(cls, address):

Determine whether it is a loopback address.

Parameters
address:strIP address to be checked
Returns
boolTrue if loopback, False otherwise
@classmethod
def IsValid(cls, address):

Validate a IP address.

Parameters
address:strIP address to be checked
Returns
boolTrue if valid, False otherwise
@classmethod
def Own(cls, address):

Check if the current host has the the given IP address.

This is done by trying to bind the given address. We return True if we succeed or false if a socket.error is raised.

Parameters
address:strIP address to be checked
Returns
boolTrue if we own the address, False otherwise
@classmethod
def ValidateNetmask(cls, netmask):

Validate a netmask suffix in CIDR notation.

Parameters
netmask:intnetmask suffix to validate
Returns
boolTrue if valid, False otherwise
@staticmethod
def GetAddressFamily(address):

Get the address family of the given address.

Parameters
address:strip address whose family will be returned
Returns
intsocket.AF_INET or socket.AF_INET6
Raises
errors.GenericErrorfor invalid addresses
@staticmethod
def GetAddressFamilyFromVersion(version):

Convert an IP version to the corresponding IP address family.

Parameters
version:intIP version, one of constants.IP4_VERSION or constants.IP6_VERSION
Returns
an int containing the IP address family, one of socket.AF_INET or socket.AF_INET6
Raises
errors.ProgrammerErrorfor unknown IP versions
@staticmethod
def GetClassFromIpFamily(family):

Return the IPAddress subclass for the given IP family.

Parameters
familyIP family (one of socket.AF_INET or socket.AF_INET6
Returns
a subclass of netutils.IPAddress
Raises
errors.ProgrammerErrorfor unknowo IP versions
@staticmethod
def GetClassFromIpVersion(version):

Return the IPAddress subclass for the given IP version.

Parameters
version:intIP version, one of constants.IP4_VERSION or constants.IP6_VERSION
Returns
a subclass of netutils.IPAddress
Raises
errors.ProgrammerErrorfor unknowo IP versions
@staticmethod
def GetVersionFromAddressFamily(family):

Convert an IP address family to the corresponding IP version.

Parameters
family:intIP address family, one of socket.AF_INET or socket.AF_INET6
Returns
an int containing the IP version, one of constants.IP4_VERSION or constants.IP6_VERSION
Raises
errors.ProgrammerErrorfor unknown families
family =

Undocumented

iplen: int =
loopback_cidr =
@staticmethod
def _GetIPIntFromString(address):

Abstract method to please pylint.