Class: RightAws::MockEc2

Inherits:
Object
  • Object
show all
Defined in:
lib/deltacloud/drivers/ec2/ec2_mock_driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MockEc2

Returns a new instance of MockEc2.



22
23
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 22

def initialize(opts={})
end

Instance Method Details

#describe_availability_zones(opts = {}) ⇒ Object



37
38
39
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 37

def describe_availability_zones(opts={})
  load_fixtures_for(:realms)
end

#describe_images(opts = {}) ⇒ Object



25
26
27
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 25

def describe_images(id)
  load_fixtures_for(:images).select { |i| i[:aws_id].eql?(id) }
end

#describe_images_by_owner(id) ⇒ Object



29
30
31
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 29

def describe_images_by_owner(id)
  load_fixtures_for(:images).select { |i| i[:aws_owner].eql?(id) }
end

#describe_instances(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 41

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



101
102
103
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 101

def describe_snapshots(opts={})
  load_fixtures_for(:storage_snapshot)
end

#describe_volumes(opts = {}) ⇒ Object



105
106
107
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 105

def describe_volumes(opts={})
  load_fixtures_for(:storage_volume)
end

#reboot_instances(id) ⇒ Object



95
96
97
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 95

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

Raises:

  • (Exception)


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
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 51

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



91
92
93
# File 'lib/deltacloud/drivers/ec2/ec2_mock_driver.rb', line 91

def terminate_instances(id)
  update_instance_state(id, 'stopping', '80')
end