def ssh(args):
prefix, at, name = args.name.rpartition("@")
instance = resources.ec2.Instance(resolve_instance_id(name))
if not instance.public_dns_name:
msg = "Unable to resolve public DNS name for {} (state: {})"
raise AegeaException(msg.format(instance, getattr(instance, "state", {}).get("Name")))
tags = {tag["Key"]: tag["Value"] for tag in instance.tags or []}
ssh_host_key = tags.get("SSHHostPublicKeyPart1", "") + tags.get("SSHHostPublicKeyPart2", "")
if ssh_host_key:
# FIXME: this results in duplicates.
# Use paramiko to detect if the key is already listed and not insert it then (or only insert if different)
add_ssh_host_key_to_known_hosts(instance.public_dns_name + " " + ssh_host_key + "\n")
ssh_args = ["ssh", prefix + at + instance.public_dns_name]
if not (prefix or at):
try:
ssh_args += ["-l", resources.iam.CurrentUser().user.name]
except:
logger.info("Unable to determine IAM username, using local username")
os.execvp("ssh", ssh_args + args.ssh_args)
评论列表
文章目录