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

Module bootstrap

source code

Functions to bootstrap a new cluster.

Functions [hide private]
 
_InitSSHSetup()
Setup the SSH configuration for the cluster.
source code
 
GenerateHmacKey(file_name)
Writes a new HMAC key.
source code
 
GenerateClusterCrypto(new_cluster_cert, new_rapi_cert, new_spice_cert, new_confd_hmac_key, new_cds, rapi_cert_pem=None, spice_cert_pem=None, spice_cacert_pem=None, cds=None, nodecert_file=pathutils.NODED_CERT_FILE, rapicert_file=pathutils.RAPI_CERT_FILE, spicecert_file=pathutils.SPICE_CERT_FILE, spicecacert_file=pathutils.SPICE_CACERT_FILE, hmackey_file=pathutils.CONFD_HMAC_KEY, cds_file=pathutils.CLUSTER_DOMAIN_SECRET_FILE)
Updates the cluster certificates, keys and secrets.
source code
 
_InitGanetiServerSetup(master_name)
Setup the necessary configuration for the initial node daemon.
source code
 
_WaitForNodeDaemon(node_name)
Wait for node daemon to become responsive.
source code
 
_WaitForMasterDaemon()
Wait for master daemon to become responsive.
source code
 
_WaitForSshDaemon(hostname, port, family)
Wait for SSH daemon to become responsive.
source code
 
RunNodeSetupCmd(cluster_name, node, basecmd, debug, verbose, use_cluster_key, ask_key, strict_host_check, data)
Runs a command to configure something on a remote machine.
source code
 
_InitFileStorageDir(file_storage_dir)
Initialize if needed the file storage.
source code
string
_PrepareFileBasedStorage(enabled_disk_templates, file_storage_dir, default_dir, file_disk_template, init_fn=_InitFileStorageDir, acceptance_fn=None)
Checks if a file-base storage type is enabled and inits the dir.
source code
 
_PrepareFileStorage(enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, acceptance_fn=None)
Checks if file storage is enabled and inits the dir.
source code
 
_PrepareSharedFileStorage(enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, acceptance_fn=None)
Checks if shared file storage is enabled and inits the dir.
source code
 
_InitCheckEnabledDiskTemplates(enabled_disk_templates)
Checks the sanity of the enabled disk templates.
source code
 
_RestrictIpolicyToEnabledDiskTemplates(ipolicy, enabled_disk_templates)
Restricts the ipolicy's disk templates to the enabled ones.
source code
 
InitCluster(cluster_name, mac_prefix, master_netmask, master_netdev, file_storage_dir, shared_file_storage_dir, candidate_pool_size, secondary_ip=None, vg_name=None, beparams=None, nicparams=None, ndparams=None, hvparams=None, diskparams=None, enabled_hypervisors=None, modify_etc_hosts=True, modify_ssh_setup=True, maintain_node_health=False, drbd_helper=None, uid_pool=None, default_iallocator=None, primary_ip_version=None, ipolicy=None, prealloc_wipe_disks=False, use_external_mip_script=False, hv_state=None, disk_state=None, enabled_disk_templates=None)
Initialise the cluster.
source code
 
InitConfig(version, cluster_config, master_node_config, cfg_file=pathutils.CLUSTER_CONF_FILE)
Create the initial cluster configuration.
source code
 
FinalizeClusterDestroy(master_uuid)
Execute the last steps of cluster destroy
source code
 
SetupNodeDaemon(opts, cluster_name, node)
Add a node to the cluster.
source code
 
MasterFailover(no_voting=False)
Failover the master node.
source code
 
GetMaster()
Returns the current master node.
source code
list
GatherMasterVotes(node_names)
Check the agreement on who is the master.
source code
Variables [hide private]
  _INITCONF_ECID = "initconfig-ecid"
  _DAEMON_READY_TIMEOUT = 10.0
After how many seconds daemon must be responsive

Imports: os, re, logging, time, tempfile, cluster, rpc, ssh, utils, errors, config, constants, objects, ssconf, serializer, hypervisor, drbd, filestorage, netutils, luxi, jstore, pathutils


Function Details [hide private]

_InitSSHSetup()

source code 

Setup the SSH configuration for the cluster.

This generates a dsa keypair for root, adds the pub key to the permitted hosts and adds the hostkey to its own known hosts.

GenerateHmacKey(file_name)

source code 

Writes a new HMAC key.

Parameters:
  • file_name (str) - Path to output file

GenerateClusterCrypto(new_cluster_cert, new_rapi_cert, new_spice_cert, new_confd_hmac_key, new_cds, rapi_cert_pem=None, spice_cert_pem=None, spice_cacert_pem=None, cds=None, nodecert_file=pathutils.NODED_CERT_FILE, rapicert_file=pathutils.RAPI_CERT_FILE, spicecert_file=pathutils.SPICE_CERT_FILE, spicecacert_file=pathutils.SPICE_CACERT_FILE, hmackey_file=pathutils.CONFD_HMAC_KEY, cds_file=pathutils.CLUSTER_DOMAIN_SECRET_FILE)

source code 

Updates the cluster certificates, keys and secrets.

Parameters:
  • new_cluster_cert (bool) - Whether to generate a new cluster certificate
  • new_rapi_cert (bool) - Whether to generate a new RAPI certificate
  • new_spice_cert (bool) - Whether to generate a new SPICE certificate
  • new_confd_hmac_key (bool) - Whether to generate a new HMAC key
  • new_cds (bool) - Whether to generate a new cluster domain secret
  • rapi_cert_pem (string) - New RAPI certificate in PEM format
  • spice_cert_pem (string) - New SPICE certificate in PEM format
  • spice_cacert_pem (string) - Certificate of the CA that signed the SPICE certificate, in PEM format
  • cds (string) - New cluster domain secret
  • nodecert_file (string) - optional override of the node cert file path
  • rapicert_file (string) - optional override of the rapi cert file path
  • spicecert_file (string) - optional override of the spice cert file path
  • spicecacert_file (string) - optional override of the spice CA cert file path
  • hmackey_file (string) - optional override of the hmac key file path

_InitGanetiServerSetup(master_name)

source code 

Setup the necessary configuration for the initial node daemon.

This creates the nodepass file containing the shared password for the cluster, generates the SSL certificate and starts the node daemon.

Parameters:
  • master_name (str) - Name of the master node

RunNodeSetupCmd(cluster_name, node, basecmd, debug, verbose, use_cluster_key, ask_key, strict_host_check, data)

source code 

Runs a command to configure something on a remote machine.

Parameters:
  • cluster_name (string) - Cluster name
  • node (string) - Node name
  • basecmd (string) - Base command (path on the remote machine)
  • debug (bool) - Enable debug output
  • verbose (bool) - Enable verbose output
  • use_cluster_key (bool) - See ssh.SshRunner.BuildCmd
  • ask_key (bool) - See ssh.SshRunner.BuildCmd
  • strict_host_check (bool) - See ssh.SshRunner.BuildCmd
  • data - JSON-serializable input data for script (passed to stdin)

_InitFileStorageDir(file_storage_dir)

source code 

Initialize if needed the file storage.

Parameters:
  • file_storage_dir - the user-supplied value
Returns:
either empty string (if file storage was disabled at build time) or the normalized path to the storage directory

_PrepareFileBasedStorage(enabled_disk_templates, file_storage_dir, default_dir, file_disk_template, init_fn=_InitFileStorageDir, acceptance_fn=None)

source code 

Checks if a file-base storage type is enabled and inits the dir.

Parameters:
  • enabled_disk_templates (list of string) - list of enabled disk templates
  • file_storage_dir (string) - the file storage directory
  • default_dir (string) - default file storage directory when file_storage_dir is 'None'
  • file_disk_template (string) - a disk template whose storage type is 'ST_FILE'
Returns: string
the name of the actual file storage directory

_PrepareFileStorage(enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, acceptance_fn=None)

source code 

Checks if file storage is enabled and inits the dir.

See Also: _PrepareFileBasedStorage

_PrepareSharedFileStorage(enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, acceptance_fn=None)

source code 

Checks if shared file storage is enabled and inits the dir.

See Also: _PrepareFileBasedStorage

_RestrictIpolicyToEnabledDiskTemplates(ipolicy, enabled_disk_templates)

source code 

Restricts the ipolicy's disk templates to the enabled ones.

This function clears the ipolicy's list of allowed disk templates from the ones that are not enabled by the cluster.

Parameters:
  • ipolicy (dict) - the instance policy
  • enabled_disk_templates (list of string) - the list of cluster-wide enabled disk templates

InitCluster(cluster_name, mac_prefix, master_netmask, master_netdev, file_storage_dir, shared_file_storage_dir, candidate_pool_size, secondary_ip=None, vg_name=None, beparams=None, nicparams=None, ndparams=None, hvparams=None, diskparams=None, enabled_hypervisors=None, modify_etc_hosts=True, modify_ssh_setup=True, maintain_node_health=False, drbd_helper=None, uid_pool=None, default_iallocator=None, primary_ip_version=None, ipolicy=None, prealloc_wipe_disks=False, use_external_mip_script=False, hv_state=None, disk_state=None, enabled_disk_templates=None)

source code 

Initialise the cluster.

Parameters:
  • candidate_pool_size (int) - master candidate pool size
  • enabled_disk_templates (list of string) - list of disk_templates to be used in this cluster

InitConfig(version, cluster_config, master_node_config, cfg_file=pathutils.CLUSTER_CONF_FILE)

source code 

Create the initial cluster configuration.

It will contain the current node, which will also be the master node, and no instances.

Parameters:
  • version (int) - configuration version
  • cluster_config (objects.Cluster) - cluster configuration
  • master_node_config (objects.Node) - master node configuration
  • cfg_file (string) - configuration file path

FinalizeClusterDestroy(master_uuid)

source code 

Execute the last steps of cluster destroy

This function shuts down all the daemons, completing the destroy begun in cmdlib.LUDestroyOpcode.

SetupNodeDaemon(opts, cluster_name, node)

source code 

Add a node to the cluster.

This function must be called before the actual opcode, and will ssh to the remote node, copy the needed files, and start ganeti-noded, allowing the master to do the rest via normal rpc calls.

Parameters:
  • cluster_name - the cluster name
  • node - the name of the new node

MasterFailover(no_voting=False)

source code 

Failover the master node.

This checks that we are not already the master, and will cause the current master to cease being master, and the non-master to become new master.

Parameters:
  • no_voting (boolean) - force the operation without remote nodes agreement (dangerous)

GetMaster()

source code 

Returns the current master node.

This is a separate function in bootstrap since it's needed by gnt-cluster, and instead of importing directly ssconf, it's better to abstract it in bootstrap, where we do use ssconf in other functions too.

GatherMasterVotes(node_names)

source code 

Check the agreement on who is the master.

This function will return a list of (node, number of votes), ordered by the number of votes. Errors will be denoted by the key 'None'.

Note that the sum of votes is the number of nodes this machine knows, whereas the number of entries in the list could be different (if some nodes vote for another master).

We remove ourselves from the list since we know that (bugs aside) since we use the same source for configuration information for both backend and boostrap, we'll always vote for ourselves.

Parameters:
  • node_names (list) - the list of nodes to query for master info; the current node will be removed if it is in the list
Returns: list
list of (node, votes)