Class: RightAws::MockEc2
- Inherits:
-
Object
- Object
- RightAws::MockEc2
- Defined in:
- lib/deltacloud/drivers/ec2/ec2_mock_driver.rb
Instance Method Summary collapse
- #describe_availability_zones(opts = {}) ⇒ Object
- #describe_images(opts = {}) ⇒ Object
- #describe_images_by_owner(id) ⇒ Object
- #describe_instances(opts = {}) ⇒ Object
- #describe_snapshots(opts = {}) ⇒ Object
- #describe_volumes(opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ MockEc2
constructor
A new instance of MockEc2.
- #reboot_instances(id) ⇒ Object
- #run_instances(image_id, min_count, max_count, group_ids, key_name, user_data = '', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil) ⇒ Object
- #terminate_instances(id) ⇒ Object (also: #destroy_instance)
Constructor Details
#initialize(opts = {}) ⇒ MockEc2
Returns a new instance of MockEc2.
4 5 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 4 def initialize(opts={}) end |
Instance Method Details
#describe_availability_zones(opts = {}) ⇒ Object
19 20 21 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 19 def describe_availability_zones(opts={}) load_fixtures_for(:realms) end |
#describe_images(opts = {}) ⇒ Object
7 8 9 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 7 def describe_images(id) load_fixtures_for(:images).select { |i| i[:aws_id].eql?(id) } end |
#describe_images_by_owner(id) ⇒ Object
11 12 13 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 11 def describe_images_by_owner(id) load_fixtures_for(:images).select { |i| i[:aws_owner].eql?(id) } end |
#describe_instances(opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 23 def describe_instances(opts={}) instances = load_fixtures_for(:instances) instances.each_with_index do |instance, i| instances[i] = update_delayed_state(instance) return [instance] if opts and opts[:id] and instance[:aws_instance_id].eql?(opts[:id]) end update_fixtures_for(:instances, instances) instances end |
#describe_snapshots(opts = {}) ⇒ Object
83 84 85 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 83 def describe_snapshots(opts={}) load_fixtures_for(:storage_snapshot) end |
#describe_volumes(opts = {}) ⇒ Object
87 88 89 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 87 def describe_volumes(opts={}) load_fixtures_for(:storage_volume) end |
#reboot_instances(id) ⇒ Object
77 78 79 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 77 def reboot_instances(id) update_instance_state(id, 'pending', '0') end |
#run_instances(image_id, min_count, max_count, group_ids, key_name, user_data = '', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil) ⇒ Object
33 34 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 69 70 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 33 def run_instances(image_id, min_count, max_count, group_ids, key_name, user_data='', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil) instances = load_fixtures_for(:instances) image = load_fixtures_for(:images).select { |img| img[:aws_id].eql?(image_id) }.first if availability_zone realm = load_fixtures_for(:realms).select { |realm| realm[:zone_name].eql?(availability_zone) }.first else realm = load_fixtures_for(:realms).first end raise Exception unless image raise Exception unless realm instance = { } instance[:aws_image_id] = image[:aws_id] instance[:aws_availability_zone] = realm[:zone_name] instance[:aws_instance_type] = instance_type instance[:aws_owner] = user_data instance[:aws_state] = 'pending' instance[:aws_reason] = '' instance[:dns_name] = "#{random_dns}-01-C9.usma2.compute.amazonaws.com" instance[:private_dns_name] = "#{random_dns}-02-P9.usma2.compute.amazonaws.com" instance[:aws_state_code] = "0" instance[:aws_key_name] = "staging" instance[:aws_kernel_id] = "aki-be3adfd7" instance[:aws_ramdisk_id] = "ari-ce34gad7" instance[:aws_groups] = ["default"] instance[:aws_instance_id] = random_instance_id instance[:aws_reservation_id] = "r-aabbccdd" instance[:aws_launch_time] = instance_time_format instances << instance update_fixtures_for(:instances, instances) return [instance] end |
#terminate_instances(id) ⇒ Object Also known as: destroy_instance
73 74 75 |
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 73 def terminate_instances(id) update_instance_state(id, 'stopping', '80') end |