def create_aws_instances():
"""
Create AWS instances and let Fabric point to them
This method creates AWS instances and points the fabric environment to them with
the current public IP and username.
"""
default_if_empty(env, 'AWS_KEY_NAME', DEFAULT_AWS_KEY_NAME)
default_if_empty(env, 'AWS_INSTANCE_NAME', default_instance_name)
# Create the key pair and security group if necessary
conn = connect()
aws_create_key_pair(conn)
sgid = check_create_aws_sec_group(conn)
# Create the instance in AWS
host_names = create_instances(conn, sgid)
# Update our fabric environment so from now on we connect to the
# AWS machine using the correct user and SSH private key
env.hosts = host_names
env.key_filename = key_filename(env.AWS_KEY_NAME)
if env.AWS_AMI_NAME in ['CentOS', 'SLES']:
env.user = 'root'
else:
env.user = 'ec2-user'
# Instances have started, but are not usable yet, make sure SSH has started
puts('Started the instance(s) now waiting for the SSH daemon to start.')
execute(check_ssh, timeout=300)
评论列表
文章目录