def _create_server_ec2(region,<EOL>access_key_id,<EOL>secret_access_key,<EOL>disk_name,<EOL>disk_size,<EOL>ami,<EOL>key_pair,<EOL>instance_type,<EOL>username,<EOL>tags={},<EOL>security_groups=None):
conn = connect_to_ec2(region, access_key_id, secret_access_key)<EOL>log_green("<STR_LIT>")<EOL>log_yellow("<STR_LIT>")<EOL>ebs_volume = EBSBlockDeviceType()<EOL>ebs_volume.size = disk_size<EOL>bdm = BlockDeviceMapping()<EOL>bdm[disk_name] = ebs_volume<EOL>image = conn.get_all_images(ami)[<NUM_LIT:0>]<EOL>reservation = image.run(<NUM_LIT:1>, <NUM_LIT:1>,<EOL>key_name=key_pair,<EOL>security_groups=security_groups,<EOL>block_device_map=bdm,<EOL>instance_type=instance_type)<EOL>instance = reservation.instances[<NUM_LIT:0>]<EOL>while instance.state == '<STR_LIT>':<EOL><INDENT>log_yellow("<STR_LIT>" % instance.state)<EOL>sleep(<NUM_LIT:10>)<EOL>instance.update()<EOL><DEDENT>log_green("<STR_LIT>" % instance.state)<EOL>wait_for_ssh(instance.public_dns_name)<EOL>for dev, bd in list(instance.block_device_mapping.items()):<EOL><INDENT>instance.modify_attribute('<STR_LIT>',<EOL>["<STR_LIT>" % (dev, <NUM_LIT:1>)])<EOL><DEDENT>conn.create_tags([instance.id], tags)<EOL>log_green("<STR_LIT>" % instance.public_dns_name)<EOL>save_ec2_state_locally(instance_id=instance.id,<EOL>region=region,<EOL>username=username,<EOL>access_key_id=access_key_id,<EOL>secret_access_key=secret_access_key)<EOL>
Creates EC2 Instance and saves it state in a local json file