Skip to content

Commit

Permalink
make keypair region specific
Browse files Browse the repository at this point in the history
  • Loading branch information
eval committed Sep 11, 2009
1 parent cd4a4dd commit c1ef3ca
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/sumo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def launch
result = ec2.run_instances(
:image_id => ami,
:instance_type => config['instance_size'] || 'm1.small',
:key_name => 'sumo',
:key_name => key_name,
:group_id => [ 'sumo' ],
:availability_zone => config['availability_zone']
)
Expand Down Expand Up @@ -235,13 +235,24 @@ def read_config
rescue Errno::ENOENT
raise "Sumo is not configured, please fill in ~/.sumo/config.yml"
end

def current_region
@current_region ||= begin
zones = ec2.describe_availability_zones
zones.availabilityZoneInfo.item[0].regionName
end
end

def keypair_file
"#{sumo_dir}/keypair.pem"
"#{sumo_dir}/keypair-#{current_region}.pem"
end

def key_name
"sumo-#{current_region}"
end

def create_keypair
keypair = ec2.create_keypair(:key_name => "sumo").keyMaterial
keypair = ec2.create_keypair(:key_name => key_name).keyMaterial
File.open(keypair_file, 'w') { |f| f.write keypair }
File.chmod 0600, keypair_file
end
Expand Down

0 comments on commit c1ef3ca

Please sign in to comment.