Module: Deltacloud::Client::Methods::LoadBalancer

Included in:
Connection, Instance, LoadBalancer
Defined in:
lib/deltacloud/client/methods/load_balancer.rb

Instance Method Summary collapse

Instance Method Details

#create_load_balancer(create_opts = {}) ⇒ Object

Create a new load_balancer

  • create_opts

:name - Load Balancer name :realm_id - Load Balancer realm id :listener_protocol - Protocol to use for LB listener (HTTP or TCP) :listener_balancer_port - Load Balancer port (like. 80) :listener_instance_port - Instances port (like, 8080)

Example:

client.create_load_balancer(:name => 'test2', :realm_id => 'us-east-1a', :listener_protocol => 'HTTP', :listener_balancer_port => '80', :listener_instance_port => '8080')


62
63
64
65
66
67
68
# File 'lib/deltacloud/client/methods/load_balancer.rb', line 62

def create_load_balancer(create_opts={})
  must_support! :load_balancers
  response = connection.post(api_uri('load_balancers')) do |request|
    request.params = create_opts
  end
  model(:load_balancer).convert(self, response.body)
end

#destroy_load_balancer(load_balancer_id) ⇒ Object

Destroy load balancer Returns ‘true’ if the response was 204 No Content

  • load_balancer_id -> The ‘id’ of the LoadBalancer to destroy



45
46
47
# File 'lib/deltacloud/client/methods/load_balancer.rb', line 45

def destroy_load_balancer(load_balancer_id)
  destroy_resource :load_balancer, load_balancer_id
end

#load_balancer(load_balancer_id) ⇒ Object

Retrieve the single load_balancer entity

  • load_balancer_id -> LoadBalancer entity to retrieve



35
36
37
38
# File 'lib/deltacloud/client/methods/load_balancer.rb', line 35

def load_balancer(load_balancer_id)
  from_resource :load_balancer,
    connection.get(api_uri("load_balancers/#{load_balancer_id}"))
end

#load_balancers(filter_opts = {}) ⇒ Object

Retrieve list of all load_balancer entities

Filter options:

  • :id -> Filter entities using ‘id’ attribute



26
27
28
29
# File 'lib/deltacloud/client/methods/load_balancer.rb', line 26

def load_balancers(filter_opts={})
  from_collection :load_balancers,
  connection.get(api_uri('load_balancers'), filter_opts)
end

#register_instance(load_balancer_id, instance_id) ⇒ Object

Register an Instance to given Load Balancer

load_balancer_id - Load Balancer to use instance_id - Instance to register to load balancer



75
76
77
78
79
80
# File 'lib/deltacloud/client/methods/load_balancer.rb', line 75

def register_instance(load_balancer_id, instance_id)
  response = connection.post(api_uri("/load_balancers/#{load_balancer_id}/register")) do |request|
    request.params = { 'instance_id' => instance_id }
  end
  model(:load_balancer).convert(self, response.body)
end

#unregister_instance(load_balancer_id, instance_id) ⇒ Object

Unregister an Instance from given Load Balancer

load_balancer_id - Load Balancer to use instance_id - Instance to unregister from load balancer



87
88
89
90
91
92
# File 'lib/deltacloud/client/methods/load_balancer.rb', line 87

def unregister_instance(load_balancer_id, instance_id)
  response = connection.post(api_uri("/load_balancers/#{load_balancer_id}/unregister")) do |request|
    request.params = { 'instance_id' => instance_id }
  end
  model(:load_balancer).convert(self, response.body)
end