Created
February 14, 2011 19:51
-
-
Save Atalanta/826421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fog' | |
| require 'ubuntu_ami' | |
| require 'chef/knife/ec2_server_create' | |
| # Here are some defaults | |
| # TODO: accept command line options | |
| REGION = "eu-west-1" | |
| RELEASE = "lucid" | |
| SECURITY_GROUP = "default" | |
| FLAVOUR = "m1.small" | |
| KEY = "gsg-opseng" | |
| ZONE = "eu-west-1b" | |
| EBS = nil | |
| def select_hostname | |
| available_hosts = search(:hostnames, 'NOT status:TAKEN').map do |hostname| | |
| hostname['id'] | |
| end | |
| return available_hosts[rand(available_hosts.size)] | |
| end | |
| def select_ami(release) | |
| ami_generator = UbuntuAmi.new(RELEASE) | |
| region = ami_generator.region_fix(REGION) | |
| size = "_" + FLAVOUR.split(".").last | |
| ebs = EBS ? "_ebs" : "" | |
| key = region + size + ebs | |
| return ami_generator.run[key] | |
| end | |
| connection = Fog::AWS::Compute.new( | |
| :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id], | |
| :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key], | |
| :region => REGION | |
| ) | |
| server = connection.servers.create( | |
| :image_id => select_ami(RELEASE), | |
| :groups => [ SECURITY_GROUP ], | |
| :flavor_id => FLAVOUR, | |
| :key_name => KEY, | |
| :availability_zone => ZONE | |
| ) | |
| puts "Instance ID: #{server.id}" | |
| puts "Flavour: #{server.flavor_id}" | |
| puts "Image: #{server.image_id}" | |
| puts "Availability Zone: #{server.availability_zone}" | |
| puts "Security Groups: #{server.groups.join(", ")}" | |
| puts "SSH Key: #{server.key_name}" | |
| print "\nWaiting for server" | |
| server.wait_for { print "."; ready? } | |
| puts("\n") | |
| puts "Public DNS Name: #{server.dns_name}" | |
| puts "Public IP Address: #{server.ip_address}" | |
| puts "Private DNS Name: #{server.private_dns_name}" | |
| puts "Private IP Address: #{server.private_ip_address}" | |
| nodename = select_hostname | |
| puts "Now bootstrap with the following command:" | |
| puts "knife bootstrap #{server.ip_address} -N #{nodename}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment