infrahouse_core.orchestrator package

Submodules

infrahouse_core.orchestrator.exceptions module

Top level exceptions.

The exception hierarchy repeats the structure of the infrahouse_core package. Each module in the package has its own exceptions.py module. The module exceptions are inherited from the upper module exceptions.

exception infrahouse_core.orchestrator.exceptions.IHOrchestratorException[source]

Bases: IHCoreException

Orchestrator related InfraHouse exception

exception infrahouse_core.orchestrator.exceptions.IHRaftLeaderNotFound[source]

Bases: IHOrchestratorException

No Raft leader could be found among the known nodes

exception infrahouse_core.orchestrator.exceptions.IHRaftPeerError[source]

Bases: IHOrchestratorException

A raft-add-peer or raft-remove-peer call failed

infrahouse_core.orchestrator.raft_cluster module

Module for OrchestratorRaftCluster — ties Raft membership to an ASG.

class infrahouse_core.orchestrator.raft_cluster.OrchestratorRaftCluster(asg_name, region=None, role_arn=None, session=None, http_port=3000, raft_port=10008)[source]

Bases: object

Ties MySQL Orchestrator Raft membership to an AWS Auto Scaling Group.

Creates one OrchestratorRaftNode per live ASG instance and provides methods to add/remove peers and reconcile the full Raft peer list against the live ASG membership.

Commands are executed on instances via SSM, so the caller does not need direct network access to the Orchestrator HTTP port.

Parameters:
  • asg_name (str) – Name of the Auto Scaling Group running Orchestrator.

  • region (str) – AWS region.

  • role_arn (str) – IAM role ARN for cross-account access.

  • session – Pre-configured boto3.Session.

  • http_port (int) – Orchestrator HTTP API port.

  • raft_port (int) – Raft protocol port.

add_peer(node)[source]

Add a peer to the Raft cluster.

Parameters:

node (OrchestratorRaftNode) – The node to add.

Raises:
property leader

Return the OrchestratorRaftNode that is the current Raft leader.

Queries each live ASG instance until one responds with a non-nil leader. All mutation operations (add/remove peer) should be sent to the leader.

Return type:

OrchestratorRaftNode

Raises:

IHRaftLeaderNotFound – If no node reports a leader.

property nodes

Return an OrchestratorRaftNode for each queryable ASG instance.

Instances in early lifecycle states (Pending, Pending:Wait, etc.) are excluded because they have no SSM agent or Orchestrator running yet.

Return type:

list[OrchestratorRaftNode]

property peers

Return the current Raft peer list from the leader as node objects.

Live ASG instances are returned as full nodes; stale peers (terminated instances no longer in the ASG) are returned as instance-less nodes created via OrchestratorRaftNode.from_peer_addr().

Return type:

list[OrchestratorRaftNode]

reconcile()[source]

Reconcile the Raft peer list against the live ASG membership.

  1. Collect the hostnames of all currently live ASG instances.

  2. Collect the hostnames from the leader’s Raft peer list.

  3. Remove stale peers (in Raft but not in ASG) by their Raft address.

  4. Add missing peers (in ASG but not in Raft) via their node objects.

Raises:
remove_peer(node)[source]

Remove a peer from the Raft cluster.

Parameters:

node (OrchestratorRaftNode) – The node to remove.

Raises:

infrahouse_core.orchestrator.raft_node module

Module for OrchestratorRaftNode — wraps a single Orchestrator node’s HTTP API via SSM.

class infrahouse_core.orchestrator.raft_node.OrchestratorRaftNode(instance=None, http_port=3000, raft_port=10008, hostname=None)[source]

Bases: object

Wraps the HTTP API of a single MySQL Orchestrator node.

Commands are executed on the instance via SSM (execute_command), so the caller does not need direct network access to the Orchestrator HTTP port.

A node may also represent a stale Raft peer whose EC2 instance no longer exists. Use from_peer_addr() to create such a node. Stale nodes expose hostname and peer_addr but cannot execute API calls.

Parameters:
  • instance (infrahouse_core.aws.asg_instance.ASGInstance or None) – An ASG instance running Orchestrator, or None for stale peers.

  • http_port (int) – Orchestrator HTTP API port.

  • raft_port (int) – Raft protocol port.

add_peer(peer)[source]

Add a peer to this node’s Raft cluster.

Parameters:

peer (OrchestratorRaftNode) – The node to add.

Raises:

IHRaftPeerError – If Orchestrator reports a failure.

classmethod from_peer_addr(peer_addr)[source]

Create a node from a Raft peer address string.

Useful for representing stale peers that no longer have a live EC2 instance.

Parameters:

peer_addr (str) – Raft peer address, e.g. "ip-10-1-100-195:10008".

Return type:

OrchestratorRaftNode

property hostname

Return the short private hostname of the underlying EC2 instance.

This is what Orchestrator uses as the Raft node identifier, e.g. "ip-10-1-100-195".

property instance

Return the underlying ASGInstance, or None for stale peers.

property is_leader

Return True if this node believes itself to be the Raft leader.

Return type:

bool

property peer_addr

Return the Raft peer address for this node in hostname:raft_port form.

Return type:

str

property private_ip

Return the private IP address of the underlying EC2 instance.

Raises:

AttributeError – If the node has no live instance (stale peer).

raft_health[source]

Retrieve the Raft health status from this node.

Returns:

Raft health payload as returned by Orchestrator.

Return type:

dict

Raises:

IHRaftPeerError – If the command fails.

raft_leader[source]

Retrieve the current Raft leader address as seen by this node.

Returns:

Leader address ("hostname:raft_port"), or None if no leader is currently elected.

Return type:

str or None

Raises:

IHRaftPeerError – If the command fails.

raft_peers[source]

Retrieve the current Raft peer list from this node.

Returns:

List of peer addresses, e.g. ["ip-10-1-100-195:10008", ...].

Return type:

list[str]

Raises:

IHRaftPeerError – If the command fails.

remove_peer(peer)[source]

Remove a peer from this node’s Raft cluster.

Parameters:

peer (OrchestratorRaftNode) – The node to remove.

Raises:

IHRaftPeerError – If Orchestrator reports a failure.

Module contents

Orchestrator Raft management classes.