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

Module vcluster

source code

Module containing utilities for virtual clusters.

Most functions manipulate file system paths and are no-ops when the environment variables GANETI_ROOTDIR and GANETI_HOSTNAME are not set. See the functions' docstrings for details.

Functions [hide private]
string
_GetRootDirectory(envname)
Retrieves root directory from an environment variable.
source code
string
_GetHostname(envname)
Retrieves virtual hostname from an environment variable.
source code
 
_CheckHostname(hostname)
Very basic check for hostnames.
source code
tuple; (string, string, string or None)
_PreparePaths(rootdir, hostname)
Checks if the root directory and hostname are acceptable.
source code
string or None
GetVirtualHostname()
Returns the virtual hostname.
source code
 
MakeNodeRoot(base, node_name)
Appends a node name to the base directory.
source code
 
ExchangeNodeRoot(node_name, filename, _basedir=_VIRT_BASEDIR, _noderoot=_VIRT_NODEROOT)
Replaces the node-specific root directory in a path.
source code
 
EnvironmentForHost(hostname, _basedir=_VIRT_BASEDIR)
Returns the environment variables for a host.
source code
 
AddNodePrefix(path, _noderoot=_VIRT_NODEROOT)
Adds a node-specific prefix to a path in a virtual cluster.
source code
 
_RemoveNodePrefix(path, _noderoot=_VIRT_NODEROOT)
Removes the node-specific prefix from a path.
source code
 
MakeVirtualPath(path, _noderoot=_VIRT_NODEROOT)
Virtualizes a path.
source code
 
LocalizeVirtualPath(path, _noderoot=_VIRT_NODEROOT)
Localizes a virtual path.
source code
Variables [hide private]
  ETC_HOSTS = "/etc/hosts"
  _VIRT_PATH_PREFIX = "/###-VIRTUAL-PATH-###,"
  _ROOTDIR_ENVNAME = "GANETI_ROOTDIR"
  _HOSTNAME_ENVNAME = "GANETI_HOSTNAME"
  _VPATH_WHITELIST = frozenset(["/etc/hosts"])
List of paths which shouldn't be virtualized

Imports: os, compat, _constants


Function Details [hide private]

_GetRootDirectory(envname)

source code 

Retrieves root directory from an environment variable.

Parameters:
  • envname (string) - Environment variable name
Returns: string
Root directory (can be empty)

_GetHostname(envname)

source code 

Retrieves virtual hostname from an environment variable.

Parameters:
  • envname (string) - Environment variable name
Returns: string
Host name (can be empty)

_CheckHostname(hostname)

source code 

Very basic check for hostnames.

Parameters:
  • hostname (string) - Hostname

_PreparePaths(rootdir, hostname)

source code 

Checks if the root directory and hostname are acceptable.

The (node-specific) root directory must have the hostname as its last component. The parent directory then becomes the cluster-wide root directory. This is necessary as some components must be able to predict the root path on a remote node (e.g. copying files via scp).

Parameters:
  • rootdir (string) - Root directory (from environment)
  • hostname (string) - Hostname (from environment)
Returns: tuple; (string, string, string or None)
Tuple containing cluster-global root directory, node root directory and virtual hostname

ExchangeNodeRoot(node_name, filename, _basedir=_VIRT_BASEDIR, _noderoot=_VIRT_NODEROOT)

source code 

Replaces the node-specific root directory in a path.

Replaces it with the root directory for another node. Assuming /tmp/vcluster/node1 is the root directory for node1, the result will be /tmp/vcluster/node3 for node3 (as long as a root directory is specified in the environment).

AddNodePrefix(path, _noderoot=_VIRT_NODEROOT)

source code 

Adds a node-specific prefix to a path in a virtual cluster.

Returned path includes user-specified root directory if specified in environment. As an example, the path /var/lib/ganeti becomes /tmp/vcluster/node1/var/lib/ganeti if /tmp/vcluster/node1 is the root directory specified in the environment.

_RemoveNodePrefix(path, _noderoot=_VIRT_NODEROOT)

source code 

Removes the node-specific prefix from a path.

This is the opposite of AddNodePrefix and removes a node-local prefix path.

MakeVirtualPath(path, _noderoot=_VIRT_NODEROOT)

source code 

Virtualizes a path.

A path is "virtualized" by stripping it of its node-specific directory and prepending a prefix (_VIRT_PATH_PREFIX). Use LocalizeVirtualPath to undo the process. Virtual paths are meant to be transported via RPC.

LocalizeVirtualPath(path, _noderoot=_VIRT_NODEROOT)

source code 

Localizes a virtual path.

A "virtualized" path consists of a prefix (LocalizeVirtualPath) and a local path. This function adds the node-specific directory to the local path. Virtual paths are meant to be transported via RPC.