Skip to content

Commit

Permalink
IOPS support for Volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin committed Jun 21, 2012
1 parent b3fef13 commit f23e5ae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ the source key.

=== Next
Release Notes:
- Added: API '2012-06-15' support for CreateVolume and DescribeVolumes API calls (to support IOPS)
- Fixed:
- Single-threaded multipart upload support (https://github.com/rightscale/right_aws/pull/116)
- S3 multi object delete (https://github.com/rightscale/right_aws/pull/106)
Expand Down
10 changes: 9 additions & 1 deletion lib/ec2/right_ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,33 @@ def describe_resources_with_list_and_options(remote_function_name, remote_item_n
# 'RemoteFunctionName' -> :remote_funtion_name
cache_name = remote_function_name.right_underscore.to_sym
list, options = AwsUtils::split_items_and_params(list_and_options)
custom_options = {}
# Resource IDs to fetch
request_hash = amazonize_list(remote_item_name, list)
# Other custom options
options.each do |key, values|
next if values.right_blank?
case key
when :options
custom_options = values
when :filters then
request_hash.merge!(amazonize_list(['Filter.?.Name', 'Filter.?.Value.?'], values))
else
request_hash.merge!(amazonize_list(key.to_s.right_camelize, values))
end
end
cache_for = (list.right_blank? && options.right_blank?) ? cache_name : nil
link = generate_request(remote_function_name, request_hash)
link = generate_request(remote_function_name, request_hash, custom_options)
request_cache_or_info(cache_for, link, parser_class, @@bench, cache_for, &block)
rescue Exception
on_exception
end

def merge_new_options_into_list_and_options(list_and_options, new_options)
list, options = AwsUtils::split_items_and_params(list_and_options)
list << options.merge(new_options)
end

#-----------------------------------------------------------------
# Keys
#-----------------------------------------------------------------
Expand Down
36 changes: 34 additions & 2 deletions lib/ec2/right_ec2_ebs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Ec2
# EBS: Volumes
#-----------------------------------------------------------------

VOLUME_API_VERSION = '2012-06-15'

# Describe EBS volumes.
#
# Accepts a list of volumes and/or a set of filters as the last parameter.
Expand All @@ -47,6 +49,14 @@ class Ec2
# :aws_id => "vol-60957009",
# :aws_created_at => "2008-06-18T08:19:20.000Z",
# :aws_instance_id => "i-c014c0a9"},
# {:aws_id => "vol-71de8b1f",
# :aws_size => 5,
# :snapshot_id => nil,
# :zone => "us-east-1a",
# :aws_status => "available",
# :aws_created_at => "2012-06-21T18:47:34.000Z",
# :volume_type => "io1",
# :iop => "5"},#
# {:aws_size => 1,
# :zone => "merlot",
# :snapshot_id => nil,
Expand All @@ -59,6 +69,7 @@ class Ec2
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeVolumes.html
#
def describe_volumes(*list_and_options)
list_and_options = merge_new_options_into_list_and_options(list_and_options, :options => {:api_version => VOLUME_API_VERSION})
describe_resources_with_list_and_options('DescribeVolumes', 'VolumeId', QEc2DescribeVolumesParser, list_and_options)
end

Expand All @@ -73,12 +84,29 @@ def describe_volumes(*list_and_options)
# :aws_created_at => "2008-06-24T18:13:32.000Z",
# :aws_size => 94}
#
def create_volume(snapshot_id, size, zone)
# ec2.create_volume(nil, 5, 'us-east-1a', :iops => '5', :volume_type => 'io1') #=>
# {:aws_id=>"vol-71de8b1f",
# :aws_size=>5,
# :snapshot_id=>nil,
# :zone=>"us-east-1a",
# :aws_status=>"creating",
# :aws_created_at=>"2012-06-21T18:47:34.000Z",
# :volume_type=>"io1",
# :iops=>"5"}
#
def create_volume(snapshot_id, size, zone, options={})
hash = { "Size" => size.to_s,
"AvailabilityZone" => zone.to_s }
# Get rig of empty snapshot: e8s guys do not like it
hash["SnapshotId"] = snapshot_id.to_s unless snapshot_id.right_blank?
link = generate_request("CreateVolume", hash )
# Add IOPS support (default behavior) but skip it when an old API version call is requested
options[:options] ||= {}
options[:options][:api_version] ||= VOLUME_API_VERSION
if options[:options][:api_version]>= VOLUME_API_VERSION
hash["VolumeType"] = options[:volume_type] unless options[:volume_type].right_blank?
hash["Iops"] = options[:iops] unless options[:iops].right_blank?
end
link = generate_request("CreateVolume", hash, options[:options])
request_info(link, QEc2CreateVolumeParser.new(:logger => @logger))
rescue Exception
on_exception
Expand Down Expand Up @@ -364,6 +392,8 @@ def tagend(name)
when 'size' then @result[:aws_size] = @text.to_i ###
when 'snapshotId' then @result[:snapshot_id] = @text.right_blank? ? nil : @text ###
when 'availabilityZone' then @result[:zone] = @text ###
when 'volumeType' then @result[:volume_type] = @text
when 'iops' then @result[:iops] = @text
end
end
def reset
Expand Down Expand Up @@ -403,6 +433,8 @@ def tagend(name)
when 'snapshotId' then @item[:snapshot_id] = @text.right_blank? ? nil : @text
when 'availabilityZone' then @item[:zone] = @text
when 'deleteOnTermination' then @item[:delete_on_termination] = (@text == 'true')
when 'volumeType' then @item[:volume_type] = @text
when 'iops' then @item[:iops] = @text
else
case full_tag_name
when %r{/volumeSet/item/volumeId$} then @item[:aws_id] = @text
Expand Down

1 comment on commit f23e5ae

@hectcastro
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any word on when the next release of this gem will be cut? Would love to have Provisioned IOPS support.

Please sign in to comment.