Class: Fog::Compute::Linode::Mock
- Inherits:
-
Object
- Object
- Fog::Compute::Linode::Mock
- Defined in:
- lib/fog/linode/compute.rb,
lib/fog/linode/requests/compute/linode_boot.rb,
lib/fog/linode/requests/compute/linode_list.rb,
lib/fog/linode/requests/compute/avail_kernels.rb,
lib/fog/linode/requests/compute/linode_create.rb,
lib/fog/linode/requests/compute/linode_delete.rb,
lib/fog/linode/requests/compute/linode_reboot.rb,
lib/fog/linode/requests/compute/linode_update.rb,
lib/fog/linode/requests/compute/linode_ip_list.rb,
lib/fog/linode/requests/compute/linode_shutdown.rb,
lib/fog/linode/requests/compute/linode_disk_list.rb,
lib/fog/linode/requests/compute/avail_datacenters.rb,
lib/fog/linode/requests/compute/avail_linodeplans.rb,
lib/fog/linode/requests/compute/avail_stackscripts.rb,
lib/fog/linode/requests/compute/linode_config_list.rb,
lib/fog/linode/requests/compute/linode_disk_create.rb,
lib/fog/linode/requests/compute/linode_disk_delete.rb,
lib/fog/linode/requests/compute/avail_distributions.rb,
lib/fog/linode/requests/compute/linode_config_create.rb,
lib/fog/linode/requests/compute/linode_config_delete.rb,
lib/fog/linode/requests/compute/linode_config_update.rb,
lib/fog/linode/requests/compute/linode_disk_createfromdistribution.rb
Overview
request :linode_resize
Class Method Summary collapse
Instance Method Summary collapse
- #avail_datacenters ⇒ Object
- #avail_distributions(distribution_id = nil) ⇒ Object
- #avail_kernels(kernel_id = nil) ⇒ Object
- #avail_linodeplans(linodeplan_id = nil) ⇒ Object
- #avail_stackscripts(stackscript_id = nil) ⇒ Object
- #data ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #linode_boot(linode_id, config_id) ⇒ Object
- #linode_config_create(linode_id, kernel_id, name, disk_list) ⇒ Object
- #linode_config_delete(linode_id, config_id) ⇒ Object
- #linode_config_list(linode_id, config_id = nil, options = {}) ⇒ Object
- #linode_config_update(linode_id, config_id, options = {}) ⇒ Object
- #linode_create(datacenter_id, plan_id, payment_term) ⇒ Object
- #linode_delete(linode_id, options = {}) ⇒ Object
- #linode_disk_create(linode_id, name, type, size) ⇒ Object
- #linode_disk_createfromdistribution(linode_id, distro_id, name, size, password) ⇒ Object
- #linode_disk_delete(linode_id, disk_id) ⇒ Object
- #linode_disk_list(linode_id, disk_id = nil) ⇒ Object
- #linode_ip_list(linode_id, ip_id = nil) ⇒ Object
- #linode_list(linode_id = nil) ⇒ Object
- #linode_reboot(linode_id, options = {}) ⇒ Object
- #linode_shutdown(linode_id) ⇒ Object
- #linode_update(linode_id, options = {}) ⇒ Object
- #reset_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
65 66 67 |
# File 'lib/fog/linode/compute.rb', line 65 def initialize(={}) @linode_api_key = [:linode_api_key] end |
Class Method Details
.data ⇒ Object
55 56 57 58 59 |
# File 'lib/fog/linode/compute.rb', line 55 def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end |
.reset ⇒ Object
61 62 63 |
# File 'lib/fog/linode/compute.rb', line 61 def self.reset @data = nil end |
Instance Method Details
#avail_datacenters ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/linode/requests/compute/avail_datacenters.rb', line 21 def avail_datacenters response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "DATA" => [ { "LOCATION" => "Dallas, TX, USA", "DATACENTERID" => 2 }, { "LOCATION" => "Fremont, CA, USA", "DATACENTERID" => 3 }, { "LOCATION" => "Atlanta, GA, USA", "DATACENTERID" => 4 }, { "LOCATION" => "Newark, NJ, USA", "DATACENTERID" => 6 }, { "LOCATION" => "London, England, UK", "DATACENTERID" => 7 }, { "LOCATION" => "Tokyo, JP", "DATACENTERID" => 8 } ], "ACTION" => "avail.datacenters" } response end |
#avail_distributions(distribution_id = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/linode/requests/compute/avail_distributions.rb', line 28 def avail_distributions(distribution_id=nil) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "avail.distributions" } if distribution_id mock_distribution = create_mock_distribution(distribution_id) response.body = body.merge("DATA" => [mock_distribution]) else mock_distributions = [] 10.times do distribution_id = rand(1..99) mock_distributions << create_mock_distribution(distribution_id) end response.body = body.merge("DATA" => mock_distributions) end response end |
#avail_kernels(kernel_id = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/linode/requests/compute/avail_kernels.rb', line 28 def avail_kernels(kernel_id=nil) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "avail.kernels" } if kernel_id mock_kernel = create_mock_kernel(kernel_id) response.body = body.merge("DATA" => [mock_kernel]) else mock_kernels = [] 10.times do kernel_id = rand(1..200) mock_kernels << create_mock_kernel(kernel_id) end response.body = body.merge("DATA" => mock_kernels) end response end |
#avail_linodeplans(linodeplan_id = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/linode/requests/compute/avail_linodeplans.rb', line 30 def avail_linodeplans(linodeplan_id = nil) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "avail.linodeplans" } if linodeplan_id mock_plan = create_mock_linodeplan(linodeplan_id) response.body = body.merge("DATA" => [mock_plan]) else mock_plans = [] 10.times do plan_id = rand(1..99) mock_plans << create_mock_linodeplan(plan_id) end response.body = body.merge("DATA" => mock_plans) end response end |
#avail_stackscripts(stackscript_id = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/linode/requests/compute/avail_stackscripts.rb', line 17 def avail_stackscripts(stackscript_id=nil) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "avail.stackscripts" } if stackscript_id mock_stackscript = create_mock_stackscript(stackscript_id) response.body = body.merge("DATA" => [mock_stackscript]) else mock_stackscripts = [] 10.times do stackscript_id = rand(1..200) mock_stackscripts << create_mock_stackscript(stackscript_id) end response.body = body.merge("DATA" => mock_stackscripts) end response end |
#data ⇒ Object
69 70 71 |
# File 'lib/fog/linode/compute.rb', line 69 def data self.class.data[@linode_api_key] end |
#linode_boot(linode_id, config_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/linode/requests/compute/linode_boot.rb', line 15 def linode_boot(linode_id, config_id) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.boot", "DATA" => { "JobID" => rand(1000..9999) } } response end |
#linode_config_create(linode_id, kernel_id, name, disk_list) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/linode/requests/compute/linode_config_create.rb', line 21 def linode_config_create(linode_id, kernel_id, name, disk_list) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.boot", "DATA" => { "ConfigID" => rand(10000..99999) } } response end |
#linode_config_delete(linode_id, config_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/linode/requests/compute/linode_config_delete.rb', line 19 def linode_config_delete(linode_id, config_id) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.config.delete", "DATA" => { "ConfigID" => rand(10000..99999) } } response end |
#linode_config_list(linode_id, config_id = nil, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/linode/requests/compute/linode_config_list.rb', line 18 def linode_config_list(linode_id, config_id=nil, ={}) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "linode.config.list" } if config_id mock_config = create_mock_config(linode_id, config_id) response.body = body.merge("DATA" => [mock_config]) else mock_configs = [] 5.times do linode_id = rand(10000..99999) config_id = rand(10000..99999) mock_configs << create_mock_config(linode_id, config_id) end response.body = body.merge("DATA" => mock_configs) end response end |
#linode_config_update(linode_id, config_id, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/linode/requests/compute/linode_config_update.rb', line 20 def linode_config_update(linode_id, config_id, ={}) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.config.update", "DATA" => { "ConfigID" => rand(10000..99999) } } response end |
#linode_create(datacenter_id, plan_id, payment_term) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/linode/requests/compute/linode_create.rb', line 31 def linode_create(datacenter_id, plan_id, payment_term) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.create", "DATA" => { "LinodeID" => rand(1000..9999) } } response end |
#linode_delete(linode_id, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/linode/requests/compute/linode_delete.rb', line 26 def linode_delete(linode_id, ={}) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.delete", "DATA" => { "LinodeID" => linode_id } } response end |
#linode_disk_create(linode_id, name, type, size) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/linode/requests/compute/linode_disk_create.rb', line 21 def linode_disk_create(linode_id, name, type, size) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.disk.create", "DATA" => { "JobID" => rand(1000..9999), "DiskID" => rand(10000..99999) } } response end |
#linode_disk_createfromdistribution(linode_id, distro_id, name, size, password) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/linode/requests/compute/linode_disk_createfromdistribution.rb', line 22 def linode_disk_createfromdistribution(linode_id, distro_id, name, size, password) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.disk.createFromDistribution", "DATA" => { "JobID" => rand(1000..9999), "DiskID" => rand(10000..99999) } } response end |
#linode_disk_delete(linode_id, disk_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/linode/requests/compute/linode_disk_delete.rb', line 19 def linode_disk_delete(linode_id, disk_id) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.disk.delete", "DATA" => { "JobID" => rand(1000..9999), "DiskID" => disk_id } } response end |
#linode_disk_list(linode_id, disk_id = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/linode/requests/compute/linode_disk_list.rb', line 19 def linode_disk_list(linode_id, disk_id=nil) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "linode.disk.list" } if disk_id mock_disk = create_mock_disk(linode_id, disk_id) response.body = body.merge("DATA" => [mock_disk]) else mock_disks = [] 2.times do disk_id = rand(10000..99999) mock_disks << create_mock_disk(linode_id, disk_id) end response.body = body.merge("DATA" => mock_disks) end response end |
#linode_ip_list(linode_id, ip_id = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/linode/requests/compute/linode_ip_list.rb', line 19 def linode_ip_list(linode_id, ip_id=nil) response = Excon::Response.new response.status = 200 body = { "ERRORARRAY" => [], "ACTION" => "linode.ip.list" } if ip_id # one IP mock_ip = create_mock_ip(ip_id) response.body = body.merge("DATA" => [mock_ip]) else # all IPs mock_ips = [] ip_id = rand(10000..99999) mock_ips << create_mock_ip(linode_id, ip_id) ip_id = rand(10000..99999) mock_ips << create_mock_ip(linode_id, ip_id, false) response.body = body.merge("DATA" => mock_ips) end response end |
#linode_list(linode_id = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/linode/requests/compute/linode_list.rb', line 28 def linode_list(linode_id=nil) body = { "ERRORARRAY" => [], "ACTION" => "linode.list" } response = Excon::Response.new response.status = 200 if linode_id # one server mock_server = create_mock_server(linode_id) response.body = body.merge("DATA" => [mock_server]) else # all servers mock_servers = [] 5.times do linode_id = rand(100000..999999) mock_servers << create_mock_server(linode_id) end response.body = body.merge("DATA" => mock_servers) end response end |
#linode_reboot(linode_id, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/linode/requests/compute/linode_reboot.rb', line 26 def linode_reboot(linode_id, ={}) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.reboot", "DATA" => { "JobID" => rand(1000..9999) } } response end |
#linode_shutdown(linode_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/linode/requests/compute/linode_shutdown.rb', line 15 def linode_shutdown(linode_id) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.shutdown", "DATA" => { "JobID" => rand(1000..9999) } } response end |
#linode_update(linode_id, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/linode/requests/compute/linode_update.rb', line 15 def linode_update(linode_id, ={}) response = Excon::Response.new response.status = 200 response.body = { "ERRORARRAY" => [], "ACTION" => "linode.update", "DATA" => { "LinodeID" => rand(1000..9999) } } response end |
#reset_data ⇒ Object
73 74 75 |
# File 'lib/fog/linode/compute.rb', line 73 def reset_data self.class.data.delete(@linode_api_key) end |