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]
dict; (int, list)
_GetIpAddressesFromIpOutput(ip_output)
Parses the output of the ip command and retrieves the IP addresses and version.
source code
tuple; (number, number, number)
GetSocketCredentials(sock)
Returns the credentials of the foreign process connected to a socket.
source code
 
IsValidInterface(ifname)
Validate an interface name.
source code
 
GetInterfaceIpAddresses(ifname)
Returns the IP addresses associated to the interface.
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)
  _IP_RE_TEXT = r"[.:a-z0-9]+"
  _IP_FAMILY_RE = re.compile(r"(?P<family>inet6?)\s+(?P<ip>%s)/"...
  _NAME_TO_IP_VER = {"inet": constants.IP4_VERSION, "inet6": con...

Imports: errno, os, re, socket, struct, IN, logging, constants, errors, utils


Function Details [hide private]

_GetIpAddressesFromIpOutput(ip_output)

source code 

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

Parameters:
  • ip_output - string 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.

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.

IsValidInterface(ifname)

source code 

Validate an interface name.

Parameters:
  • ifname (string) - Name of the network interface
Returns:
boolean indicating whether the interface name is valid or not.

GetInterfaceIpAddresses(ifname)

source code 

Returns the IP addresses associated to the interface.

Parameters:
  • ifname (string) - Name 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

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 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

Variables Details [hide private]

_IP_FAMILY_RE

Value:
re.compile(r"(?P<family>inet6?)\s+(?P<ip>%s)/" % _IP_RE_TEXT, re.IGNOR\
ECASE)

_NAME_TO_IP_VER

Value:
{"inet": constants.IP4_VERSION, "inet6": constants.IP6_VERSION,}