charmhelpers.contrib.hahelpers package

charmhelpers.contrib.hahelpers.apache module

charmhelpers.contrib.hahelpers.apache.get_ca_cert()
charmhelpers.contrib.hahelpers.apache.get_cert(cn=None)
charmhelpers.contrib.hahelpers.apache.install_ca_cert(ca_cert)
charmhelpers.contrib.hahelpers.apache.retrieve_ca_cert(cert_file)

charmhelpers.contrib.hahelpers.cluster module

Helpers for clustering and determining “cluster leadership” and other clustering-related helpers.

exception charmhelpers.contrib.hahelpers.cluster.CRMDCNotFound

Bases: Exception

exception charmhelpers.contrib.hahelpers.cluster.CRMResourceNotFound

Bases: Exception

exception charmhelpers.contrib.hahelpers.cluster.HAIncompleteConfig

Bases: Exception

exception charmhelpers.contrib.hahelpers.cluster.HAIncorrectConfig

Bases: Exception

charmhelpers.contrib.hahelpers.cluster.canonical_url(configs, vip_setting='vip')

Returns the correct HTTP URL to this host given the state of HTTPS configuration and hacluster.

:configs : OSTemplateRenderer: A config tempating object to inspect for
a complete https context.
Vip_setting:str: Setting in charm config that specifies VIP address.
charmhelpers.contrib.hahelpers.cluster.determine_apache_port(public_port, singlenode_mode=False)

Description: Determine correct apache listening port based on public IP + state of the cluster.

public_port: int: standard public port for given service

singlenode_mode: boolean: Shuffle ports when only a single unit is present

returns: int: the correct listening port for the HAProxy service

charmhelpers.contrib.hahelpers.cluster.determine_apache_port_single(public_port, *, singlenode_mode=True)

Description: Determine correct apache listening port based on public IP + state of the cluster.

public_port: int: standard public port for given service

singlenode_mode: boolean: Shuffle ports when only a single unit is present

returns: int: the correct listening port for the HAProxy service

charmhelpers.contrib.hahelpers.cluster.determine_api_port(public_port, singlenode_mode=False)

Determine correct API server listening port based on existence of HTTPS reverse proxy and/or haproxy.

public_port: int: standard public port for given service

singlenode_mode: boolean: Shuffle ports when only a single unit is present

returns: int: the correct listening port for the API service

charmhelpers.contrib.hahelpers.cluster.distributed_wait(modulo=None, wait=None, operation_name='operation')

Distribute operations by waiting based on modulo_distribution

If modulo and or wait are not set, check config_get for those values. If config values are not set, default to modulo=3 and wait=30.

Parameters:
  • modulo – int The modulo number creates the group distribution
  • wait – int The constant time wait value
  • operation_name – string Operation name for status message i.e. ‘restart’
Side effect:

Calls config_get()

Side effect:

Calls log()

Side effect:

Calls status_set()

Side effect:

Calls time.sleep()

charmhelpers.contrib.hahelpers.cluster.eligible_leader(resource)
charmhelpers.contrib.hahelpers.cluster.get_hacluster_config(exclude_keys=None)

Obtains all relevant configuration from charm configuration required for initiating a relation to hacluster:

ha-bindiface, ha-mcastport, vip, os-internal-hostname, os-admin-hostname, os-public-hostname, os-access-hostname

param: exclude_keys: list of setting key(s) to be excluded. returns: dict: A dict containing settings keyed by setting name. raises: HAIncompleteConfig if settings are missing or incorrect.

charmhelpers.contrib.hahelpers.cluster.get_managed_services_and_ports(services, external_ports, external_services=None, port_conv_f=functools.partial(<function determine_apache_port>, singlenode_mode=True))

Get the services and ports managed by this charm.

Return only the services and corresponding ports that are managed by this charm. This excludes haproxy when there is a relation with hacluster. This is because this charm passes responsability for stopping and starting haproxy to hacluster.

Similarly, if a relation with hacluster exists then the ports returned by this method correspond to those managed by the apache server rather than haproxy.

Parameters:
  • services (List[str]) – List of services.
  • external_ports (List[int]) – List of ports managed by external services.
  • external_services (List[str]) – List of services to be removed if ha relation is present.
  • port_conv_f – Function to apply to ports to calculate the ports managed by services controlled by this charm.
Returns:

A tuple containing a list of services first followed by a list of ports.

Return type:

Tuple[List[str], List[int]]

charmhelpers.contrib.hahelpers.cluster.https()

Determines whether enough data has been provided in configuration or relation data to configure HTTPS . returns: boolean

charmhelpers.contrib.hahelpers.cluster.is_clustered()
charmhelpers.contrib.hahelpers.cluster.is_crm_dc()

Determine leadership by querying the pacemaker Designated Controller

charmhelpers.contrib.hahelpers.cluster.is_elected_leader(resource)

Returns True if the charm executing this is the elected cluster leader.

It relies on two mechanisms to determine leadership:
1. If juju is sufficiently new and leadership election is supported, the is_leader command will be used. 2. If the charm is part of a corosync cluster, call corosync to determine leadership. 3. If the charm is not part of a corosync cluster, the leader is determined as being “the alive unit with the lowest unit numer”. In other words, the oldest surviving unit.
charmhelpers.contrib.hahelpers.cluster.is_leader(resource)
charmhelpers.contrib.hahelpers.cluster.oldest_peer(peers)

Determines who the oldest peer is by comparing unit numbers.

charmhelpers.contrib.hahelpers.cluster.peer_ips(peer_relation='cluster', addr_key='private-address')

Return a dict of peers and their private-address

charmhelpers.contrib.hahelpers.cluster.peer_units(peer_relation='cluster')
charmhelpers.contrib.hahelpers.cluster.valid_hacluster_config()

Check that either vip or dns-ha is set. If dns-ha then one of os-*-hostname must be set.

Note: ha-bindiface and ha-macastport both have defaults and will always be set. We only care that either vip or dns-ha is set.

Returns:boolean: valid config returns true.

raises: HAIncompatibileConfig if settings conflict. raises: HAIncompleteConfig if settings are missing.