marin-core 0.2.270.dev43348799107
Basename is uppercase README.mdCalls glob for filename search
SHA-256f16fc1865672ec66c710abd5cddc7c56c17740d1c32379a1168793be81f10072
Evidence
1# Copyright The Marin Authors
2# SPDX-License-Identifier: Apache-2.0
1# Copyright The Marin Authors
2# SPDX-License-Identifier: Apache-2.0
3
4"""Unified cluster management utilities."""
5
6from . import gcp
7
8__all__ = [
9 "gcp",
10]
1# Copyright The Marin Authors
2# SPDX-License-Identifier: Apache-2.0
3
4"""GCP utilities for cluster management.
5
6This provides functions to get access to the current GCP configuration, list
7TPUs, and find TPUs or VMs by name or IP address.
8"""
9
10import json
11import logging
12import subprocess
13from typing import Any
14
15logger = logging.getLogger(__name__)
16
17
18def run_gcloud_command(cmd: list[str], **kwargs) -> subprocess.CompletedProcess:
19 """Run a gcloud command with error handling."""
20 try:
21 logger.info(f"Running {' '.join(cmd)}")
22 return subprocess.run(cmd, check=True, capture_output=True, text=True, **kwargs)
23 except subprocess.CalledProcessError as e:
24 raise RuntimeError(f"gcloud command failed: {' '.join(cmd)}\nError: {e.stderr}") from e
25
26
27def get_project_id() -> str | None:
28 """Get the current GCP project ID."""
29 try:
30 result = run_gcloud_command(["gcloud", "config", "get-value", "project"])
31 return result.stdout.strip() or None
32 except RuntimeError:
33 return None
34
35
36def list_tpu_nodes(project: str, zone: str | None = None, filter_expr: str = "") -> list[dict …
⋯8 lines
45 f"--project={project}",
46 f"--zone={zone_arg}",
47 "--format=json",
48 ]
49 if filter_expr:
50 cmd.append(f"--filter={filter_expr}")
51
52 result = run_gcloud_command(cmd)
53 return json.loads(result.stdout)
54
55
56def _parse_tpu_node_name(full_name: str, fallback_zone: str) -> tuple[str, str]:
57 name_parts = full_name.sp …
87:62… fallback_zone=zone or "-")
88
89
90def _find_tpu_by_ip_in_nodes(
91 target_ip: str,
92 tpu_nodes: list[dict[str, Any]],
93 *,
94 fallback_zone: str,
95) -> tuple[str, str, int] | None:
96 for node in tpu …
Showing the top 5 files — 17 more files (126 regions) not shown.
No evidence locations were recorded for this file. Raw result