mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ec2] simplify request method signature
This commit is contained in:
parent
3ffa8b153a
commit
c9fdf125a7
32 changed files with 147 additions and 110 deletions
|
@ -139,8 +139,12 @@ module Fog
|
|||
|
||||
private
|
||||
|
||||
def request(params, parser)
|
||||
def request(params)
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
|
||||
idempotent = params.delete(:idempotent)
|
||||
parser = params.delete(:parser)
|
||||
|
||||
params.merge!({
|
||||
'AWSAccessKeyId' => @aws_access_key_id,
|
||||
'SignatureMethod' => 'HmacSHA256',
|
||||
|
@ -161,12 +165,13 @@ module Fog
|
|||
body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
|
||||
|
||||
response = @connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:idempotent => idempotent,
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
})
|
||||
|
||||
response
|
||||
|
|
|
@ -12,9 +12,10 @@ unless Fog.mocking?
|
|||
# * 'publicIp'<~String> - The acquired address
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
def allocate_address
|
||||
request({
|
||||
'Action' => 'AllocateAddress'
|
||||
}, Fog::Parsers::AWS::EC2::AllocateAddress.new)
|
||||
request(
|
||||
'Action' => 'AllocateAddress',
|
||||
:parser => Fog::Parsers::AWS::EC2::AllocateAddress.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,11 +16,12 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def associate_address(instance_id, public_ip)
|
||||
request({
|
||||
'Action' => 'AssociateAddress',
|
||||
'InstanceId' => instance_id,
|
||||
'PublicIp' => public_ip
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'AssociateAddress',
|
||||
'InstanceId' => instance_id,
|
||||
'PublicIp' => public_ip,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -21,12 +21,13 @@ unless Fog.mocking?
|
|||
# * 'status'<~String> - Status of volume
|
||||
# * 'volumeId'<~String> - Reference to volume
|
||||
def attach_volume(instance_id, volume_id, device)
|
||||
request({
|
||||
'Action' => 'AttachVolume',
|
||||
'VolumeId' => volume_id,
|
||||
'InstanceId' => instance_id,
|
||||
'Device' => device
|
||||
}, Fog::Parsers::AWS::EC2::AttachVolume.new)
|
||||
request(
|
||||
'Action' => 'AttachVolume',
|
||||
'VolumeId' => volume_id,
|
||||
'InstanceId' => instance_id,
|
||||
'Device' => device,
|
||||
:parser => Fog::Parsers::AWS::EC2::AttachVolume.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -25,8 +25,9 @@ unless Fog.mocking?
|
|||
# * 'return'<~Boolean> - success?
|
||||
def authorize_security_group_ingress(options = {})
|
||||
request({
|
||||
'Action' => 'AuthorizeSecurityGroupIngress'
|
||||
}.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
|
||||
'Action' => 'AuthorizeSecurityGroupIngress',
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -17,10 +17,11 @@ unless Fog.mocking?
|
|||
# * 'keyName'<~String> - Name of key
|
||||
# * 'requestId'<~String> - Id of request
|
||||
def create_key_pair(key_name)
|
||||
request({
|
||||
'Action' => 'CreateKeyPair',
|
||||
'KeyName' => key_name
|
||||
}, Fog::Parsers::AWS::EC2::CreateKeyPair.new)
|
||||
request(
|
||||
'Action' => 'CreateKeyPair',
|
||||
'KeyName' => key_name,
|
||||
:parser => Fog::Parsers::AWS::EC2::CreateKeyPair.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,11 +16,12 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def create_security_group(name, description)
|
||||
request({
|
||||
'Action' => 'CreateSecurityGroup',
|
||||
'GroupName' => name,
|
||||
'GroupDescription' => CGI.escape(description)
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'CreateSecurityGroup',
|
||||
'GroupName' => name,
|
||||
'GroupDescription' => CGI.escape(description),
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,10 +19,11 @@ unless Fog.mocking?
|
|||
# * 'status'<~String> - state of snapshot
|
||||
# * 'volumeId'<~String> - id of volume snapshot targets
|
||||
def create_snapshot(volume_id)
|
||||
request({
|
||||
'Action' => 'CreateSnapshot',
|
||||
'VolumeId' => volume_id
|
||||
}, Fog::Parsers::AWS::EC2::CreateSnapshot.new)
|
||||
request(
|
||||
'Action' => 'CreateSnapshot',
|
||||
'VolumeId' => volume_id,
|
||||
:parser => Fog::Parsers::AWS::EC2::CreateSnapshot.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -21,12 +21,13 @@ unless Fog.mocking?
|
|||
# * 'status's<~String> - State of volume
|
||||
# * 'volumeId'<~String> - Reference to volume
|
||||
def create_volume(availability_zone, size, snapshot_id = nil)
|
||||
request({
|
||||
'Action' => 'CreateVolume',
|
||||
'AvailabilityZone' => availability_zone,
|
||||
'Size' => size,
|
||||
'SnapshotId' => snapshot_id
|
||||
}, Fog::Parsers::AWS::EC2::CreateVolume.new)
|
||||
request(
|
||||
'Action' => 'CreateVolume',
|
||||
'AvailabilityZone' => availability_zone,
|
||||
'Size' => size,
|
||||
'SnapshotId' => snapshot_id,
|
||||
:parser => Fog::Parsers::AWS::EC2::CreateVolume.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,10 +15,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def delete_key_pair(key_name)
|
||||
request({
|
||||
'Action' => 'DeleteKeyPair',
|
||||
'KeyName' => key_name
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'DeleteKeyPair',
|
||||
'KeyName' => key_name,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,10 +15,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def delete_security_group(name)
|
||||
request({
|
||||
'Action' => 'DeleteSecurityGroup',
|
||||
'GroupName' => name
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'DeleteSecurityGroup',
|
||||
'GroupName' => name,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,10 +15,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def delete_snapshot(snapshot_id)
|
||||
request({
|
||||
'Action' => 'DeleteSnapshot',
|
||||
'SnapshotId' => snapshot_id
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'DeleteSnapshot',
|
||||
'SnapshotId' => snapshot_id,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,10 +15,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def delete_volume(volume_id)
|
||||
request({
|
||||
'Action' => 'DeleteVolume',
|
||||
'VolumeId' => volume_id
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'DeleteVolume',
|
||||
'VolumeId' => volume_id,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,8 +19,9 @@ unless Fog.mocking?
|
|||
def describe_addresses(public_ip = [])
|
||||
params = AWS.indexed_param('PublicIp', public_ip)
|
||||
request({
|
||||
'Action' => 'DescribeAddresses'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new)
|
||||
'Action' => 'DescribeAddresses',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeAddresses.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,8 +20,9 @@ unless Fog.mocking?
|
|||
def describe_availability_zones(zone_name = [])
|
||||
params = AWS.indexed_param('ZoneName', zone_name)
|
||||
request({
|
||||
'Action' => 'DescribeAvailabilityZones'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeAvailabilityZones.new)
|
||||
'Action' => 'DescribeAvailabilityZones',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeAvailabilityZones.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -34,8 +34,9 @@ unless Fog.mocking?
|
|||
options.merge!(AWS.indexed_param('ImageId', image_id))
|
||||
end
|
||||
request({
|
||||
'Action' => 'DescribeImages'
|
||||
}.merge!(options), Fog::Parsers::AWS::EC2::DescribeImages.new)
|
||||
'Action' => 'DescribeImages',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeImages.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -52,8 +52,9 @@ unless Fog.mocking?
|
|||
def describe_instances(instance_id = [])
|
||||
params = AWS.indexed_param('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'DescribeInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeInstances.new)
|
||||
'Action' => 'DescribeInstances',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeInstances.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,8 +19,9 @@ unless Fog.mocking?
|
|||
def describe_key_pairs(key_name = [])
|
||||
params = AWS.indexed_param('KeyName', key_name)
|
||||
request({
|
||||
'Action' => 'DescribeKeyPairs'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeKeyPairs.new)
|
||||
'Action' => 'DescribeKeyPairs',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeKeyPairs.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,8 +19,9 @@ unless Fog.mocking?
|
|||
def describe_regions(region_name = [])
|
||||
params = AWS.indexed_param('RegionName', region_name)
|
||||
request({
|
||||
'Action' => 'DescribeRegions'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeRegions.new)
|
||||
'Action' => 'DescribeRegions',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeRegions.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -27,8 +27,9 @@ unless Fog.mocking?
|
|||
def describe_reserved_instances(reserved_instances_id = [])
|
||||
params = AWS.indexed_param('ReservedInstancesId', reserved_instances_id)
|
||||
request({
|
||||
'Action' => 'DescribeReservedInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeReservedInstances.new)
|
||||
'Action' => 'DescribeReservedInstances',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeReservedInstances.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -29,8 +29,9 @@ unless Fog.mocking?
|
|||
def describe_security_groups(group_name = [])
|
||||
params = AWS.indexed_param('GroupName', group_name)
|
||||
request({
|
||||
'Action' => 'DescribeSecurityGroups',
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new)
|
||||
'Action' => 'DescribeSecurityGroups',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -22,8 +22,9 @@ unless Fog.mocking?
|
|||
def describe_snapshots(snapshot_id = [])
|
||||
params = AWS.indexed_param('SnapshotId', snapshot_id)
|
||||
request({
|
||||
'Action' => 'DescribeSnapshots'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new)
|
||||
'Action' => 'DescribeSnapshots',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeSnapshots.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -28,8 +28,9 @@ unless Fog.mocking?
|
|||
def describe_volumes(volume_id = [])
|
||||
params = AWS.indexed_param('VolumeId', volume_id)
|
||||
request({
|
||||
'Action' => 'DescribeVolumes'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeVolumes.new)
|
||||
'Action' => 'DescribeVolumes',
|
||||
:parser => Fog::Parsers::AWS::EC2::DescribeVolumes.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,9 +24,10 @@ unless Fog.mocking?
|
|||
# * 'volumeId'<~String> - Reference to volume
|
||||
def detach_volume(volume_id, options = {})
|
||||
request({
|
||||
'Action' => 'DetachVolume',
|
||||
'VolumeId' => volume_id
|
||||
}.merge!(options), Fog::Parsers::AWS::EC2::DetachVolume.new)
|
||||
'Action' => 'DetachVolume',
|
||||
'VolumeId' => volume_id,
|
||||
:parser => Fog::Parsers::AWS::EC2::DetachVolume.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,10 +15,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def disassociate_address(public_ip)
|
||||
request({
|
||||
'Action' => 'DisassociateAddress',
|
||||
'PublicIp' => public_ip
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'DisassociateAddress',
|
||||
'PublicIp' => public_ip,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -17,10 +17,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'timestamp'<~Time> - Timestamp of last update to output
|
||||
def get_console_output(instance_id)
|
||||
request({
|
||||
'Action' => 'GetConsoleOutput',
|
||||
'InstanceId' => instance_id
|
||||
}, Fog::Parsers::AWS::EC2::GetConsoleOutput.new)
|
||||
request(
|
||||
'Action' => 'GetConsoleOutput',
|
||||
'InstanceId' => instance_id,
|
||||
:parser => Fog::Parsers::AWS::EC2::GetConsoleOutput.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -17,8 +17,9 @@ unless Fog.mocking?
|
|||
def reboot_instances(instance_id = [])
|
||||
params = AWS.indexed_param('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'RebootInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::Basic.new)
|
||||
'Action' => 'RebootInstances',
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,10 +12,11 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def release_address(public_ip)
|
||||
request({
|
||||
'Action' => 'ReleaseAddress',
|
||||
'PublicIp' => public_ip
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
request(
|
||||
'Action' => 'ReleaseAddress',
|
||||
'PublicIp' => public_ip,
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -25,8 +25,9 @@ unless Fog.mocking?
|
|||
# * 'return'<~Boolean> - success?
|
||||
def revoke_security_group_ingress(options = {})
|
||||
request({
|
||||
'Action' => 'RevokeSecurityGroupIngress'
|
||||
}.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
|
||||
'Action' => 'RevokeSecurityGroupIngress',
|
||||
:parser => Fog::Parsers::AWS::EC2::Basic.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -81,11 +81,12 @@ unless Fog.mocking?
|
|||
options['UserData'] = Base64.encode64(options['UserData'])
|
||||
end
|
||||
request({
|
||||
'Action' => 'RunInstances',
|
||||
'ImageId' => image_id,
|
||||
'MinCount' => min_count,
|
||||
'MaxCount' => max_count
|
||||
}.merge!(options), Fog::Parsers::AWS::EC2::RunInstances.new)
|
||||
'Action' => 'RunInstances',
|
||||
'ImageId' => image_id,
|
||||
'MinCount' => min_count,
|
||||
'MaxCount' => max_count,
|
||||
:parser => Fog::Parsers::AWS::EC2::RunInstances.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,8 +24,9 @@ unless Fog.mocking?
|
|||
def terminate_instances(instance_id)
|
||||
params = AWS.indexed_param('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'TerminateInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
|
||||
'Action' => 'TerminateInstances',
|
||||
:parser => Fog::Parsers::AWS::EC2::TerminateInstances.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -110,6 +110,7 @@ module Fog
|
|||
|
||||
def request(params)
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
idempotent = params.delete(:idempotent)
|
||||
parser = params.delete(:parser)
|
||||
|
||||
params.merge!({
|
||||
|
@ -132,12 +133,13 @@ module Fog
|
|||
body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
|
||||
|
||||
response = @connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:idempotent => idempotent,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
})
|
||||
|
||||
response
|
||||
|
|
Loading…
Reference in a new issue