Class: Fog::AWS::EC2::Mock
- Inherits:
-
Object
- Object
- Fog::AWS::EC2::Mock
- Defined in:
- lib/fog/aws/ec2.rb,
lib/fog/aws/models/ec2/images.rb,
lib/fog/aws/models/ec2/flavors.rb,
lib/fog/aws/models/ec2/servers.rb,
lib/fog/aws/models/ec2/volumes.rb,
lib/fog/aws/models/ec2/addresses.rb,
lib/fog/aws/models/ec2/key_pairs.rb,
lib/fog/aws/models/ec2/snapshots.rb,
lib/fog/aws/models/ec2/security_groups.rb,
lib/fog/aws/requests/ec2/attach_volume.rb,
lib/fog/aws/requests/ec2/create_volume.rb,
lib/fog/aws/requests/ec2/delete_volume.rb,
lib/fog/aws/requests/ec2/detach_volume.rb,
lib/fog/aws/requests/ec2/run_instances.rb,
lib/fog/aws/requests/ec2/create_key_pair.rb,
lib/fog/aws/requests/ec2/create_snapshot.rb,
lib/fog/aws/requests/ec2/delete_key_pair.rb,
lib/fog/aws/requests/ec2/delete_snapshot.rb,
lib/fog/aws/requests/ec2/describe_images.rb,
lib/fog/aws/requests/ec2/release_address.rb,
lib/fog/aws/requests/ec2/allocate_address.rb,
lib/fog/aws/requests/ec2/describe_regions.rb,
lib/fog/aws/requests/ec2/describe_volumes.rb,
lib/fog/aws/requests/ec2/reboot_instances.rb,
lib/fog/aws/requests/ec2/associate_address.rb,
lib/fog/aws/requests/ec2/describe_addresses.rb,
lib/fog/aws/requests/ec2/describe_instances.rb,
lib/fog/aws/requests/ec2/describe_key_pairs.rb,
lib/fog/aws/requests/ec2/describe_snapshots.rb,
lib/fog/aws/requests/ec2/get_console_output.rb,
lib/fog/aws/requests/ec2/terminate_instances.rb,
lib/fog/aws/requests/ec2/disassociate_address.rb,
lib/fog/aws/requests/ec2/create_security_group.rb,
lib/fog/aws/requests/ec2/delete_security_group.rb,
lib/fog/aws/requests/ec2/describe_security_groups.rb,
lib/fog/aws/requests/ec2/describe_availability_zones.rb,
lib/fog/aws/requests/ec2/describe_reserved_instances.rb,
lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb,
lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb
Instance Method Summary collapse
- #addresses(attributes = {}) ⇒ Object
- #allocate_address ⇒ Object
- #associate_address(instance_id, public_ip) ⇒ Object
- #attach_volume(instance_id, volume_id, device) ⇒ Object
- #authorize_security_group_ingress(options = {}) ⇒ Object
- #create_key_pair(key_name) ⇒ Object
- #create_security_group(name, description) ⇒ Object
- #create_snapshot(volume_id) ⇒ Object
- #create_volume(availability_zone, size, snapshot_id = nil) ⇒ Object
- #delete_key_pair(key_name) ⇒ Object
- #delete_security_group(name) ⇒ Object
- #delete_snapshot(snapshot_id) ⇒ Object
- #delete_volume(volume_id) ⇒ Object
- #describe_addresses(public_ip = []) ⇒ Object
- #describe_availability_zones(zone_name = []) ⇒ Object
- #describe_images(options = {}) ⇒ Object
- #describe_instances(instance_id = {}) ⇒ Object
- #describe_key_pairs(key_name = []) ⇒ Object
- #describe_regions(region_name = []) ⇒ Object
- #describe_reserved_instances(reserved_instances_id = {}) ⇒ Object
- #describe_security_groups(group_name = []) ⇒ Object
- #describe_snapshots(snapshot_id = []) ⇒ Object
- #describe_volumes(volume_id = []) ⇒ Object
- #detach_volume(volume_id, options = {}) ⇒ Object
- #disassociate_address(public_ip) ⇒ Object
- #flavors ⇒ Object
- #get_console_output(instance_id) ⇒ Object
- #images ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #key_pairs ⇒ Object
- #reboot_instances(instance_id = []) ⇒ Object
- #release_address(public_ip) ⇒ Object
- #reset_data ⇒ Object
-
#revoke_security_group_ingress(options = {}) ⇒ Object
TODO: handle the GroupName/Source/Source case.
-
#run_instances(image_id, min_count, max_count, options = {}) ⇒ Object
TODO: allow for block device mapping in mocks TODO: allow for rootDeviceType specification.
- #security_groups ⇒ Object
- #servers ⇒ Object
- #snapshots(attributes = {}) ⇒ Object
- #terminate_instances(instance_id) ⇒ Object
- #volumes(attributes = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
74 75 76 |
# File 'lib/fog/aws/ec2.rb', line 74 def initialize(={}) reset_data end |
Instance Method Details
#addresses(attributes = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/fog/aws/models/ec2/addresses.rb', line 9 def addresses(attributes = {}) Fog::AWS::EC2::Addresses.new({ :connection => self }.merge!(attributes)) end |
#allocate_address ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/aws/requests/ec2/allocate_address.rb', line 26 def allocate_address response = Excon::Response.new response.status = 200 public_ip = Fog::AWS::Mock.ip_address data ={ 'instanceId' => '', 'publicIp' => public_ip } @data[:addresses][public_ip] = data response.body = { 'publicIp' => public_ip, 'requestId' => Fog::AWS::Mock.request_id } response end |
#associate_address(instance_id, public_ip) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/aws/requests/ec2/associate_address.rb', line 32 def associate_address(instance_id, public_ip) response = Excon::Response.new response.status = 200 instance = @data[:instances][instance_id] address = @data[:addresses][public_ip] if instance && address address['instanceId'] = instance_id response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#attach_volume(instance_id, volume_id, device) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/aws/requests/ec2/attach_volume.rb', line 38 def attach_volume(instance_id, volume_id, device) response = Excon::Response.new if instance_id && volume_id && device response.status = 200 instance = @data[:instances][instance_id] volume = @data[:volumes][volume_id] if instance && volume data = { 'attachTime' => Time.now, 'device' => device, 'instanceId' => instance_id, 'status' => 'attaching', 'volumeId' => volume_id } volume['attachmentSet'] << data response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data) else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end else response.status = 400 response.body = { 'Code' => 'MissingParameter' } if !instance_id response['Message'] = 'The request must contain the parameter instance_id' elsif !volume_id response['Message'] = 'The request must contain the parameter volume_id' else response['Message'] = 'The request must contain the parameter device' end end response end |
#authorize_security_group_ingress(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb', line 38 def ( = {}) response = Excon::Response.new group = @data[:security_groups][['GroupName']] group['ipPermissions'] ||= [] if ['GroupName'] && ['SourceSecurityGroupName'] && ['SourceSecurityGroupOwnerId'] owner = Fog::AWS::Mock.owner_id ['icmp', 'tcp', 'udp'].each do |protocol| group['ipPermissions'] << { 'groups' => [{'groupName' => ['GroupName'], 'userId' => owner}], 'fromPort' => 1, 'ipRanges' => [], 'ipProtocol' => protocol, 'toPort' => 65535 } end else group['ipPermissions'] << { 'groups' => [], 'fromPort' => ['FromPort'], 'ipRanges' => [{ 'cidrIp' => ['CidrIp'] }], 'ipProtocol' => ['IpProtocol'], 'toPort' => ['ToPort'] } end response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } response end |
#create_key_pair(key_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/aws/requests/ec2/create_key_pair.rb', line 32 def create_key_pair(key_name) response = Excon::Response.new unless @data[:key_pairs][key_name] response.status = 200 data = { 'keyFingerprint' => Fog::AWS::Mock.key_fingerprint, 'keyMaterial' => Fog::AWS::Mock.key_material, 'keyName' => key_name } @data[:key_pairs][key_name] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data) else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#create_security_group(name, description) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/aws/requests/ec2/create_security_group.rb', line 32 def create_security_group(name, description) response = Excon::Response.new unless @data[:security_groups][name] data = { 'groupDescription' => description, 'groupName' => name, 'ipPermissions' => [], 'ownerId' => Fog::AWS::Mock.owner_id } @data[:security_groups][name] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#create_snapshot(volume_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fog/aws/requests/ec2/create_snapshot.rb', line 34 def create_snapshot(volume_id) response = Excon::Response.new if @data[:volumes][volume_id] response.status = 200 snapshot_id = Fog::AWS::Mock.snapshot_id data = { 'progress' => '', 'snapshotId' => snapshot_id, 'startTime' => Time.now, 'status' => 'pending', 'volumeId' => volume_id } @data[:snapshots][snapshot_id] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data) else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#create_volume(availability_zone, size, snapshot_id = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fog/aws/requests/ec2/create_volume.rb', line 38 def create_volume(availability_zone, size, snapshot_id = nil) response = Excon::Response.new if availability_zone && size response.status = 200 volume_id = Fog::AWS::Mock.volume_id data = { 'availabilityZone' => availability_zone, 'attachmentSet' => [], 'createTime' => Time.now, 'size' => size, 'snapshotId' => snapshot_id || '', 'status' => 'creating', 'volumeId' => volume_id } @data[:volumes][volume_id] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data.reject {|key,value| !['availabilityZone','createTime','size','snapshotId','status','volumeId'].include?(key) }) else response.status = 400 response.body = { 'Code' => 'MissingParameter' } unless availability_zone response.body['Message'] = 'The request must contain the parameter availability_zone' else response.body['Message'] = 'The request must contain the parameter size' end end response end |
#delete_key_pair(key_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/aws/requests/ec2/delete_key_pair.rb', line 30 def delete_key_pair(key_name) response = Excon::Response.new @data[:key_pairs].delete(key_name) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } response end |
#delete_security_group(name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/aws/requests/ec2/delete_security_group.rb', line 29 def delete_security_group(name) response = Excon::Response.new if @data[:security_groups][name] @data[:security_groups].delete(name) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#delete_snapshot(snapshot_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/aws/requests/ec2/delete_snapshot.rb', line 30 def delete_snapshot(snapshot_id) response = Excon::Response.new if snapshot = @data[:snapshots].delete(snapshot_id) response.status = true response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#delete_volume(volume_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/aws/requests/ec2/delete_volume.rb', line 30 def delete_volume(volume_id) response = Excon::Response.new if volume = @data[:volumes][volume_id] @data[:deleted_at][volume_id] = Time.now volume['status'] = 'deleting' response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#describe_addresses(public_ip = []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/aws/requests/ec2/describe_addresses.rb', line 32 def describe_addresses(public_ip = []) response = Excon::Response.new public_ip = [*public_ip] if public_ip != [] addresses_set = @data[:addresses].reject {|key, value| !public_ip.include?(key)}.values else addresses_set = @data[:addresses].values end if public_ip.length == 0 || public_ip.length == addresses_set.length response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'addressesSet' => addresses_set } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#describe_availability_zones(zone_name = []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/aws/requests/ec2/describe_availability_zones.rb', line 33 def describe_availability_zones(zone_name = []) response = Excon::Response.new zone_name = [*zone_name] zones = { 'us-east-1a' => {"zoneName"=>"us-east-1a", "regionName"=>"us-east-1", "zoneState"=>"available"}, 'us-east-1b' => {"zoneName"=>"us-east-1b", "regionName"=>"us-east-1", "zoneState"=>"available"}, 'us-east-1c' => {"zoneName"=>"us-east-1c", "regionName"=>"us-east-1", "zoneState"=>"available"}, 'us-east-1d' => {"zoneName"=>"us-east-1d", "regionName"=>"us-east-1", "zoneState"=>"available"} } if zone_name != [] availability_zone_info = zones.reject {|key, value| !zone_name.include?(key)}.values else availability_zone_info = zones.values end response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'availabilityZoneInfo' => availability_zone_info } response end |
#describe_images(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/aws/requests/ec2/describe_images.rb', line 47 def describe_images( = {}) response = Excon::Response.new images = [] (rand(101 + 100)).times do images << Fog::AWS::Mock.image end response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'imagesSet' => images } response end |
#describe_instances(instance_id = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fog/aws/requests/ec2/describe_instances.rb', line 65 def describe_instances(instance_id = {}) response = Excon::Response.new instance_id = [*instance_id] if instance_id != [] instance_set = @data[:instances].reject {|key,value| !instance_id.include?(key)}.values else instance_set = @data[:instances].values end instance_set.each do |instance| case instance['instanceState']['name'] when 'pending' if Time.now - instance['launchTime'] > 2 instance['instanceState'] = { :code => 16, :name => 'running' } end when 'rebooting' instance['instanceState'] = { :code => 16, :name => 'running' } when 'shutting-down' if Time.now - @data[:deleted_at][instance['instanceId']] > 2 instance['instanceState'] = { :code => 16, :name => 'terminating' } end when 'terminating' if Time.now - @data[:deleted_at][instance['instanceId']] > 4 @data[:deleted_at].delete(instance['instanceId']) @data[:instances].delete(instance['instanceId']) end end end if instance_id.length == 0 || instance_id.length == instance_set.length response.status = 200 reservation_set = {} instance_set.each do |instance| reservation_set[instance['reservationId']] ||= { 'groupSet' => instance['groupSet'], 'instancesSet' => [], 'ownerId' => instance['ownerId'], 'reservationId' => instance['reservationId'] } 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 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'reservationSet' => reservation_set.values } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#describe_key_pairs(key_name = []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fog/aws/requests/ec2/describe_key_pairs.rb', line 32 def describe_key_pairs(key_name = []) response = Excon::Response.new key_name = [*key_name] if key_name != [] key_set = @data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values else key_set = @data[:key_pairs].values end if key_name.length == 0 || key_name.length == key_set.length response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'keySet' => key_set.map do |key| key.reject {|key,value| !['keyFingerprint', 'keyName'].include?(key)} end } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#describe_regions(region_name = []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/aws/requests/ec2/describe_regions.rb', line 32 def describe_regions(region_name = []) response = Excon::Response.new region_name = [*region_name] regions = { 'eu-west-1' => {"regionName"=>"eu-west-1", "regionEndpoint"=>"eu-west-1.ec2.amazonaws.com"}, 'us-east-1' => {"regionName"=>"us-east-1", "regionEndpoint"=>"us-east-1.ec2.amazonaws.com"} } if region_name != [] region_info = regions.reject {|key, value| !region_name.include?(key)}.values else region_info = regions.values end response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'regionInfo' => region_info } response end |
#describe_reserved_instances(reserved_instances_id = {}) ⇒ Object
40 41 42 |
# File 'lib/fog/aws/requests/ec2/describe_reserved_instances.rb', line 40 def describe_reserved_instances(reserved_instances_id = {}) raise MockNotImplemented.new("Contributions welcome!") end |
#describe_security_groups(group_name = []) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/aws/requests/ec2/describe_security_groups.rb', line 42 def describe_security_groups(group_name = []) response = Excon::Response.new group_name = [*group_name] if group_name != [] security_group_info = @data[:security_groups].reject {|key, value| !group_name.include?(key)}.values else security_group_info = @data[:security_groups].values end if group_name.length == 0 || group_name.length == security_group_info.length response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'securityGroupInfo' => security_group_info } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#describe_snapshots(snapshot_id = []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fog/aws/requests/ec2/describe_snapshots.rb', line 35 def describe_snapshots(snapshot_id = []) response = Excon::Response.new snapshot_id = [*snapshot_id] if snapshot_id != [] snapshot_set = @data[:snapshots].reject {|key,value| !snapshot_id.include?(key)}.values else snapshot_set = @data[:snapshots].values end snapshot_set.each do |snapshot| case snapshot['status'] when 'creating' if Time.now - volume['createTime'] > 2 snapshot['progress'] = '100%' snapshot['status'] = 'completed' else snapshot['progress'] = '50%' snapshot['status'] = 'in progress' end end end if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'snapshotSet' => snapshot_set } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#describe_volumes(volume_id = []) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/aws/requests/ec2/describe_volumes.rb', line 41 def describe_volumes(volume_id = []) response = Excon::Response.new volume_id = [*volume_id] if volume_id != [] volume_set = @data[:volumes].reject {|key,value| !volume_id.include?(key)}.values else volume_set = @data[:volumes].values end volume_set.each do |volume| case volume['status'] when 'creating' if Time.now - volume['createTime'] > 2 volume['status'] = 'available' end when 'deleting' if Time.now - @data[:deleted_at][volume['volumeId']] > 2 @data[:deleted_at].delete(volume['volumeId']) @data[:volumes].delete(volume['volumeId']) end end end if volume_id.length == 0 || volume_id.length == volume_set.length response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'volumeSet' => volume_set } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#detach_volume(volume_id, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/aws/requests/ec2/detach_volume.rb', line 38 def detach_volume(volume_id, = {}) response = Excon::Response.new response.status = 200 if volume = @data[:volumes][volume_id] data = volume['attachmentSet'].pop response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data) else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#disassociate_address(public_ip) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/aws/requests/ec2/disassociate_address.rb', line 30 def disassociate_address(public_ip) response = Excon::Response.new response.status = 200 if address = @data[:addresses][public_ip] address['instanceId'] = '' response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#flavors ⇒ Object
9 10 11 |
# File 'lib/fog/aws/models/ec2/flavors.rb', line 9 def flavors Fog::AWS::EC2::Flavors.new(:connection => self) end |
#get_console_output(instance_id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/aws/requests/ec2/get_console_output.rb', line 32 def get_console_output(instance_id) response = Excon::Response.new if instance = @data[:instances][instance_id] response.status = 200 response.body = { 'instanceId' => instance_id, 'output' => Fog::AWS::Mock.console_output, 'requestId' => Fog::AWS::Mock.request_id, 'timestamp' => Time.now } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#images ⇒ Object
9 10 11 |
# File 'lib/fog/aws/models/ec2/images.rb', line 9 def images Fog::AWS::EC2::Images.new(:connection => self) end |
#key_pairs ⇒ Object
9 10 11 |
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 9 def key_pairs Fog::AWS::EC2::KeyPairs.new(:connection => self) end |
#reboot_instances(instance_id = []) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/aws/requests/ec2/reboot_instances.rb', line 30 def reboot_instances(instance_id = []) response = Excon::Response.new instance_id = [*instance_id] if (@data[:instances].keys & instance_id).length == instance_id.length for instance_id in instance_id @data[:instances][instance_id]['status'] = 'rebooting' end response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#release_address(public_ip) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/aws/requests/ec2/release_address.rb', line 27 def release_address(public_ip) response = Excon::Response.new if (address = @data[:addresses].delete(public_ip)) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#reset_data ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fog/aws/ec2.rb', line 62 def reset_data @data = { :deleted_at => {}, :addresses => {}, :instances => {}, :key_pairs => {}, :security_groups => {}, :snapshots => {}, :volumes => {} } end |
#revoke_security_group_ingress(options = {}) ⇒ Object
TODO: handle the GroupName/Source/Source case
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb', line 39 def revoke_security_group_ingress( = {}) if ['GroupName'] && ['SourceSecurityGroupName'] && ['SourceSecurityGroupOwnerId'] raise MockNotImplemented.new("Contributions welcome!") else response = Excon::Response.new group = @data[:security_groups][['GroupName']] ingress = group['ipPermissions'].select {|| ['fromPort'] == ['FromPort'] && ['ipProtocol'] == ['IpProtocol'] && ['toPort'] == ['ToPort'] && ['ipRanges'].first['cidrIp'] == ['CidrIp'] }.first group['ipPermissions'].delete(ingress) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true } response end end |
#run_instances(image_id, min_count, max_count, options = {}) ⇒ Object
TODO: allow for block device mapping in mocks TODO: allow for rootDeviceType specification
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/fog/aws/requests/ec2/run_instances.rb', line 99 def run_instances(image_id, min_count, max_count, = {}) response = Excon::Response.new response.status = 200 group_set = [ (['GroupId'] || 'default') ] instances_set = [] owner_id = Fog::AWS::Mock.owner_id reservation_id = Fog::AWS::Mock.reservation_id min_count.times do |i| instance_id = Fog::AWS::Mock.instance_id data = { 'amiLaunchIndex' => i, 'blockDeviceMapping' => [], 'dnsName' => '', 'groupSet' => group_set, 'imageId' => image_id, 'instanceId' => instance_id, 'instanceState' => { 'code' => 0, 'name' => 'pending' }, 'instanceType' => ['InstanceType'] || 'm1.small', 'kernelId' => ['KernelId'] || Fog::AWS::Mock.kernel_id, 'keyName' => ['KeyName'] || '', 'launchTime' => Time.now, 'monitoring' => { 'state' => ['Monitoring.Enabled'] || false }, 'ownerId' => owner_id, 'placement' => { 'availabilityZone' => ['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone }, 'privateDnsName' => '', 'productCodes' => [], 'ramdiskId' => ['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)} end response.body = { 'groupSet' => group_set, 'instancesSet' => instances_set, 'ownerId' => owner_id, 'requestId' => Fog::AWS::Mock.request_id, 'reservationId' => reservation_id } response end |
#security_groups ⇒ Object
9 10 11 |
# File 'lib/fog/aws/models/ec2/security_groups.rb', line 9 def security_groups Fog::AWS::EC2::SecurityGroups.new(:connection => self) end |
#servers ⇒ Object
9 10 11 |
# File 'lib/fog/aws/models/ec2/servers.rb', line 9 def servers Fog::AWS::EC2::Servers.new(:connection => self) end |
#snapshots(attributes = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 9 def snapshots(attributes = {}) Fog::AWS::EC2::Snapshots.new({ :connection => self }.merge!(attributes)) end |
#terminate_instances(instance_id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/aws/requests/ec2/terminate_instances.rb', line 37 def terminate_instances(instance_id) response = Excon::Response.new instance_id = [*instance_id] if (@data[:instances].keys & instance_id).length == instance_id.length for instance_id in instance_id response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'instancesSet' => [] } instance = @data[:instances][instance_id] @data[:deleted_at][instance_id] = Time.now response.status = 200 # TODO: the codes are mostly educated guessing, not certainty code = case instance['state'] when 'pending' 0 when 'running' 16 when 'shutting-down' 32 when 'terminated' 64 when 'rebooting' 128 end state = { 'name' => 'shutting-down', 'code' => 32} response.body['instancesSet'] << { 'instanceId' => instance_id, 'previousState' => instance['instanceState'], 'currentState' => state } instance['instanceState'] = state end else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |