Parent

Class/Module Index [+]

Quicksearch

Fog::HP::LB::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/hp/lb.rb, line 43
def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
        :versions => {
          "v1.1" => { "id" => "v1.1",
                      "links" => [{"href" => "http://api-docs.hpcloud.com", "rel" => "self"}],
                      "status" => "CURRENT",
                      "updated" => "2012-12-18T18:30:02.25Z"
          }
        },
        :limits => {
          "absolute" => {
            "values" => {
              "maxLoadBalancerNameLength" => 128,
              "maxLoadBalancers"          => 20,
              "maxNodesPerLoadBalancer"   => 5,
              "maxVIPsPerLoadBalancer"    => 1
            }
          }
        },
        :lbs => {},
        :protocols => {
          "HTTP" => { "name" => "HTTP", "port" => 80 },
          "TCP"  => { "name" => "TCP", "port"  => 443 }
        },
        :algorithms => {
          "ROUND_ROBIN"       => { "name" => "ROUND_ROBIN" },
          "LEAST_CONNECTIONS" => { "name" => "LEAST_CONNECTIONS"}
        }
    }
  end
end
new(options={}) click to toggle source
# File lib/fog/hp/lb.rb, line 80
def initialize(options={})
  @hp_access_key = options[:hp_access_key]
end
reset() click to toggle source
# File lib/fog/hp/lb.rb, line 76
def self.reset
  @data = nil
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 70
def create_load_balancer(name, nodes, options={})
  ### Call: {"name" => "my-shiny-lb1", "nodes" => [{"address" => "15.185.1.1", "port" => "80"}]}
  response = Excon::Response.new
  response.status = 202
  # add the id, and other attributes that are added by the system
  nodes.each do |n|
    n['id']         = Fog::HP::Mock.uuid.to_s
    n['condition']  = 'ENABLED'
    n['status']     = 'ONLINE'
  end
  data = {
      'id'        => Fog::HP::Mock.uuid.to_s,
      'name'      => name,
      'protocol'  => options['protocol'] || 'HTTP',
      'port'      => options['port'] || '80',
      'algorithm' => options['algorithm'] || 'ROUND_ROBIN',
      'status'    => 'ACTIVE',
      'created'   => '2012-01-01T13:32:20Z',
      'updated'   => '2012-01-01T13:32:20Z',
      'nodes'     => nodes
  }
  if (!options['virtualIps'].nil? && !options['virtualIps'].empty?)
    data['virtualIps'] = options['virtualIps']
  else
    data['virtualIps'] = [{
                     'ipVersion' => 'IPV4',
                     'type' => 'PUBLIC',
                     'id' => Fog::HP::Mock.uuid.to_s,
                     'address' => Fog::HP::Mock.ip_address
                  }]
  end

  self.data[:lbs][data['id']] = data
  response.body = data
  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 45
def create_load_balancer_node(load_balancer_id, address, port, options={})
  response = Excon::Response.new
  if get_load_balancer(load_balancer_id)
    response.status = 202

    data = {
        'id'        => Fog::HP::Mock.uuid.to_s,
        'address'   => address,
        'port'      => port,
        'condition' => options['condition'] || 'ENABLED',
        'status'    => 'ONLINE'
    }

    self.data[:lbs][load_balancer_id]['nodes'] << data
    response.body = {'nodes' => [data]}
    response
  else
    raise Fog::HP::LB::NotFound
  end
end
data() click to toggle source
# File lib/fog/hp/lb.rb, line 84
def data
  self.class.data[@hp_access_key]
end
delete_load_balancer(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/delete_load_balancer.rb, line 20
def delete_load_balancer(load_balancer_id)
  response = Excon::Response.new
  if list_load_balancers.body['loadBalancers'].find { |_| _['id'] == load_balancer_id }
    response.status = 202
    response
  else
    raise Fog::HP::LB::NotFound
  end
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 20
def delete_load_balancer_node(load_balancer_id, node_id)
  response = Excon::Response.new
  if get_load_balancer(load_balancer_id)
    if get_load_balancer_node(load_balancer_id, node_id)
      response.status = 202
      nodes = delete_node(load_balancer_id, node_id)
      self.data[:lbs][load_balancer_id]['nodes'] = nodes
      response
    else
      raise Fog::HP::LB::NotFound
    end
  else
    raise Fog::HP::LB::NotFound
  end
end
delete_node(load_balancer_id, node_id) click to toggle source
# File lib/fog/hp/requests/lb/delete_load_balancer_node.rb, line 36
def delete_node(load_balancer_id, node_id)
  nodes = list_load_balancer_nodes(load_balancer_id).body['nodes']
  nodes.reject {|n| n['id'] == node_id}
end
find_node(load_balancer_id, node_id) click to toggle source
# File lib/fog/hp/requests/lb/get_load_balancer_node.rb, line 44
def find_node(load_balancer_id, node_id)
  nodes = list_load_balancer_nodes(load_balancer_id).body['nodes']
  nodes.find {|n| n['id'] == node_id}
end
get_load_balancer(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/get_load_balancer.rb, line 44
def get_load_balancer(load_balancer_id)
  response = Excon::Response.new
  if lb = list_load_balancers.body['loadBalancers'].find { |_| _['id'] == load_balancer_id }
    response.status = 200
    response.body = lb
    response
  else
    raise Fog::HP::LB::NotFound
  end
end
get_load_balancer_node(load_balancer_id, node_id) click to toggle source
# File lib/fog/hp/requests/lb/get_load_balancer_node.rb, line 29
def get_load_balancer_node(load_balancer_id, node_id)
  response = Excon::Response.new
  if get_load_balancer(load_balancer_id)
   if node = find_node(load_balancer_id, node_id)
     response.status = 200
     response.body = node
     response
   else
     raise Fog::HP::LB::NotFound
   end
  else
    raise Fog::HP::LB::NotFound
  end
end
list_algorithms() click to toggle source
# File lib/fog/hp/requests/lb/list_algorithms.rb, line 21
def list_algorithms
  response = Excon::Response.new
  algorithms  = self.data[:algorithms].values
  response.status = 200
  response.body = { 'algorithms' => algorithms }
  response
end
list_limits() click to toggle source
# File lib/fog/hp/requests/lb/list_limits.rb, line 26
def list_limits
  response        = Excon::Response.new
  limits          = self.data[:limits].values
  response.status = 200
  response.body   = { 'limits' => limits }
  response
end
list_load_balancer_nodes(load_balancer_id) click to toggle source
# File lib/fog/hp/requests/lb/list_load_balancer_nodes.rb, line 26
def list_load_balancer_nodes(load_balancer_id)
  response = Excon::Response.new
  if lb = get_load_balancer(load_balancer_id).body
    response.status = 200
    response.body   = {'nodes' => lb['nodes']}
    response
  else
    raise Fog::HP::LB::NotFound
  end
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 27
def list_load_balancer_virtual_ips(load_balancer_id)
  response = Excon::Response.new
  if lb_data = get_load_balancer(load_balancer_id)
    virtual_ips = lb_data.body['virtualIps']
    response.status = 200
    response.body   = { 'virtualIps' => virtual_ips }
    response
  else
    raise Fog::HP::LB::NotFound
  end
end
list_load_balancers() click to toggle source
# File lib/fog/hp/requests/lb/list_load_balancers.rb, line 29
def list_load_balancers
  response = Excon::Response.new
  lbs = self.data[:lbs].values
  response.status = 200
  response.body = { 'loadBalancers' => lbs }
  response
end
list_protocols() click to toggle source
# File lib/fog/hp/requests/lb/list_protocols.rb, line 23
def list_protocols
  response = Excon::Response.new
  protocols  = self.data[:protocols].values
  response.status = 200
  response.body   = { 'protocols' => protocols }
  response
end
list_versions() click to toggle source
# File lib/fog/hp/requests/lb/list_versions.rb, line 14
def list_versions
  response        = Excon::Response.new
  versions       = self.data[:versions].values
  response.status = 200
  response.body   = { 'versions' => versions }
  response
end
reset_data() click to toggle source
# File lib/fog/hp/lb.rb, line 88
def reset_data
  self.class.data.delete(@hp_access_key)
end
update_load_balancer(load_balancer_id, options={}) click to toggle source
# File lib/fog/hp/requests/lb/update_load_balancer.rb, line 28
def update_load_balancer(load_balancer_id, options={})
  response = Excon::Response.new
  if lb = list_load_balancers.body['loadBalancers'].find { |_| _['id'] == load_balancer_id }

    lb['name']      = options['name']      if options['name']
    lb['algorithm'] = options['algorithm'] if options['algorithm']

    response.status = 202
    response.body   = ''
    response
  else
    raise Fog::HP::LB::NotFound
  end
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 25
def update_load_balancer_node(load_balancer_id, node_id, condition)
  response = Excon::Response.new
  if lb_data = get_load_balancer(load_balancer_id)
    if get_load_balancer_node(load_balancer_id, node_id)
      nodes = update_node(lb_data, node_id, condition)
      self.data[:lbs][load_balancer_id]['nodes'] = nodes
      response.status = 202
      response
    else
      raise Fog::HP::LB::NotFound
    end
  else
    raise Fog::HP::LB::NotFound
  end
end
update_node(lb_data, node_id, condition) click to toggle source
# File lib/fog/hp/requests/lb/update_load_balancer_node.rb, line 41
def update_node(lb_data, node_id, condition)
  nodes = lb_data.body['nodes']
  node = nodes.select {|n| n['id'] == node_id}.first
  # update the node attributes
  if node
    node['condition'] = condition
    node['status'] = condition == 'ENABLED' ? 'ONLINE' : 'OFFLINE'
  end
  new_nodes = nodes.reject {|n| n['id'] == node_id}
  new_nodes << node
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.