Package ganeti :: Module netutils :: Class IPAddress
[hide private]
[frames] | no frames]

Class IPAddress

source code


Class that represents an IP address.

Instance Methods [hide private]

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
bool
IsValid(cls, address)
Validate a IP address.
source code
bool
Own(cls, address)
Check if the current host has the the given IP address.
source code
bool
InNetwork(cls, cidr, address)
Determine whether an address is within a network.
source code
bool
IsLoopback(cls, address)
Determine whether it is a loopback address.
source code
Static Methods [hide private]
 
_GetIPIntFromString(address)
Abstract method to please pylint.
source code
int
GetAddressFamily(address)
Get the address family of the given address.
source code
 
GetVersionFromAddressFamily(family)
Convert an IP address family to the corresponding IP version.
source code
 
GetAddressFamilyFromVersion(version)
Convert an IP version to the corresponding IP address family.
source code
Class Variables [hide private]
  iplen = 0
  family = None
  loopback_cidr = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

IsValid(cls, address)
Class Method

source code 

Validate a IP address.

Parameters:
  • address (str) - IP address to be checked
Returns: bool
True if valid, False otherwise

Own(cls, address)
Class Method

source code 

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 (str) - IP address to be checked
Returns: bool
True if we own the address, False otherwise

InNetwork(cls, cidr, address)
Class Method

source code 

Determine whether an address is within a network.

Parameters:
  • cidr (string) - Network in CIDR notation, e.g. '192.0.2.0/24', '2001:db8::/64'
  • address (str) - IP address
Returns: bool
True if address is in cidr, False otherwise

GetAddressFamily(address)
Static Method

source code 

Get the address family of the given address.

Parameters:
  • address (str) - ip address whose family will be returned
Returns: int
socket.AF_INET or socket.AF_INET6
Raises:

GetVersionFromAddressFamily(family)
Static Method

source code 

Convert an IP address family to the corresponding IP version.

Parameters:
  • family (int) - IP 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:

GetAddressFamilyFromVersion(version)
Static Method

source code 

Convert an IP version to the corresponding IP address family.

Parameters:
Returns:
an int containing the IP address family, one of socket.AF_INET or socket.AF_INET6
Raises:

IsLoopback(cls, address)
Class Method

source code 

Determine whether it is a loopback address.

Parameters:
  • address (str) - IP address to be checked
Returns: bool
True if loopback, False otherwise