From ae2a24b1bdddc491c670964106d245860652a3ac Mon Sep 17 00:00:00 2001 From: Sergey Efremov Date: Thu, 6 Dec 2012 15:04:26 +0400 Subject: [PATCH] added support for high io EC2 instances and EBS optimized volumnes --- lib/rubber/cloud/fog.rb | 10 ++++++---- lib/rubber/recipes/rubber/instances.rb | 3 ++- lib/rubber/recipes/rubber/volumes.rb | 6 +++--- templates/base/config/rubber/rubber.yml | 18 ++++++++++++++++++ test/cloud/aws_test.rb | 2 +- test/cloud/fog_test.rb | 2 +- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/rubber/cloud/fog.rb b/lib/rubber/cloud/fog.rb index e24c26c42..a30155902 100644 --- a/lib/rubber/cloud/fog.rb +++ b/lib/rubber/cloud/fog.rb @@ -23,12 +23,13 @@ def table_store(table_key) raise NotImplementedError, "No table store available for generic fog adapter" end - def create_instance(ami, ami_type, security_groups, availability_zone) + def create_instance(ami, ami_type, security_groups, availability_zone, ebs_optimized) response = @compute_provider.servers.create(:image_id => ami, :flavor_id => ami_type, :groups => security_groups, :availability_zone => availability_zone, - :key_name => env.key_name) + :key_name => env.key_name, + :ebs_optimized => ebs_optimized) instance_id = response.id return instance_id end @@ -236,8 +237,9 @@ def destroy_static_ip(ip) return address.destroy end - def create_volume(size, zone) - volume = @compute_provider.volumes.create(:size => size.to_s, :availability_zone => zone) + def create_volume(size, zone, volume_type, iops) + volume = @compute_provider.volumes.create(:size => size.to_s, :availability_zone => zone, + :type => volume_type, :iops => iops) return volume.id end diff --git a/lib/rubber/recipes/rubber/instances.rb b/lib/rubber/recipes/rubber/instances.rb index 97aac3101..cfaebedcd 100644 --- a/lib/rubber/recipes/rubber/instances.rb +++ b/lib/rubber/recipes/rubber/instances.rb @@ -260,6 +260,7 @@ def create_instance(instance_alias, instance_roles, create_spot_instance) ami = cloud_env.image_id ami_type = cloud_env.image_type availability_zone = env.availability_zone + ebs_optimized = cloud_env.ebs_optimized create_spot_instance ||= cloud_env.spot_instance @@ -294,7 +295,7 @@ def create_instance(instance_alias, instance_roles, create_spot_instance) if !create_spot_instance || (create_spot_instance && max_wait_time < 0) logger.info "Creating instance #{ami}/#{ami_type}/#{security_groups.join(',') rescue 'Default'}/#{availability_zone || 'Default'}" - instance_id = cloud.create_instance(ami, ami_type, security_groups, availability_zone) + instance_id = cloud.create_instance(ami, ami_type, security_groups, availability_zone, ebs_optimized) end logger.info "Instance #{instance_alias} created: #{instance_id}" diff --git a/lib/rubber/recipes/rubber/volumes.rb b/lib/rubber/recipes/rubber/volumes.rb index f9857a10e..871ff0cba 100644 --- a/lib/rubber/recipes/rubber/volumes.rb +++ b/lib/rubber/recipes/rubber/volumes.rb @@ -72,8 +72,8 @@ detach_volume(volume_id) end - def create_volume(size, zone) - volumeId = cloud.create_volume(size.to_s, zone) + def create_volume(size, zone, volume_type, iops) + volumeId = cloud.create_volume(size.to_s, zone, volume_type, iops.to_s) fatal "Failed to create volume" if volumeId.nil? return volumeId end @@ -91,7 +91,7 @@ def setup_volume(ic, vol_spec) # first create the volume if we don't have a global record (artifacts) for it if ! vol_id logger.info "Creating volume for #{ic.full_name}:#{vol_spec['device']}" - vol_id = create_volume(vol_spec['size'], vol_spec['zone']) + vol_id = create_volume(vol_spec['size'], vol_spec['zone'], vol_spec['type'], vol_spec['iops']) artifacts['volumes'][key] = vol_id rubber_instances.save created = vol_spec['device'] diff --git a/templates/base/config/rubber/rubber.yml b/templates/base/config/rubber/rubber.yml index b9ddade1a..a04afec89 100644 --- a/templates/base/config/rubber/rubber.yml +++ b/templates/base/config/rubber/rubber.yml @@ -86,6 +86,12 @@ cloud_providers: image_type: m1.small image_id: ami-eafa5883 + # EBS I/O optimized instace + # EBS-optimized instances deliver dedicated throughput between Amazon EC2 and Amazon EBS, with options + # between 500 Mbps and 1000 Mbps depending on the instance type used. + # Read more and make sure that your image_type supports ebs_optimized function at: http://aws.amazon.com/ec2/instance-types/ + ebs_optimized: false + # OPTIONAL: EC2 spot instance request support. # # Enables the creation of spot instance requests. Rubber will wait synchronously until the request is fulfilled, @@ -244,20 +250,32 @@ stop_on_error_cmd: "function error_exit { exit 99; }; trap error_exit ERR" # device: /dev/sdh # OS device to attach volume to # mount: /mnt/mysql # The directory to mount this volume to # filesystem: ext3 # the filesystem to create on volume +# type: standard # type of volume, standard or io1 +# iops: 500 # The number of I/O operations per second (IOPS) that the volume supports. +# # Required when the volume type is io1; not used with standard volumes. # - size: 10 # size of vol in GBs # zone: us-east-1a # zone to create volume in, needs to match host's zone # device: /dev/sdi # OS device to attach volume to # mount: /mnt/logs # The directory to mount this volume to # filesystem: ext3 # the filesystem to create on volume +# type: standard # type of volume, standard or io1 +# iops: 500 # The number of I/O operations per second (IOPS) that the volume supports. +# # Required when the volume type is io1; not used with standard volumes. # # # volumes without mount/filesystem can be used in raid arrays # # - size: 50 # size of vol in GBs # zone: us-east-1a # zone to create volume in, needs to match host's zone # device: /dev/sdx # OS device to attach volume to +# type: standard # type of volume, standard or io1 +# iops: 500 # The number of I/O operations per second (IOPS) that the volume supports. +# # Required when the volume type is io1; not used with standard volumes. # - size: 50 # size of vol in GBs # zone: us-east-1a # zone to create volume in, needs to match host's zone # device: /dev/sdy # OS device to attach volume to +# type: standard # type of volume, standard or io1 +# iops: 500 # The number of I/O operations per second (IOPS) that the volume supports. +# # Required when the volume type is io1; not used with standard volumes. # # # Use some ephemeral volumes for raid array # local_volumes: diff --git a/test/cloud/aws_test.rb b/test/cloud/aws_test.rb index 734f70119..a71c14682 100644 --- a/test/cloud/aws_test.rb +++ b/test/cloud/aws_test.rb @@ -26,7 +26,7 @@ class AwsTest < Test::Unit::TestCase end should "create instance" do - assert @cloud.create_instance('', '', '', '') + assert @cloud.create_instance('', '', '', '', '') end end diff --git a/test/cloud/fog_test.rb b/test/cloud/fog_test.rb index 96eb22200..1d8ee6ed4 100644 --- a/test/cloud/fog_test.rb +++ b/test/cloud/fog_test.rb @@ -27,7 +27,7 @@ class FogTest < Test::Unit::TestCase end should "create instance" do - assert @cloud.create_instance('', '', '', '') + assert @cloud.create_instance('', '', '', '', '') end end