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.



97
98
99
100
101
# File 'lib/fog/rackspace/load_balancers.rb', line 97

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



29
30
31
32
33
34
35
36
# File 'lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb', line 29

def create_load_balancer(name, protocol, port, virtual_ips, nodes, options = {})
  data = {"loadBalancer"=>{"name"=>name, "id"=>uniq_id, "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}}}
  data["virtual_ips"] = virtual_ips.collect {|n| {"virtualIps"=>[{"address"=> MockData.ipv4_address, "id"=>uniq_id, "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}}
  data["nodes"] = nodes.collect {|n| {"address"=>n[:address], "id"=>uniq_id, "type"=>"PRIMARY", "port"=>n[:port], "status"=>"ONLINE", "condition"=>"ENABLED", "weight"=>1}}}
  Excon::Response.new(:body => data, :status => 202)
end

#delete_load_balancer(load_balancer_id) ⇒ Object



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

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

#get_load_balancer(load_balancer_id) ⇒ Object



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 16

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}}}
   response
end

#get_stats(load_balancer_id) ⇒ Object



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

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