Permalink
Browse files

allow user to just specify ec2 region and pick sensible defaults

- possible to override defaults derived from region:
  - ec2 endpoint
  - availability zone

Change-Id: I9d19f01f2e717874171b92f7e400a6031619ef86
  • Loading branch information...
1 parent c98612f commit dc2bf95aea74d9eb9d5a30b1506990bdbf5079c0 @pmenglund pmenglund committed Sep 5, 2012
Showing with 22 additions and 3 deletions.
  1. +22 −3 aws_cpi/lib/cloud/aws/cloud.rb
@@ -30,6 +30,7 @@ def initialize(options)
@agent_properties = @options["agent"] || {}
@aws_properties = @options["aws"]
+ @aws_region = @aws_properties.delete("region")
@registry_properties = @options["registry"]
@default_key_name = @aws_properties["default_key_name"]
@@ -38,7 +39,7 @@ def initialize(options)
aws_params = {
:access_key_id => @aws_properties["access_key_id"],
:secret_access_key => @aws_properties["secret_access_key"],
- :ec2_endpoint => @aws_properties["ec2_endpoint"] || DEFAULT_EC2_ENDPOINT,
+ :ec2_endpoint => @aws_properties["ec2_endpoint"] || default_ec2_endpoint,
:max_retries => @aws_properties["max_retries"] || DEFAULT_MAX_RETRIES,
:logger => @aws_logger
}
@@ -182,11 +183,13 @@ def create_disk(size, instance_id = nil)
cloud_error("AWS CPI maximum disk size is 1 TiB")
end
+ # if the disk is created for an instance, use the same availability
+ # zone as they must match
if instance_id
instance = @ec2.instances[instance_id]
availability_zone = instance.availability_zone
else
- availability_zone = DEFAULT_AVAILABILITY_ZONE
+ availability_zone = default_availability_zone
end
volume_params = {
@@ -307,6 +310,7 @@ def configure_networks(instance_id, network_spec)
# provided by the stemcell manifest
# @option cloud_properties [String] disk (2048)
# root disk size
+ # @return [String] EC2 AMI name of the stemcell
def create_stemcell(image_path, cloud_properties)
# TODO: refactor into several smaller methods
with_thread_name("create_stemcell(#{image_path}...)") do
@@ -428,7 +432,7 @@ def select_availability_zone(volumes, resource_pool_az)
ensure_same_availability_zone(disks, resource_pool_az)
disks.first.availability_zone
else
- resource_pool_az || DEFAULT_AVAILABILITY_ZONE
+ resource_pool_az || default_availability_zone
end
end
@@ -678,6 +682,21 @@ def validate_options
end
end
+ def default_ec2_endpoint
+ if @aws_region
+ "ec2.#{@aws_region}.amazonaws.com"
+ else
+ DEFAULT_EC2_ENDPOINT
+ end
+ end
+
+ def default_availability_zone
+ if @aws_region
+ "#{@aws_region}b"
+ else
+ DEFAULT_AVAILABILITY_ZONE
+ end
+ end
end
end

0 comments on commit dc2bf95

Please sign in to comment.