Class: Fog::Compute::Linode::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/linode/compute.rb,
lib/fog/linode/requests/compute/image_list.rb,
lib/fog/linode/requests/compute/linode_boot.rb,
lib/fog/linode/requests/compute/linode_list.rb,
lib/fog/linode/requests/compute/image_delete.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/linode_disk_resize.rb,
lib/fog/linode/requests/compute/linode_disk_update.rb,
lib/fog/linode/requests/compute/avail_distributions.rb,
lib/fog/linode/requests/compute/avail_nodebalancers.rb,
lib/fog/linode/requests/compute/linode_disk_imagize.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_duplicate.rb,
lib/fog/linode/requests/compute/linode_disk_createfromimage.rb,
lib/fog/linode/requests/compute/linode_disk_createfromdistribution.rb

Overview

request :linode_resize

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



75
76
77
# File 'lib/fog/linode/compute.rb', line 75

def initialize(options={})
  @linode_api_key = options[:linode_api_key]
end

Class Method Details

.dataObject



65
66
67
68
69
# File 'lib/fog/linode/compute.rb', line 65

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {}
  end
end

.resetObject



71
72
73
# File 'lib/fog/linode/compute.rb', line 71

def self.reset
  @data = nil
end

Instance Method Details

#avail_datacentersObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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,  "ABBR" => "dallas" },
      { "LOCATION" => "Fremont, CA, USA",    "DATACENTERID" => 3,  "ABBR" => "fremont" },
      { "LOCATION" => "Atlanta, GA, USA",    "DATACENTERID" => 4,  "ABBR" => "atlanta" },
      { "LOCATION" => "Newark, NJ, USA",     "DATACENTERID" => 6,  "ABBR" => "newark" },
      { "LOCATION" => "London, England, UK", "DATACENTERID" => 7,  "ABBR" => "london" },
      { "LOCATION" => "Tokyo, JP",           "DATACENTERID" => 8,  "ABBR" => "tokyo" },
      { "LOCATION" => "Singapore, SGP",      "DATACENTERID" => 9,  "ABBR" => "singapore" },
      { "LOCATION" => "Frankfurt, DE",       "DATACENTERID" => 10, "ABBR" => "frankfurt" },
      { "LOCATION" => "Tokyo 2, JP",         "DATACENTERID" => 11, "ABBR" => "tokyo2" },
    ],
    "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(options = {}) ⇒ Object

Raises:

  • (Fog::Errors::Error)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/linode/requests/compute/avail_kernels.rb', line 28

def avail_kernels(options={})
  # avail.kernels used to accept a kernelId parameter (now removed)
  raise Fog::Errors::Error.new('avail_kernels no longer accepts a kernelId parameter') unless !options || options.is_a?(Hash)

  response = Excon::Response.new
  response.status = 200

  body = {
    "ERRORARRAY" => [],
    "ACTION" => "avail.kernels"
  }
  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)
  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_nodebalancersObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/linode/requests/compute/avail_nodebalancers.rb', line 25

def avail_nodebalancers
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION" => "avail.nodebalancers",
    "DATA" => [{
      "MONTHLY" => 20.0,
      "HOURLY" => 0.03,
      "CONNECTIONS" => 10000
    }]
  }
  response
end

#avail_stackscripts(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/linode/requests/compute/avail_stackscripts.rb', line 17

def avail_stackscripts(options={})
  response = Excon::Response.new
  response.status = 200

  body = {
    "ERRORARRAY" => [],
    "ACTION" => "avail.stackscripts"
  }
  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)
  response
end

#dataObject



79
80
81
# File 'lib/fog/linode/compute.rb', line 79

def data
  self.class.data[@linode_api_key]
end

#image_delete(image_id, status = 'available') ⇒ Object



18
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/image_delete.rb', line 18

def image_delete(image_id, status='available')
  size = rand(1..999999)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "image.delete",
    "DATA"       => { "LAST_USED_DT" => "2014-07-21 12:31:54.0",
                      "DESCRIPTION" => "Fog Mock Linode Image #{image_id}",
                      "LABEL" => "test_#{image_id}_image",
                      "STATUS" => status,
                      "SIZE" => size,
                      "ISPUBLIC" => rand(0..1),
                      "CREATE_DT" => "2014-06-23 13:45:12.0",
                      "USED" => rand(1..size),
                      "FS_TYPE" => "ext4",
                      "USERID" => Fog::Mock.random_numbers(4),
                      "IMAGEID" => image_id }
  }
  response
end

#image_list(pending = nil, image_id = nil) ⇒ Object



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/image_list.rb', line 22

def image_list(pending=nil, image_id=nil)
  response = Excon::Response.new
  response.status = 200
  body = {
    "ERRORARRAY" => [],
    "ACTION" => "image.list"
  }
  if image_id
    mock_image = create_mock_image(image_id)
    response.body = body.merge("DATA" => [mock_image])
  else
    mock_images = []
    rand(1..3).times do
      image_id = Fog::Mock.random_numbers(5)
      mock_images << create_mock_image(image_id)
    end
    response.body = body.merge("DATA" => mock_images)
  end
  response
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, options={})
  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, options={})
  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, options={})
  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_createfromimage(linode_id, image_id, label, size, password, sshkey) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/linode/requests/compute/linode_disk_createfromimage.rb', line 23

def linode_disk_createfromimage(linode_id, image_id, label, size, password, sshkey)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "linode.disk.createfromimage",
    "DATA"       => { "JobID" => Fog::Mock.random_numbers(4),
                      "DiskID" => Fog::Mock.random_numbers(5) }
  }
  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_duplicate(linode_id, disk_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/linode/requests/compute/linode_disk_duplicate.rb', line 19

def linode_disk_duplicate(linode_id, disk_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "linode.disk.duplicate",
    "DATA"       => { "JobID" => Fog::Mock.random_numbers(4),
                      "DiskID" => Fog::Mock.random_numbers(5) }
  }
  response
end

#linode_disk_imagize(linode_id, disk_id, description, label) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/linode/requests/compute/linode_disk_imagize.rb', line 21

def linode_disk_imagize(linode_id, disk_id, description, label)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "linode.disk.imagize",
    "DATA"       => {
      "JobID" => Fog::Mock.random_numbers(4),
      "ImageID" => Fog::Mock.random_numbers(4)
	    }
  }
  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_disk_resize(linode_id, disk_id, size) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/linode/requests/compute/linode_disk_resize.rb', line 20

def linode_disk_resize(linode_id, disk_id, size)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "linode.disk.resize",
    "DATA"       => {
      "JobID" => Fog::Mock.random_numbers(4),
      "DiskID" => Fog::Mock.random_numbers(4)
	    }
  }
  response
end

#linode_disk_update(linode_id, disk_id, label, isreadonly) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/linode/requests/compute/linode_disk_update.rb', line 21

def linode_disk_update(linode_id, disk_id, label, isreadonly)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "linode.disk.update",
    "DATA"       => { "DiskID" => Fog::Mock.random_numbers(5) }
  }
  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, options={})
  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, options={})
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "ERRORARRAY" => [],
    "ACTION"     => "linode.update",
    "DATA"       => { "LinodeID" => rand(1000..9999) }
  }
  response
end

#reset_dataObject



83
84
85
# File 'lib/fog/linode/compute.rb', line 83

def reset_data
  self.class.data.delete(@linode_api_key)
end