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.
dict; (int, list)
|
|
tuple; (number, number, number)
|
|
|
|
|
|
Hostname
|
|
int
|
|
|
TcpPing(target,
port,
timeout=10,
live_port_needed=False,
source=None)
Simple ping implementation using TCP connect(2). |
source code
|
|
int
|
|
|
|
|
_STRUCT_UCRED = "iII"
|
|
_STRUCT_UCRED_SIZE = struct.calcsize(_STRUCT_UCRED)
|
|
_SO_PEERCRED = 17
|
|
_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,
vcluster
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.
|
Returns the credentials of the foreign process connected to a
socket.
- Parameters:
- Returns: tuple; (number, number, number)
- The PID, UID and GID of the connected foreign process.
|
Validate an interface name.
- Parameters:
ifname (string) - Name of the network interface
- Returns:
- boolean indicating whether the interface name is valid or not.
|
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
|
Returns a Hostname object.
- Parameters:
name (str) - hostname or None
family (int) - AF_INET | AF_INET6 | None
- Returns: Hostname
- Hostname object
- Raises:
|
Returns the validated integer port number if it is valid.
- Parameters:
port - the port number to be validated
- Returns: int
- the validated value.
- Raises:
ValueError - if the port is not valid
|
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
|
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
|
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
|
_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,}
|
|