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

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/linode/compute.rb,
lib/rackspace-fog/linode/requests/compute/linode_boot.rb,
lib/rackspace-fog/linode/requests/compute/linode_list.rb,
lib/rackspace-fog/linode/requests/compute/avail_kernels.rb,
lib/rackspace-fog/linode/requests/compute/linode_create.rb,
lib/rackspace-fog/linode/requests/compute/linode_delete.rb,
lib/rackspace-fog/linode/requests/compute/linode_reboot.rb,
lib/rackspace-fog/linode/requests/compute/linode_update.rb,
lib/rackspace-fog/linode/requests/compute/linode_ip_list.rb,
lib/rackspace-fog/linode/requests/compute/linode_shutdown.rb,
lib/rackspace-fog/linode/requests/compute/linode_disk_list.rb,
lib/rackspace-fog/linode/requests/compute/avail_datacenters.rb,
lib/rackspace-fog/linode/requests/compute/avail_linodeplans.rb,
lib/rackspace-fog/linode/requests/compute/avail_stackscripts.rb,
lib/rackspace-fog/linode/requests/compute/linode_config_list.rb,
lib/rackspace-fog/linode/requests/compute/linode_disk_create.rb,
lib/rackspace-fog/linode/requests/compute/linode_disk_delete.rb,
lib/rackspace-fog/linode/requests/compute/avail_distributions.rb,
lib/rackspace-fog/linode/requests/compute/linode_config_create.rb,
lib/rackspace-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.



66
67
68
# File 'lib/rackspace-fog/linode/compute.rb', line 66

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

Class Method Details

.dataObject



56
57
58
59
60
# File 'lib/rackspace-fog/linode/compute.rb', line 56

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

.resetObject



62
63
64
# File 'lib/rackspace-fog/linode/compute.rb', line 62

def self.reset
  @data = nil
end

Instance Method Details

#avail_datacentersObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rackspace-fog/linode/requests/compute/avail_datacenters.rb', line 23

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rackspace-fog/linode/requests/compute/avail_distributions.rb', line 30

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rackspace-fog/linode/requests/compute/avail_kernels.rb', line 30

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rackspace-fog/linode/requests/compute/avail_linodeplans.rb', line 34

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rackspace-fog/linode/requests/compute/avail_stackscripts.rb', line 19

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



70
71
72
# File 'lib/rackspace-fog/linode/compute.rb', line 70

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

#linode_boot(linode_id, config_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/rackspace-fog/linode/requests/compute/linode_boot.rb', line 17

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



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

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_list(linode_id, config_id = nil, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rackspace-fog/linode/requests/compute/linode_config_list.rb', line 20

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_create(datacenter_id, plan_id, payment_term) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/rackspace-fog/linode/requests/compute/linode_create.rb', line 33

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



28
29
30
31
32
33
34
35
36
37
# File 'lib/rackspace-fog/linode/requests/compute/linode_delete.rb', line 28

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



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

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rackspace-fog/linode/requests/compute/linode_disk_createfromdistribution.rb', line 24

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



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

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rackspace-fog/linode/requests/compute/linode_disk_list.rb', line 21

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rackspace-fog/linode/requests/compute/linode_ip_list.rb', line 21

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rackspace-fog/linode/requests/compute/linode_list.rb', line 30

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



28
29
30
31
32
33
34
35
36
37
# File 'lib/rackspace-fog/linode/requests/compute/linode_reboot.rb', line 28

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



17
18
19
20
21
22
23
24
25
26
# File 'lib/rackspace-fog/linode/requests/compute/linode_shutdown.rb', line 17

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



17
18
19
20
21
22
23
24
25
26
# File 'lib/rackspace-fog/linode/requests/compute/linode_update.rb', line 17

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



74
75
76
# File 'lib/rackspace-fog/linode/compute.rb', line 74

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