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/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.



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

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

Class Method Details

.dataObject



62
63
64
65
66
# File 'lib/fog/linode/compute.rb', line 62

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

.resetObject



68
69
70
# File 'lib/fog/linode/compute.rb', line 68

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
# 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

#dataObject



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

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



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

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