mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'master' into rds_subnets
This commit is contained in:
commit
a07acc4c02
12 changed files with 95 additions and 7 deletions
|
@ -1,5 +1,9 @@
|
|||
language: ruby
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- rvm: 1.8.7
|
||||
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.2
|
||||
|
|
|
@ -112,7 +112,7 @@ geemus says: "That should give you everything you need to get started, but let m
|
|||
|
||||
## Contributing
|
||||
|
||||
* Find something you would like to work on. For suggestions look for the `easy`, `medium` and `hard` tags in the {issues}[http://github.com/fog/fog/issues]
|
||||
* Find something you would like to work on. For suggestions look for the `easy`, `medium` and `hard` tags in the [issues](https://github.com/fog/fog/issues)
|
||||
* Fork the project and do your work in a topic branch.
|
||||
* Add shindo tests to prove your code works and run all the tests using `bundle exec rake`.
|
||||
* Rebase your branch against fog/fog to make sure everything is up to date.
|
||||
|
|
|
@ -9,6 +9,7 @@ module Fog
|
|||
{ :bits => 0, :cores => 2, :disk => 0, :id => 't1.micro', :name => 'Micro Instance', :ram => 613},
|
||||
|
||||
{ :bits => 32, :cores => 1, :disk => 160, :id => 'm1.small', :name => 'Small Instance', :ram => 1740.8},
|
||||
{ :bits => 32, :cores => 2, :disk => 400, :id => 'm1.medium', :name => 'Medium Instance', :ram => 3750},
|
||||
{ :bits => 64, :cores => 4, :disk => 850, :id => 'm1.large', :name => 'Large Instance', :ram => 7680},
|
||||
{ :bits => 64, :cores => 8, :disk => 1690, :id => 'm1.xlarge', :name => 'Extra Large Instance', :ram => 15360},
|
||||
|
||||
|
@ -58,6 +59,14 @@ module Fog
|
|||
# ram=1740.8
|
||||
# >,
|
||||
# <Fog::AWS::Compute::Flavor
|
||||
# id="m1.medium",
|
||||
# bits=32,
|
||||
# cores=2,
|
||||
# disk=400,
|
||||
# name="Medium Instance",
|
||||
# ram=3750
|
||||
# >,
|
||||
# <Fog::AWS::Compute::Flavor
|
||||
# id="m1.large",
|
||||
# bits=64,
|
||||
# cores=4,
|
||||
|
|
|
@ -28,6 +28,7 @@ module Fog
|
|||
attribute :image_id, :aliases => 'LaunchSpecification.ImageId'
|
||||
attribute :monitoring, :aliases => 'LaunchSpecification.Monitoring'
|
||||
attribute :block_device_mapping, :aliases => 'LaunchSpecification.BlockDeviceMapping'
|
||||
attribute :subnet_id, :aliases => 'LaunchSpecification.SubnetId'
|
||||
attribute :tags, :aliases => 'tagSet'
|
||||
attribute :fault, :squash => 'message'
|
||||
attribute :user_data
|
||||
|
@ -109,10 +110,21 @@ module Fog
|
|||
'LaunchSpecification.Placement.AvailabilityZone' => availability_zone,
|
||||
'LaunchSpecification.SecurityGroup' => groups,
|
||||
'LaunchSpecification.UserData' => user_data,
|
||||
'LaunchSpecification.SubnetId' => subnet_id,
|
||||
'Type' => request_type,
|
||||
'ValidFrom' => valid_from,
|
||||
'ValidUntil' => valid_until }
|
||||
options.delete_if {|key, value| value.nil?}
|
||||
|
||||
# If subnet is defined then this is a Virtual Private Cloud.
|
||||
# subnet & security group cannot co-exist. Attempting to specify
|
||||
# both subnet and groups will cause an error. Instead please make
|
||||
# use of Security Group Ids when working in a VPC.
|
||||
if subnet_id
|
||||
options.delete('LaunchSpecification.SecurityGroup')
|
||||
else
|
||||
options.delete('LaunchSpecification.SubnetId')
|
||||
end
|
||||
|
||||
data = connection.request_spot_instances(image_id, flavor_id, price, options).body
|
||||
spot_instance_request = data['spotInstanceRequestSet'].first
|
||||
|
|
|
@ -48,7 +48,7 @@ module Fog
|
|||
@response['spotInstanceRequestSet'] << @spot_instance_request
|
||||
@spot_instance_request = { 'launchSpecification' => { 'blockDeviceMapping' => [], 'groupSet' => [] } }
|
||||
end
|
||||
when 'imageId', 'instanceType', 'keyname'
|
||||
when 'imageId', 'instanceType', 'keyname', 'subnetId'
|
||||
@spot_instance_request['launchSpecification'][name] = value
|
||||
when 'enabled'
|
||||
@spot_instance_request['launchSpecification']['monitoring'] = (value == 'true')
|
||||
|
|
|
@ -11,6 +11,7 @@ module Fog
|
|||
raise ArgumentError.new("Filters must be a hash, but is a #{filters.class}.") unless filters.is_a?(Hash)
|
||||
next_token = filters.delete('nextToken') || filters.delete('NextToken')
|
||||
max_results = filters.delete('maxResults') || filters.delete('MaxResults')
|
||||
all_instances = filters.delete('includeAllInstances') || filters.delete('IncludeAllInstances')
|
||||
|
||||
params = Fog::AWS.indexed_request_param('InstanceId', filters.delete('InstanceId'))
|
||||
|
||||
|
@ -18,6 +19,7 @@ module Fog
|
|||
|
||||
params['NextToken'] = next_token if next_token
|
||||
params['MaxResults'] = max_results if max_results
|
||||
params['IncludeAllInstances'] = all_instances if all_instances
|
||||
|
||||
request({
|
||||
'Action' => 'DescribeInstanceStatus',
|
||||
|
|
|
@ -25,6 +25,7 @@ module Fog
|
|||
# * 'imageId'<~String> - AMI for instance
|
||||
# * 'instanceType'<~String> - type for instance
|
||||
# * 'monitoring'<~Boolean> - monitoring status for instance
|
||||
# * 'subnetId'<~String> - VPC subnet ID for instance
|
||||
# * 'productDescription'<~String> - general description of AMI
|
||||
# * 'spotInstanceRequestId'<~String> - id of spot instance request
|
||||
# * 'spotPrice'<~Float> - maximum price for instances to be launched
|
||||
|
|
|
@ -24,6 +24,7 @@ module Fog
|
|||
# * 'Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination
|
||||
# * 'LaunchSpecification.KeyName'<~String> - Name of a keypair to add to booting instances
|
||||
# * 'LaunchSpecification.Monitoring.Enabled'<~Boolean> - Enables monitoring, defaults to disabled
|
||||
# * 'LaunchSpecification.SubnetId'<~String> - VPC subnet ID in which to launch the instance
|
||||
# * 'LaunchSpecification.Placement.AvailabilityZone'<~String> - Placement constraint for instances
|
||||
# * 'LaunchSpecification.SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances, not supported in VPC
|
||||
# * 'LaunchSpecification.SecurityGroupId'<~Array> or <~String> - Id of security group(s) for instances, use this or LaunchSpecification.SecurityGroup
|
||||
|
@ -47,6 +48,7 @@ module Fog
|
|||
# * 'imageId'<~String> - AMI for instance
|
||||
# * 'instanceType'<~String> - type for instance
|
||||
# * 'monitoring'<~Boolean> - monitoring status for instance
|
||||
# * 'subnetId'<~String> - VPC subnet ID for instance
|
||||
# * 'productDescription'<~String> - general description of AMI
|
||||
# * 'spotInstanceRequestId'<~String> - id of spot instance request
|
||||
# * 'spotPrice'<~Float> - maximum price for instances to be launched
|
||||
|
|
|
@ -103,10 +103,20 @@ module Fog
|
|||
|
||||
response.headers['x-amz-version-id'] = object['VersionId'] if bucket[:versioning]
|
||||
|
||||
body = object[:body]
|
||||
if options['Range']
|
||||
# since AWS S3 itself does not support multiple range headers, we will use only the first
|
||||
ranges = byte_ranges(options['Range'], body.size)
|
||||
unless ranges.nil? || ranges.empty?
|
||||
response.status = 206
|
||||
body = body[ranges.first]
|
||||
end
|
||||
end
|
||||
|
||||
unless block_given?
|
||||
response.body = object[:body]
|
||||
response.body = body
|
||||
else
|
||||
data = StringIO.new(object[:body])
|
||||
data = StringIO.new(body)
|
||||
remaining = data.length
|
||||
while remaining > 0
|
||||
chunk = data.read([remaining, Excon::CHUNK_SIZE].min)
|
||||
|
@ -142,6 +152,39 @@ module Fog
|
|||
response
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# === Borrowed from rack
|
||||
# Parses the "Range:" header, if present, into an array of Range objects.
|
||||
# Returns nil if the header is missing or syntactically invalid.
|
||||
# Returns an empty array if none of the ranges are satisfiable.
|
||||
def byte_ranges(http_range, size)
|
||||
# See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35>
|
||||
return nil unless http_range
|
||||
ranges = []
|
||||
http_range.split(/,\s*/).each do |range_spec|
|
||||
matches = range_spec.match(/bytes=(\d*)-(\d*)/)
|
||||
return nil unless matches
|
||||
r0,r1 = matches[1], matches[2]
|
||||
if r0.empty?
|
||||
return nil if r1.empty?
|
||||
# suffix-byte-range-spec, represents trailing suffix of file
|
||||
r0 = [size - r1.to_i, 0].max
|
||||
r1 = size - 1
|
||||
else
|
||||
r0 = r0.to_i
|
||||
if r1.empty?
|
||||
r1 = size - 1
|
||||
else
|
||||
r1 = r1.to_i
|
||||
return nil if r1 < r0 # backwards range is syntactically invalid
|
||||
r1 = size-1 if r1 >= size
|
||||
end
|
||||
end
|
||||
ranges << (r0..r1) if r0 <= r1
|
||||
end
|
||||
ranges
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,12 +10,18 @@ module Fog
|
|||
# * object<~String> - Name of object to look for
|
||||
#
|
||||
def get_object(container, object, &block)
|
||||
response = request({
|
||||
params = {}
|
||||
|
||||
if block_given?
|
||||
params[:response_block] = Proc.new
|
||||
end
|
||||
|
||||
response = request(params.merge!({
|
||||
:block => block,
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
|
||||
}, false, &block)
|
||||
}), false)
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ Shindo.tests('Fog::Compute[:aws] | spot instance requests', ['aws']) do
|
|||
'keyName' => Fog::Nullable::String,
|
||||
'imageId' => String,
|
||||
'instanceType' => String,
|
||||
'monitoring' => Fog::Boolean
|
||||
'monitoring' => Fog::Boolean,
|
||||
'subnetId' => String
|
||||
},
|
||||
'productDescription' => String,
|
||||
'spotInstanceRequestId' => String,
|
||||
|
|
|
@ -26,6 +26,14 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do
|
|||
data
|
||||
end
|
||||
|
||||
tests("#get_object('#{@directory.identity}', 'fog_object', {'Range' => 'bytes=0-20'})").returns(lorem_file.read[0..20]) do
|
||||
Fog::Storage[:aws].get_object(@directory.identity, 'fog_object', {'Range' => 'bytes=0-20'}).body
|
||||
end
|
||||
|
||||
tests("#get_object('#{@directory.identity}', 'fog_object', {'Range' => 'bytes=0-0'})").returns(lorem_file.read[0..0]) do
|
||||
Fog::Storage[:aws].get_object(@directory.identity, 'fog_object', {'Range' => 'bytes=0-0'}).body
|
||||
end
|
||||
|
||||
tests("#head_object('#{@directory.identity}', 'fog_object')").succeeds do
|
||||
Fog::Storage[:aws].head_object(@directory.identity, 'fog_object')
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue