зеркало из https://github.com/microsoft/fog.git
consolidate implementation/usage of indexed params for aws
This commit is contained in:
Родитель
6647fdf18c
Коммит
78a3e26048
|
@ -7,6 +7,14 @@ module Fog
|
|||
load "fog/aws/s3.rb"
|
||||
end
|
||||
|
||||
def self.indexed_param(key, values)
|
||||
params = {}
|
||||
[*values].each_with_index do |value, index|
|
||||
params["#{key}.#{index}"] = value
|
||||
end
|
||||
params
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
srand(Time.now.to_i)
|
||||
|
||||
|
|
|
@ -141,15 +141,6 @@ module Fog
|
|||
|
||||
private
|
||||
|
||||
def indexed_params(name, params)
|
||||
indexed, index = {}, 1
|
||||
for param in [*params]
|
||||
indexed["#{name}.#{index}"] = param
|
||||
index += 1
|
||||
end
|
||||
indexed
|
||||
end
|
||||
|
||||
def request(params, parser)
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
params.merge!({
|
||||
|
|
|
@ -104,8 +104,8 @@ module Fog
|
|||
if @availability_zone
|
||||
options['Placement.AvailabilityZone'] = @availability_zone
|
||||
end
|
||||
@groups.each_with_index do |group, index|
|
||||
options["SecurityGroup.#{index}"] = group
|
||||
unless @groups.empty?
|
||||
options.merge!(AWS.indexed_param("SecurityGroup", @groups))
|
||||
end
|
||||
if @kernel_id
|
||||
options['KernelId'] = @kernel_id
|
||||
|
|
|
@ -17,7 +17,7 @@ unless Fog.mocking?
|
|||
# * 'instanceId'<~String> - instance for ip address
|
||||
# * 'publicIp'<~String> - ip address for instance
|
||||
def describe_addresses(public_ip = [])
|
||||
params = indexed_params('PublicIp', public_ip)
|
||||
params = AWS.indexed_param('PublicIp', public_ip)
|
||||
request({
|
||||
'Action' => 'DescribeAddresses'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new)
|
||||
|
|
|
@ -18,7 +18,7 @@ unless Fog.mocking?
|
|||
# * 'zoneName'<~String> - Name of zone
|
||||
# * 'zoneState'<~String> - State of zone
|
||||
def describe_availability_zones(zone_name = [])
|
||||
params = indexed_params('ZoneName', zone_name)
|
||||
params = AWS.indexed_param('ZoneName', zone_name)
|
||||
request({
|
||||
'Action' => 'DescribeAvailabilityZones'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeAvailabilityZones.new)
|
||||
|
|
|
@ -31,7 +31,7 @@ unless Fog.mocking?
|
|||
# * 'ramdiskId'<~String> - Ramdisk id associated with image, if any
|
||||
def describe_images(options = {})
|
||||
if image_id = options.delete('ImageId')
|
||||
options.merge!(indexed_params('ImageId', image_id))
|
||||
options.merge!(AWS.indexed_param('ImageId', image_id))
|
||||
end
|
||||
request({
|
||||
'Action' => 'DescribeImages'
|
||||
|
|
|
@ -39,7 +39,7 @@ unless Fog.mocking?
|
|||
# * 'ramdiskId'<~String> - Id of ramdisk used to launch instance
|
||||
# * 'reason'<~String> - reason for most recent state transition, or blank
|
||||
def describe_instances(instance_id = [])
|
||||
params = indexed_params('InstanceId', instance_id)
|
||||
params = AWS.indexed_param('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'DescribeInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeInstances.new)
|
||||
|
|
|
@ -17,7 +17,7 @@ unless Fog.mocking?
|
|||
# * 'keyName'<~String> - Name of key
|
||||
# * 'keyFingerprint'<~String> - Fingerprint of key
|
||||
def describe_key_pairs(key_name = [])
|
||||
params = indexed_params('KeyName', key_name)
|
||||
params = AWS.indexed_param('KeyName', key_name)
|
||||
request({
|
||||
'Action' => 'DescribeKeyPairs'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeKeyPairs.new)
|
||||
|
|
|
@ -17,7 +17,7 @@ unless Fog.mocking?
|
|||
# * 'regionName'<~String> - Name of region
|
||||
# * 'regionEndpoint'<~String> - Service endpoint for region
|
||||
def describe_regions(region_name = [])
|
||||
params = indexed_params('RegionName', region_name)
|
||||
params = AWS.indexed_param('RegionName', region_name)
|
||||
request({
|
||||
'Action' => 'DescribeRegions'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeRegions.new)
|
||||
|
|
|
@ -27,7 +27,7 @@ unless Fog.mocking?
|
|||
# * 'toPort'<~Integer> - End of port range (or -1 for ICMP wildcard)
|
||||
# * 'ownerId'<~String> - AWS Access Key Id of the owner of the security group
|
||||
def describe_security_groups(group_name = [])
|
||||
params = indexed_params('GroupName', group_name)
|
||||
params = AWS.indexed_param('GroupName', group_name)
|
||||
request({
|
||||
'Action' => 'DescribeSecurityGroups',
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new)
|
||||
|
|
|
@ -20,7 +20,7 @@ unless Fog.mocking?
|
|||
# * 'status'<~String>: Snapshot state, in ['pending', 'completed']
|
||||
# * 'volumeId'<~String>: Id of volume that snapshot contains
|
||||
def describe_snapshots(snapshot_id = [])
|
||||
params = indexed_params('SnapshotId', snapshot_id)
|
||||
params = AWS.indexed_param('SnapshotId', snapshot_id)
|
||||
request({
|
||||
'Action' => 'DescribeSnapshots'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new)
|
||||
|
|
|
@ -26,7 +26,7 @@ unless Fog.mocking?
|
|||
# * 'status'<~String> - Attachment state
|
||||
# * 'volumeId'<~String> - Reference to volume
|
||||
def describe_volumes(volume_id = [])
|
||||
params = indexed_params('VolumeId', volume_id)
|
||||
params = AWS.indexed_param('VolumeId', volume_id)
|
||||
request({
|
||||
'Action' => 'DescribeVolumes'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeVolumes.new)
|
||||
|
|
|
@ -15,7 +15,7 @@ unless Fog.mocking?
|
|||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def reboot_instances(instance_id = [])
|
||||
params = indexed_params('InstanceId', instance_id)
|
||||
params = AWS.indexed_param('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'RebootInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::Basic.new)
|
||||
|
|
|
@ -22,7 +22,7 @@ unless Fog.mocking?
|
|||
# * 'code'<~Integer> - current status code
|
||||
# * 'name'<~String> - name of current state
|
||||
def terminate_instances(instance_id)
|
||||
params = indexed_params('InstanceId', instance_id)
|
||||
params = AWS.indexed_param('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'TerminateInstances'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
|
||||
|
|
|
@ -81,15 +81,7 @@ module Fog
|
|||
end
|
||||
|
||||
def encode_attribute_names(attributes)
|
||||
encoded_attribute_names = {}
|
||||
if attributes
|
||||
index = 0
|
||||
for attribute in attributes
|
||||
encoded_attribute_names["AttributeName.#{index}"] = attribute.to_s
|
||||
index += 1
|
||||
end
|
||||
end
|
||||
encoded_attribute_names
|
||||
AWS.indexed_param('AttributeName', attributes.map {|attribute| attributes.to_s})
|
||||
end
|
||||
|
||||
def encode_batch_attributes(items, replace_attributes = Hash.new([]))
|
||||
|
|
Загрузка…
Ссылка в новой задаче