mine.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import argparse
  10. import boto3
  11. from mypy_boto3_ec2.type_defs import FilterTypeDef
  12. from materialize.cli.scratch import check_required_vars
  13. from materialize.scratch import print_instances, whoami
  14. def configure_parser(parser: argparse.ArgumentParser) -> None:
  15. check_required_vars()
  16. parser.add_argument(
  17. "who",
  18. nargs="*",
  19. help="Whose instances to show (defaults to yourself)",
  20. )
  21. parser.add_argument("--all", help="Show all instances", action="store_true")
  22. parser.add_argument("--output-format", choices=["table", "csv"], default="table")
  23. def run(args: argparse.Namespace) -> None:
  24. filters: list[FilterTypeDef] = []
  25. if not args.all:
  26. filters.append({"Name": "tag:LaunchedBy", "Values": args.who or [whoami()]})
  27. print_instances(
  28. list(boto3.resource("ec2").instances.filter(Filters=filters)),
  29. args.output_format,
  30. )