Class: Fog::Rackspace::LoadBalancers::Mock

Inherits:
Service
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/rackspace/load_balancers.rb,
lib/fog/rackspace/requests/load_balancers/get_stats.rb,
lib/fog/rackspace/requests/load_balancers/get_load_balancer.rb,
lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb,
lib/fog/rackspace/requests/load_balancers/delete_load_balancer.rb

Instance Method Summary collapse

Methods included from Shared

#algorithms, #protocols, #usage

Methods inherited from Service

#authenticate, #endpoint_uri, #region, #request, #request_without_retry, #service_name, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



95
96
97
98
99
# File 'lib/fog/rackspace/load_balancers.rb', line 95

def initialize(options={})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
end

Instance Method Details

#create_load_balancer(name, protocol, port, virtual_ips, nodes, options = {}) ⇒ Object



48
49
50
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb', line 48

def create_load_balancer(name, protocol, port, virtual_ips, nodes, options = {})
  data = {
    "loadBalancer" => {
      "name" => name,
      "id" => Fog::Mock.random_numbers(6),
      "protocol" => protocol,
      "port" => port,
      "algorithm" => "RANDOM",
      "status" => "BUILD",
      "cluster" => { "name" => "my-cluster.rackspace.net" },
      "timeout" => 30,
      "created" => {"time" => MockData.zulu_time },
      "updated" => {"time" => MockData.zulu_time },
      "halfClosed" => false,
      "connectionLogging" => { "enabled" => false },
      "contentCaching" => { "enabled" => false },
      "httpsRedirect" => false
    }
  }

  data["virtual_ips"] = virtual_ips.map do |n|
    {
      "virtualIps" => [
        {
          "address" => MockData.ipv4_address,
          "id" => Fog::Mock.random_numbers(6),
          "type" => n.type,
          "ipVersion" => "IPV4"
        },
        {
          "address" => MockData.ipv6_address,
          "id" => Fog::Mock.random_numbers(4),
          "type" => "PUBLIC",
          "ipVersion" => "IPV6"
        }
      ],
      "sourceAddresses" => {
        "ipv6Public" => MockData.ipv6_address,
        "ipv4Servicenet" => MockData.ipv4_address,
        "ipv4Public" => MockData.ipv4_address
      }
    }
  end

  data["nodes"] = nodes.map do |n|
    {
      "address" => n.address,
      "id" => Fog::Mock.random_numbers(6),
      "type" => "PRIMARY",
      "port" => n.port,
      "status" => "ONLINE",
      "condition" => "ENABLED",
      "weight" => 1
    }
  end

  Excon::Response.new(:body => data, :status => 202)
end

#delete_load_balancer(load_balancer_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/rackspace/requests/load_balancers/delete_load_balancer.rb', line 15

def delete_load_balancer(load_balancer_id)
  response = Excon::Response.new
  response.status = 202
  response.body = ""
end

#get_load_balancer(load_balancer_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/rackspace/requests/load_balancers/get_load_balancer.rb', line 15

def get_load_balancer(load_balancer_id)
 response = Excon::Response.new
 response.status = 200
 response.body =  {
   "loadBalancer"=> {
     "name"=>"load_balancer_#{load_balancer_id}",
     "id"=> load_balancer_id,
     "protocol"=>"HTTP",
     "port"=>80,
     "algorithm"=>"RANDOM",
     "status"=>"ACTIVE",
     "cluster"=>{"name"=>"my-cluster.rackspace.net"},
     "nodes"=>[{"address"=> MockData.ipv4_address, "id"=> Fog::Mock.random_numbers(6), "type"=>"PRIMARY", "port"=>80, "status"=>"ONLINE", "condition"=>"ENABLED"}],
     "timeout"=>30,
     "created"=>{"time"=>MockData.zulu_time},
     "virtualIps"=>[
       {"address"=> MockData.ipv4_address, "id"=>Fog::Mock.random_numbers(4), "type"=>"PUBLIC", "ipVersion"=>"IPV4"},
       {"address"=> MockData.ipv6_address, "id"=>Fog::Mock.random_numbers(4), "type"=>"PUBLIC", "ipVersion"=>"IPV6"}],
     "sourceAddresses"=>{"ipv6Public"=> MockData.ipv6_address, "ipv4Servicenet"=> MockData.ipv4_address, "ipv4Public"=> MockData.ipv4_address},
     "updated"=>{"time"=>"2013-09-04T06:29:09Z"},
     "halfClosed"=>false,
     "connectionLogging"=>{"enabled"=>false},
     "contentCaching"=>{"enabled"=>false},
     "httpsRedirect"=>false}}
   response
end

#get_stats(load_balancer_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/rackspace/requests/load_balancers/get_stats.rb', line 15

def get_stats(load_balancer_id)
  mock_data = {
      'connectTimeOut' => 0,
      'connectError' => 1,
      'connectFailure' => 2,
      'dataTimedOut' => 3,
      'keepAliveTimedOut' => 4,
      'maxConn' => 5
  }

  Excon::Response.new(:body => mock_data, :status => 200)
end