From 32f4af0ecfc1b918decd9fc462441a35160e53d9 Mon Sep 17 00:00:00 2001 From: "geemus (Wesley Beary)" Date: Mon, 15 Feb 2010 11:57:35 -0800 Subject: [PATCH] easier region switching for ec2 --- lib/fog/aws/ec2.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index e52afd850..52473442e 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -109,6 +109,7 @@ module Fog # # ==== Parameters # * options<~Hash> - config arguments for connection. Defaults to {}. + # * region<~String> - optional region to use, in ['eu-west-1', 'us-east-1', 'us-west-1'] # # ==== Returns # * EC2 object with connection to aws. @@ -120,7 +121,16 @@ module Fog raise ArgumentError.new('aws_secret_access_key is required to access ec2') end @hmac = HMAC::SHA256.new(@aws_secret_access_key) - @host = options[:host] || 'ec2.amazonaws.com' + @host = options[:host] || case options[:region] + when 'eu-west-1' + 'ec2.eu-west-1.amazonaws.com' + when 'us-east-1' + 'ec2.us-east-1.amazonaws.com' + when 'us-west-1' + 'ec2.us-west-1.amazonaws.com' + else + 'ec2.amazonaws.com' + end @port = options[:port] || 443 @scheme = options[:scheme] || 'https' end