(args: argparse.Namespace)
| 59 | |
| 60 | |
| 61 | def run(args: argparse.Namespace) -> None: |
| 62 | # Read the machine config, applying any overrides. |
| 63 | descs = load_machine_descs( |
| 64 | args.machine, |
| 65 | instance_type=args.instance_type, |
| 66 | size_gb=args.size_gb, |
| 67 | ) |
| 68 | |
| 69 | if len(descs) != 1: |
| 70 | raise RuntimeError( |
| 71 | f"'go' expects a single-machine config, got {len(descs)} machines" |
| 72 | ) |
| 73 | |
| 74 | check_required_vars() |
| 75 | |
| 76 | # Try to find an existing instance |
| 77 | try: |
| 78 | instance = get_instance("mine") |
| 79 | say(f"Found existing instance {instance.instance_id} ({name(tags(instance))})") |
| 80 | print_instances([instance], "table") |
| 81 | print("Connecting...") |
| 82 | mssh(instance, "") |
| 83 | return |
| 84 | except RuntimeError: |
| 85 | pass |
| 86 | |
| 87 | # No existing instance — create one |
| 88 | label = args.machine or args.instance_type |
| 89 | say(f"No existing instance found, creating from {label}...") |
| 90 | |
| 91 | max_age = datetime.timedelta(days=args.max_age_days) |
| 92 | extra_tags = {"LaunchedBy": whoami()} |
| 93 | instances = launch_cluster( |
| 94 | descs, |
| 95 | extra_tags=extra_tags, |
| 96 | delete_after=datetime.datetime.now(datetime.timezone.utc) + max_age, |
| 97 | ) |
| 98 | |
| 99 | print("Launched:") |
| 100 | print_instances(instances, "table") |
| 101 | print("Connecting...") |
| 102 | mssh(instances[0], "") |
nothing calls this directly
no test coverage detected