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

Module bootstrap

source code

Functions to bootstrap a new cluster.

Functions [hide private]
 
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, new_client_cert, master_name, rapi_cert_pem=None, spice_cert_pem=None, spice_cacert_pem=None, cds=None, nodecert_file=pathutils.NODED_CERT_FILE, clientcert_file=pathutils.NODED_CLIENT_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, cfg)
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)
Wait for SSH daemon to become responsive.
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, _storage_path_acceptance_fn, 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
 
_PrepareGlusterStorage(enabled_disk_templates, file_storage_dir, init_fn=_InitFileStorageDir, acceptance_fn=None)
Checks if gluster 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
 
_InitCheckDrbdHelper(drbd_helper, drbd_enabled)
Checks the DRBD usermode helper.
source code
 
InitCluster(cluster_name, mac_prefix, master_netmask, master_netdev, file_storage_dir, shared_file_storage_dir, gluster_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, default_iallocator_params=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, install_image=None, zeroing_image=None, compression_tools=None, enabled_user_shutdown=False)
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, ssh_port)
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
 
MajorityHealthy()
Check if the majority of nodes is healthy
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, cluster, rpc, ssh, utils, errors, config, constants, objects, ssconf, serializer, hypervisor, drbd, filestorage, netutils, luxi, jstore, pathutils, runtime, vcluster


Function Details [hide private]

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, new_client_cert, master_name, rapi_cert_pem=None, spice_cert_pem=None, spice_cacert_pem=None, cds=None, nodecert_file=pathutils.NODED_CERT_FILE, clientcert_file=pathutils.NODED_CLIENT_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
  • new_client_cert (bool) - Whether to generate a new client certificate
  • master_name (string) - FQDN of the master node
  • 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, cfg)

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
  • cfg (ConfigWriter) - the configuration writer

_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, _storage_path_acceptance_fn, 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', 'ST_SHARED_FILE' or 'ST_GLUSTER'
  • _storage_path_acceptance_fn (function) - checks whether the given file-based storage directory is acceptable
Returns: string
the name of the actual file storage directory

See Also: cluster.CheckFileBasedStoragePathVsEnabledDiskTemplates for details

_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

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

source code 

Checks if gluster 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

_InitCheckDrbdHelper(drbd_helper, drbd_enabled)

source code 

Checks the DRBD usermode helper.

Parameters:
  • drbd_helper (string) - name of the DRBD usermode helper that the system should use

InitCluster(cluster_name, mac_prefix, master_netmask, master_netdev, file_storage_dir, shared_file_storage_dir, gluster_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, default_iallocator_params=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, install_image=None, zeroing_image=None, compression_tools=None, enabled_user_shutdown=False)

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
  • enabled_user_shutdown (bool) - whether user shutdown is enabled cluster wide

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, ssh_port)

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
  • ssh_port - the SSH port 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)
Returns:
the pair of an exit code and warnings to display

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

Parameters:
  • node_names (list) - the list of nodes to query for master info
Returns: list
list of (node, votes)

MajorityHealthy()

source code 

Check if the majority of nodes is healthy

Gather master votes from all nodes known to this node; return True if a strict majority of nodes is reachable and has some opinion on which node is master. Note that this will not guarantee any node to win an election but it ensures that a standard master-failover is still possible.