def run(args: argparse.Namespace) -> None: extra_tags = {} if args.extra_tags: extra_tags = json.loads(args.extra_tags) if not isinstance(extra_tags, dict) or not all( isinstance(k, str) and isinstance(v, str) for k, v in extra_tags.items()): raise RuntimeError( "extra-tags must be a JSON dictionary of strings to strings") check_required_vars() extra_tags["LaunchedBy"] = whoami() if args.machine: with open(ROOT / "misc" / "scratch" / "{}.json".format(args.machine)) as f: print("Reading machine configs from {}".format(f.name)) descs = [ MachineDesc.parse_obj(obj) for obj in multi_json(f.read()) ] else: print("Reading machine configs from stdin...") descs = [ MachineDesc.parse_obj(obj) for obj in multi_json(sys.stdin.read()) ] if args.ssh and len(descs) != 1: raise RuntimeError("Cannot use `--ssh` with {} instances".format( len(descs))) if args.max_age_days <= 0: raise RuntimeError( f"max_age_days must be positive, got {args.max_age_days}") max_age = datetime.timedelta(days=args.max_age_days) instances = launch_cluster( descs, subnet_id=args.subnet_id, key_name=args.key_name, security_group_id=args.security_group_id, instance_profile=args.instance_profile, extra_tags=extra_tags, delete_after=datetime.datetime.utcnow() + max_age, git_rev=args.git_rev, extra_env={}, ) print("Launched instances:") print_instances(instances, args.output_format) if args.ssh: print("ssh-ing into: {}".format(instances[0].instance_id)) mssh(instances[0], "")
def run(args: argparse.Namespace) -> None: # SSH will join together multiple arguments with spaces, so we don't lose # anything by doing the same. instance = boto3.resource("ec2").Instance(args.instance) mssh(instance, " ".join(args.command))