Coverage for cli/main.py: 95.89%

59 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-30 21:22 +0000

1""" 

2GCO CLI - Main entry point. 

3 

4A comprehensive CLI for managing GCO multi-region EKS clusters. 

5 

6Commands: 

7 gco stacks deploy-all -y # Deploy all infrastructure 

8 gco jobs submit-sqs job.yaml -r us-east-1 # Submit job via SQS (recommended) 

9 gco jobs submit job.yaml -n gco-jobs # Submit job via API Gateway 

10 gco jobs list --all-regions # List jobs across regions 

11 gco capacity check -t g4dn.xlarge # Check GPU capacity 

12 gco inference deploy my-llm -i ... # Deploy inference endpoint 

13 gco stacks destroy-all -y # Tear down everything 

14 

15Full reference: docs/CLI.md 

16""" 

17 

18import logging 

19import os 

20 

21import click 

22 

23from . import __version__ 

24from .commands import ( 

25 analytics, 

26 capacity, 

27 cluster, 

28 config_cmd, 

29 costs, 

30 dag, 

31 files, 

32 images, 

33 inference, 

34 jobs, 

35 mission_cmd, 

36 models, 

37 monitoring, 

38 nodepools, 

39 queue, 

40 stacks, 

41 storage, 

42 tasks, 

43 templates, 

44 webhooks, 

45) 

46from .config import get_config 

47 

48 

49def _configure_cli_logging(verbose: bool) -> None: 

50 """ 

51 Configure logging for the CLI. 

52 

53 By default, the CLI is quiet: only WARNING and above from our own code, 

54 and the chatty AWS SDK / HTTP stack loggers (``botocore``, ``boto3``, 

55 ``urllib3``, ``s3transfer``, ``kubernetes``) are pinned at WARNING so 

56 credential-discovery INFO messages and retry-attempt INFO messages don't 

57 clutter normal output. 

58 

59 ``--verbose`` / ``-v`` (or ``GCO_LOG_LEVEL=DEBUG``) turns on DEBUG for 

60 everything, which is the right escape hatch when something is actually 

61 wrong and you need to see what the SDK is doing. 

62 

63 This function also calls ``logging.basicConfig`` with ``force=True`` so 

64 it overrides any ``basicConfig`` that might have been called at import 

65 time by a library module (the CLI owns its log configuration). 

66 """ 

67 env_level = os.environ.get("GCO_LOG_LEVEL") 

68 if verbose or (env_level and env_level.upper() == "DEBUG"): 

69 level = logging.DEBUG 

70 elif env_level: 70 ↛ 71line 70 didn't jump to line 71 because the condition on line 70 was never true

71 level = getattr(logging, env_level.upper(), logging.WARNING) 

72 else: 

73 level = logging.WARNING 

74 

75 logging.basicConfig( 

76 level=level, 

77 format="%(asctime)s %(levelname)s %(name)s: %(message)s", 

78 force=True, 

79 ) 

80 

81 # Pin noisy third-party loggers even when we're at DEBUG, unless the 

82 # user explicitly asked for verbose output. This keeps ``-v`` useful 

83 # for seeing OUR logs without being drowned by boto's retry chatter. 

84 third_party_level = logging.DEBUG if verbose else logging.WARNING 

85 for name in ("botocore", "boto3", "urllib3", "s3transfer", "kubernetes"): 

86 logging.getLogger(name).setLevel(third_party_level) 

87 

88 

89@click.group() 

90@click.version_option(version=__version__, prog_name="gco") 

91@click.option("--config", "-c", "config_file", help="Path to config file") 

92@click.option("--region", "-r", "default_region", help="Default AWS region") 

93@click.option( 

94 "--output", 

95 "-o", 

96 "output_format", 

97 type=click.Choice(["table", "json", "yaml"]), 

98 default=None, 

99 help="Output format (defaults to the configured value)", 

100) 

101@click.option("--verbose", "-v", is_flag=True, default=None, help="Verbose output") 

102@click.option( 

103 "--regional-api/--global-api", 

104 default=None, 

105 help="Use regional API endpoints, or explicitly use the global endpoint", 

106) 

107@click.pass_context 

108def cli( 

109 ctx: click.Context, 

110 config_file: str | None, 

111 default_region: str | None, 

112 output_format: str | None, 

113 verbose: bool | None, 

114 regional_api: bool | None, 

115) -> None: 

116 """GCO CLI - Manage multi-region EKS clusters for AI/ML workloads.""" 

117 config = get_config(config_file) 

118 

119 if default_region: 

120 config.default_region = default_region 

121 if output_format: 

122 config.output_format = output_format 

123 if verbose is not None: 

124 config.verbose = verbose 

125 if regional_api is not None: 

126 config.use_regional_api = regional_api 

127 

128 _configure_cli_logging(config.verbose) 

129 ctx.obj = config 

130 

131 

132# Register command groups 

133cli.add_command(jobs) 

134cli.add_command(dag) 

135cli.add_command(queue) 

136cli.add_command(templates) 

137cli.add_command(webhooks) 

138cli.add_command(capacity) 

139cli.add_command(cluster) 

140cli.add_command(inference) 

141cli.add_command(images) 

142cli.add_command(models) 

143cli.add_command(nodepools) 

144cli.add_command(costs) 

145cli.add_command(stacks) 

146cli.add_command(storage) 

147cli.add_command(files) 

148cli.add_command(config_cmd) 

149cli.add_command(analytics) 

150cli.add_command(monitoring) 

151cli.add_command(tasks) 

152cli.add_command(mission_cmd) 

153 

154 

155def main() -> None: 

156 """Main entry point for the CLI.""" 

157 cli(obj=None) 

158 

159 

160if __name__ == "__main__": 

161 main()