module documentation

Ganeti network utility module.

This module holds functions that can be used in both daemons (all) and the command line scripts.

Class Hostname Class implementing resolver and hostname functionality.
Class IP4Address IPv4 address class.
Class IP6Address IPv6 address class.
Class IPAddress Class that represents an IP address.
Function FormatAddress Format a socket address
Function GetDaemonPort Get the daemon port for this cluster.
Function GetHostname Returns a Hostname object.
Function GetInterfaceIpAddresses Returns the IP addresses associated to the interface.
Function GetSocketCredentials Returns the credentials of the foreign process connected to a socket.
Function IsValidInterface Validate an interface name.
Function TcpPing Simple ping implementation using TCP connect(2).
Function ValidatePortNumber Returns the validated integer port number if it is valid.
Function _GetIpAddressesFromIpOutput Parses the output of the ip command and retrieves the IP addresses and version.
Constant _IP_FAMILY_RE Undocumented
Constant _IP_RE_TEXT Undocumented
Constant _NAME_TO_IP_VER Undocumented
Constant _STRUCT_UCRED Undocumented
Constant _STRUCT_UCRED_SIZE Undocumented
def FormatAddress(address, family=None):

Format a socket address

Parameters
address:family specific (usually tuple)address, as reported by this class
family:integersocket family (one of socket.AF_*) or None
def GetDaemonPort(daemon_name):

Get the daemon port for this cluster.

Note that this routine does not read a ganeti-specific file, but instead uses socket.getservbyname to allow pre-customization of this parameter outside of Ganeti.

Parameters
daemon_name:stringdaemon name (in constants.DAEMONS_PORTS)
Returns
intUndocumented
def GetHostname(name=None, family=None):

Returns a Hostname object.

Parameters
name:strhostname or None
family:intAF_INET | AF_INET6 | None
Returns
HostnameHostname object
Raises
errors.OpPrereqErrorin case of errors in resolving
def GetInterfaceIpAddresses(ifname):

Returns the IP addresses associated to the interface.

Parameters
ifname:stringName of the network interface
Returns
A dict having for keys the IP version (either constants.IP4_VERSION or constants.IP6_VERSION) and for values the lists of IP addresses of the respective version associated to the interface
def GetSocketCredentials(sock):

Returns the credentials of the foreign process connected to a socket.

Parameters
sockUnix socket
Returns
tuple; (number, number, number)The PID, UID and GID of the connected foreign process.
def IsValidInterface(ifname):

Validate an interface name.

Parameters
ifname:stringName of the network interface
Returns
boolean indicating whether the interface name is valid or not.
def TcpPing(target, port, timeout=10, live_port_needed=False, source=None):

Simple ping implementation using TCP connect(2).

Check if the given IP is reachable by doing attempting a TCP connect to it.

Parameters
target:strthe IP to ping
port:intthe port to connect to
timeout:intthe timeout on the connection attempt
live_port_needed:booleanwhether a closed port will cause the function to return failure, as if there was a timeout
source:str or Noneif specified, will cause the connect to be made from this specific source address; failures to bind other than EADDRNOTAVAIL will be ignored
def ValidatePortNumber(port):

Returns the validated integer port number if it is valid.

Parameters
portthe port number to be validated
Returns
intthe validated value.
Raises
ValueErrorif the port is not valid
def _GetIpAddressesFromIpOutput(ip_output):

Parses the output of the ip command and retrieves the IP addresses and version.

Parameters
ip_outputstring containing the output of the ip command;
Returns
dict; (int, list)a dict having as keys the IP versions and as values the corresponding list of addresses found in the IP output.
_IP_FAMILY_RE =

Undocumented

Value
re.compile('(?P<family>inet6?)\\s+(?P<ip>%s)/'%_IP_RE_TEXT, re.IGNORECASE)
_IP_RE_TEXT: str =

Undocumented

Value
'[.:a-z0-9]+'
_NAME_TO_IP_VER =

Undocumented

Value
{'inet': constants.IP4_VERSION, 'inet6': constants.IP6_VERSION}
_STRUCT_UCRED: str =

Undocumented

Value
'iII'
_STRUCT_UCRED_SIZE =

Undocumented

Value
struct.calcsize(_STRUCT_UCRED)