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

Module netutils

source code

Ganeti network utility module.

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

Classes [hide private]
  Hostname
Class implementing resolver and hostname functionality.
  IPAddress
Class that represents an IP address.
  IP4Address
IPv4 address class.
  IP6Address
IPv6 address class.
Functions [hide private]
tuple; (number, number, number)
GetSocketCredentials(sock)
Returns the credentials of the foreign process connected to a socket.
source code
Hostname
GetHostname(name=None, family=None)
Returns a Hostname object.
source code
 
TcpPing(target, port, timeout=10, live_port_needed=False, source=None)
Simple ping implementation using TCP connect(2).
source code
int
GetDaemonPort(daemon_name)
Get the daemon port for this cluster.
source code
 
FormatAddress(address, family=None)
Format a socket address
source code
Variables [hide private]
  _STRUCT_UCRED = "iII"
  _STRUCT_UCRED_SIZE = struct.calcsize(_STRUCT_UCRED)

Imports: errno, re, socket, struct, IN, constants, errors


Function Details [hide private]

GetSocketCredentials(sock)

source code 

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

Parameters:
  • sock - Unix socket
Returns: tuple; (number, number, number)
The PID, UID and GID of the connected foreign process.

GetHostname(name=None, family=None)

source code 

Returns a Hostname object.

Parameters:
  • name (str) - hostname or None
  • family (int) - AF_INET | AF_INET6 | None
Returns: Hostname
Hostname object
Raises:

TcpPing(target, port, timeout=10, live_port_needed=False, source=None)

source code 

Simple ping implementation using TCP connect(2).

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

Parameters:
  • target (str) - the IP or hostname to ping
  • port (int) - the port to connect to
  • timeout (int) - the timeout on the connection attempt
  • live_port_needed (boolean) - whether a closed port will cause the function to return failure, as if there was a timeout
  • source (str or None) - if specified, will cause the connect to be made from this specific source address; failures to bind other than EADDRNOTAVAIL will be ignored

GetDaemonPort(daemon_name)

source code 

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 (string) - daemon name (in constants.DAEMONS_PORTS)
Returns: int

FormatAddress(address, family=None)

source code 

Format a socket address

Parameters:
  • address (family specific (usually tuple)) - address, as reported by this class
  • family (integer) - socket family (one of socket.AF_*) or None