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]
  HostInfo
Class implementing resolver and hostname functionality
Functions [hide private]
tuple; (number, number, number)
GetSocketCredentials(sock)
Returns the credentials of the foreign process connected to a socket.
source code
 
GetHostInfo(name=None)
Lookup host name and raise an OpPrereqError for failures
source code
boolean
_GenericIsValidIP(family, ip)
Generic internal version of ip validation.
source code
boolean
IsValidIP4(ip)
Verifies an IPv4 address.
source code
boolean
IsValidIP6(ip)
Verifies an IPv6 address.
source code
boolean
IsValidIP(ip)
Verifies an IP address.
source code
int
GetAddressFamily(ip)
Get the address family of the given address.
source code
 
TcpPing(target, port, timeout=10, live_port_needed=False, source=None)
Simple ping implementation using TCP connect(2).
source code
bool
OwnIpAddress(address)
Check if the current host has the the given IP address.
source code
int
GetDaemonPort(daemon_name)
Get the daemon port for this cluster.
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.

_GenericIsValidIP(family, ip)

source code 

Generic internal version of ip validation.

Parameters:
  • family (int) - socket.AF_INET | socket.AF_INET6
  • ip (str) - the address to be checked
Returns: boolean
True if ip is valid, False otherwise

IsValidIP4(ip)

source code 

Verifies an IPv4 address.

This function checks if the given address is a valid IPv4 address.

Parameters:
  • ip (str) - the address to be checked
Returns: boolean
True if ip is valid, False otherwise

IsValidIP6(ip)

source code 

Verifies an IPv6 address.

This function checks if the given address is a valid IPv6 address.

Parameters:
  • ip (str) - the address to be checked
Returns: boolean
True if ip is valid, False otherwise

IsValidIP(ip)

source code 

Verifies an IP address.

This function checks if the given IP address (both IPv4 and IPv6) is valid.

Parameters:
  • ip (str) - the address to be checked
Returns: boolean
True if ip is valid, False otherwise

GetAddressFamily(ip)

source code 

Get the address family of the given address.

Parameters:
  • ip (str) - ip address whose family will be returned
Returns: int
socket.AF_INET or socket.AF_INET6
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

OwnIpAddress(address)

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 (string) - the address to check
Returns: bool
True if we own the address

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