Coverage for src/tagmania/start_cluster.py: 92%
12 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-02 01:51 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-02 01:51 +0000
1"""AWS Cluster Start CLI.
3This module provides a command-line interface for starting all EC2 instances
4in a cluster identified by their "Cluster" tag. It's a simple utility that
5starts all stopped instances in the specified cluster.
7The tool relies on EC2 instances having "Cluster" tags to identify which
8instances belong to the cluster that should be started.
10Features:
11 - Start all instances in a cluster simultaneously
12 - Support for AWS profile selection
13 - Simple command-line interface
14 - Confirmation message on completion
16Usage:
17 The module is typically invoked via the cluster-start CLI command:
19 ```bash
20 # Start a cluster using default AWS profile
21 cluster-start production-web
23 # Start a cluster using specific AWS profile
24 cluster-start --profile myprofile production-web
25 ```
27Note:
28 This operation starts all instances in the cluster regardless of their
29 current state. Running instances are not affected.
30"""
32import argparse
34from tagmania.iac_tools.clusterset import ClusterSet
37def main():
38 """Main entry point for the cluster start CLI.
40 Parses command line arguments to identify the cluster name and optional
41 AWS profile, then starts all EC2 instances in the specified cluster.
43 Args:
44 Command line arguments are parsed internally:
45 - cluster: Name of the cluster to start (required)
46 - --profile: AWS profile to use (optional)
48 Raises:
49 SystemExit: On invalid command line arguments.
50 AWSError: On AWS API failures during instance start operations.
51 """
52 parser = argparse.ArgumentParser(
53 description="AWS cluster start tool.",
54 epilog='This tool relies on the "Cluster" and "Owner" tags on instances and '
55 "volumes. IAC automation puts this in place."
56 "Starts the cluster CLUSTER.",
57 )
58 parser.add_argument(
59 "cluster",
60 help="the name CLUSTER of the cluster in question. This can be found by looking at any node "
61 'in the AWS console and looking for the "Cluster" tag.',
62 )
64 parser.add_argument("--profile", "-p", help="the AWS profile to use", default=None)
65 args = parser.parse_args()
67 cluster = ClusterSet(args.cluster, profile=args.profile)
68 cluster.start_instances()
69 print(f"Cluster {cluster.cluster_names} started successfully.")
72if __name__ == "__main__":
73 main()