class Fog::HP::LB::Real

Create a new load balancer

Parameters

Returns

Create a new load balancer node

Parameters

Returns

Delete an existing load balancer

Parameters

Delete an existing load balancer node

Parameters

Get details for an existing load balancer

Parameters

Returns

List algorithms

Returns

List limits

Returns

List all load balancer nodes

Returns

List virtual IPs for an existing load balancer

Parameters

Returns

List all load balancers

Returns

List protocols

Returns

Update an existing load balancer

Parameters

Update an existing load balancer node

Parameters

Attributes

credentials[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/hp/lb.rb, line 96
def initialize(options={})
  @hp_access_key = options[:hp_access_key]
  @hp_secret_key      = options[:hp_secret_key]
  @hp_auth_uri        = options[:hp_auth_uri]
  @connection_options = options[:connection_options] || {}
  ### Set an option to use the style of authentication desired; :v1 or :v2 (default)
  auth_version        = options[:hp_auth_version] || :v2
  ### Pass the service name for object storage to the authentication call
  options[:hp_service_type] ||= "hpext:lbaas"
  @hp_tenant_id       = options[:hp_tenant_id]
  @hp_avl_zone        = options[:hp_avl_zone]

  ### Make the authentication call
  if (auth_version == :v2)
    # Call the control services authentication
    credentials = Fog::HP.authenticate_v2(options, @connection_options)
    # the CS service catalog returns the block storage endpoint
    @hp_block_uri = credentials[:endpoint_url]
  else
    # Call the legacy v1.0/v1.1 authentication
    credentials = Fog::HP.authenticate_v1(options, @connection_options)
    # the user sends in the block storage endpoint
    @hp_block_uri = options[:hp_auth_uri]
  end

  @auth_token = credentials[:auth_token]
  @persistent = options[:persistent] || false

  uri = URI.parse(@hp_block_uri)
  @host   = uri.host
  @path   = uri.path
  @port   = uri.port
  @scheme = uri.scheme

  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Public Instance Methods

create_load_balancer(name, nodes, options={}) click to toggle source
# File lib/fog/hp/requests/lb/create_load_balancer.rb, line 41
def create_load_balancer(name, nodes, options={})
  ### Inconsistent behavior. Should be passing in as a 'loadbalancer' => {'name', 'nodes'}
  data = {
    'name'  => name,
    'nodes' => nodes
  }
  l_options = ['port', 'protocol', 'algorithm']
  l_options.select{|o| options[o]}.each do |key|
    data[key] = options[key]
  end

  if options['virtualIps']
    data['virtualIps'] = []
    for vip in options['virtualIps']
      data['virtualIps'] << vip
    end
  end

  response = request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'POST',
    :path    => 'loadbalancers'
  )
  response
end
create_load_balancer_node(load_balancer_id, address, port, options={}) click to toggle source
# File lib/fog/hp/requests/lb/create_load_balancer_node.rb, line 23
def create_load_balancer_node(load_balancer_id, address, port, options={})
  data = {
    'nodes' => [
        {
            'address' => address,
            'port'    => port
        }
    ]
  }
  if options['condition']
    data['nodes'][0]['condition'] = options['condition']
  end

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'POST',
    :path    => "loadbalancers/#{load_balancer_id}/nodes"
  )
end
delete_load_balancer(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/delete_load_balancer.rb, line 10
def delete_load_balancer(load_balancer_id)
  request(
      :expects => 202,
      :method  => 'DELETE',
      :path    => "loadbalancers/#{load_balancer_id}"
  )
end
delete_load_balancer_node(load_balancer_id, node_id) click to toggle source
# File lib/fog/hp/requests/lb/delete_load_balancer_node.rb, line 11
def delete_load_balancer_node(load_balancer_id, node_id)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}"
  )
end
get_load_balancer(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/get_load_balancer.rb, line 35
def get_load_balancer(load_balancer_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "loadbalancers/#{load_balancer_id}"
  )
end
get_load_balancer_node(load_balancer_id, node_id) click to toggle source

Get details for an existing load balancer node

Parameters

  • ‘load_balancer_id’<~String> - UUId of the load balancer to get

  • ‘node_id’<~String> - UUId of node to get

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUId for the node

      • ‘address’<~String> - Address for the node

      • ‘port’<~String> - Port for the node

      • ‘condition’<~String> - Condition for the node e.g. ‘ENABLED’

      • ‘status’<~String> - Status for the node e.g. ‘ONLINE’

# File lib/fog/hp/requests/lb/get_load_balancer_node.rb, line 19
def get_load_balancer_node(load_balancer_id, node_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}"
  )
end
list_algorithms() click to toggle source
# File lib/fog/hp/requests/lb/list_algorithms.rb, line 12
def list_algorithms
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'algorithms'
  )
end
list_limits() click to toggle source
# File lib/fog/hp/requests/lb/list_limits.rb, line 17
def list_limits
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'limits'
  )
end
list_load_balancer_nodes(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/list_load_balancer_nodes.rb, line 16
def list_load_balancer_nodes(load_balancer_id)
  response = request(
    :expects => 200,
    :method  => 'GET',
    :path    => "loadbalancers/#{load_balancer_id}/nodes"
  )
  response
end
list_load_balancer_virtual_ips(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/list_load_balancer_virtual_ips.rb, line 18
def list_load_balancer_virtual_ips(load_balancer_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "loadbalancers/#{load_balancer_id}/virtualips"
  )
end
list_load_balancers() click to toggle source
# File lib/fog/hp/requests/lb/list_load_balancers.rb, line 20
def list_load_balancers
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'loadbalancers'
  )
end
list_protocols() click to toggle source
# File lib/fog/hp/requests/lb/list_protocols.rb, line 13
def list_protocols
  response = request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'protocols'
  )
  response
end
list_versions() click to toggle source
# File lib/fog/hp/requests/lb/list_versions.rb, line 5
def list_versions
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => ''
  )
end
reload() click to toggle source
# File lib/fog/hp/lb.rb, line 133
def reload
  @connection.reset
end
request(params, parse_json = true, &block) click to toggle source
# File lib/fog/hp/lb.rb, line 137
def request(params, parse_json = true, &block)
  begin
    response = @connection.request(params.merge!({
       :headers => {
         'Content-Type' => 'application/json',
         'Accept'       => 'application/json',
         'X-Auth-Token' => @auth_token
       }.merge!(params[:headers] || {}),
       :path    => "#{@path}/#{params[:path]}",
   }), &block)
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::HP::LB::NotFound.slurp(error)
    else
      error
    end
  end
  if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
    response.body = Fog::JSON.decode(response.body)
  end
  response
end
update_load_balancer(load_balancer_id, options={}) click to toggle source
# File lib/fog/hp/requests/lb/update_load_balancer.rb, line 12
def update_load_balancer(load_balancer_id, options={})
  data = {}
  l_options = ['name', 'algorithm']
  l_options.select{|o| options[o]}.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'PUT',
    :path    => "loadbalancers/#{load_balancer_id}"
  )
end
update_load_balancer_node(load_balancer_id, node_id, condition) click to toggle source
# File lib/fog/hp/requests/lb/update_load_balancer_node.rb, line 12
def update_load_balancer_node(load_balancer_id, node_id, condition)
  data = {
    'condition' => condition
  }
  request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'PUT',
    :path    => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}"
  )
end