mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ec2] cleanup/optimize mocks
This commit is contained in:
parent
f5673d34e0
commit
0f1ff813d1
4 changed files with 70 additions and 69 deletions
|
@ -69,6 +69,10 @@ module Fog
|
|||
instance_set = @data[:instances].values
|
||||
end
|
||||
|
||||
if instance_id.length == 0 || instance_id.length == instance_set.length
|
||||
response.status = 200
|
||||
reservation_set = {}
|
||||
|
||||
instance_set.each do |instance|
|
||||
case instance['instanceState']['name']
|
||||
when 'pending'
|
||||
|
@ -93,13 +97,8 @@ module Fog
|
|||
@data[:instances].delete(instance['instanceId'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if instance_id.length == 0 || instance_id.length == instance_set.length
|
||||
instance_set = instance_set.reject {|instance| !@data[:instances][instance['instanceId']]}
|
||||
response.status = 200
|
||||
reservation_set = {}
|
||||
instance_set.each do |instance|
|
||||
if @data[:instances][instance['instanceId']]
|
||||
reservation_set[instance['reservationId']] ||= {
|
||||
'groupSet' => instance['groupSet'],
|
||||
'instancesSet' => [],
|
||||
|
@ -108,6 +107,7 @@ module Fog
|
|||
}
|
||||
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'blockDeviceMapping', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
|
||||
end
|
||||
end
|
||||
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
|
|
|
@ -39,6 +39,7 @@ module Fog
|
|||
snapshot_set = @data[:snapshots].values
|
||||
end
|
||||
|
||||
if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length
|
||||
snapshot_set.each do |snapshot|
|
||||
case snapshot['status']
|
||||
when 'in progress', 'pending'
|
||||
|
@ -52,7 +53,6 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
|
|
|
@ -45,6 +45,7 @@ module Fog
|
|||
volume_set = @data[:volumes].values
|
||||
end
|
||||
|
||||
if volume_id.length == 0 || volume_id.length == volume_set.length
|
||||
volume_set.each do |volume|
|
||||
case volume['status']
|
||||
when 'attaching'
|
||||
|
@ -64,7 +65,6 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
if volume_id.length == 0 || volume_id.length == volume_set.length
|
||||
volume_set = volume_set.reject {|volume| !@data[:volumes][volume['volumeId']]}
|
||||
response.status = 200
|
||||
response.body = {
|
||||
|
|
|
@ -104,11 +104,10 @@ module Fog
|
|||
|
||||
min_count.times do |i|
|
||||
instance_id = Fog::AWS::Mock.instance_id
|
||||
data = {
|
||||
instance = {
|
||||
'amiLaunchIndex' => i,
|
||||
'blockDeviceMapping' => [],
|
||||
'dnsName' => '',
|
||||
'groupSet' => group_set,
|
||||
'imageId' => image_id,
|
||||
'instanceId' => instance_id,
|
||||
'instanceState' => { 'code' => 0, 'name' => 'pending' },
|
||||
|
@ -117,18 +116,20 @@ module Fog
|
|||
'keyName' => options['KeyName'] || '',
|
||||
'launchTime' => Time.now,
|
||||
'monitoring' => { 'state' => options['Monitoring.Enabled'] || false },
|
||||
'ownerId' => @owner_id,
|
||||
'placement' => { 'availabilityZone' => options['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone },
|
||||
'privateDnsName' => '',
|
||||
'privateIpAddress' => '',
|
||||
'productCodes' => [],
|
||||
'ramdiskId' => options['RamdiskId'] || Fog::AWS::Mock.ramdisk_id,
|
||||
'reason' => '',
|
||||
'reservationId' => reservation_id,
|
||||
'rootDeviceType' => 'instance-store'
|
||||
}
|
||||
@data[:instances][instance_id] = data
|
||||
instances_set << data.reject{|key,value| !['amiLaunchIndex', 'blockDeviceMapping', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
|
||||
instances_set << instance
|
||||
@data[:instances][instance_id] = instance.merge({
|
||||
'groupSet' => group_set,
|
||||
'ownerId' => @owner_id,
|
||||
'privateIpAddress' => '',
|
||||
'reservationId' => reservation_id,
|
||||
})
|
||||
end
|
||||
response.body = {
|
||||
'groupSet' => group_set,
|
||||
|
|
Loading…
Add table
Reference in a new issue