(args: argparse.Namespace)
| 199 | |
| 200 | |
| 201 | def run(args: argparse.Namespace) -> None: |
| 202 | extra_tags = {} |
| 203 | if args.extra_tags: |
| 204 | extra_tags = json.loads(args.extra_tags) |
| 205 | if not isinstance(extra_tags, dict) or not all( |
| 206 | isinstance(k, str) and isinstance(v, str) for k, v in extra_tags.items() |
| 207 | ): |
| 208 | raise RuntimeError( |
| 209 | "extra-tags must be a JSON dictionary of strings to strings" |
| 210 | ) |
| 211 | |
| 212 | descs = load_machine_descs( |
| 213 | args.machine, |
| 214 | instance_type=args.instance_type, |
| 215 | size_gb=args.size_gb, |
| 216 | ) |
| 217 | |
| 218 | check_required_vars() |
| 219 | extra_tags["LaunchedBy"] = whoami() |
| 220 | |
| 221 | if args.ssh and len(descs) != 1: |
| 222 | raise RuntimeError(f"Cannot use `--ssh` with {len(descs)} instances") |
| 223 | |
| 224 | if args.max_age_days <= 0: |
| 225 | raise RuntimeError(f"max_age_days must be positive, got {args.max_age_days}") |
| 226 | max_age = datetime.timedelta(days=args.max_age_days) |
| 227 | |
| 228 | instances = launch_cluster( |
| 229 | descs, |
| 230 | key_name=args.key_name, |
| 231 | security_group_name=args.security_group_name, |
| 232 | instance_profile=args.instance_profile, |
| 233 | extra_tags=extra_tags, |
| 234 | delete_after=datetime.datetime.now(datetime.timezone.utc) + max_age, |
| 235 | git_rev=args.git_rev, |
| 236 | extra_env={}, |
| 237 | ) |
| 238 | |
| 239 | print("Launched instances:") |
| 240 | print_instances(instances, args.output_format) |
| 241 | |
| 242 | if args.ssh: |
| 243 | print(f"ssh-ing into: {instances[0].instance_id}") |
| 244 | mssh(instances[0], "") |
nothing calls this directly
no test coverage detected