Class: Fog::HP::LB::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/hp/requests/lb/list_limits.rb,
lib/fog/hp/lb.rb,
lib/fog/hp/requests/lb/list_versions.rb,
lib/fog/hp/requests/lb/list_protocols.rb,
lib/fog/hp/requests/lb/list_algorithms.rb,
lib/fog/hp/requests/lb/get_load_balancer.rb,
lib/fog/hp/requests/lb/list_load_balancers.rb,
lib/fog/hp/requests/lb/create_load_balancer.rb,
lib/fog/hp/requests/lb/delete_load_balancer.rb,
lib/fog/hp/requests/lb/update_load_balancer.rb,
lib/fog/hp/requests/lb/get_load_balancer_node.rb,
lib/fog/hp/requests/lb/list_load_balancer_nodes.rb,
lib/fog/hp/requests/lb/create_load_balancer_node.rb,
lib/fog/hp/requests/lb/delete_load_balancer_node.rb,
lib/fog/hp/requests/lb/update_load_balancer_node.rb,
lib/fog/hp/requests/lb/list_load_balancer_virtual_ips.rb

Overview

List virtual IPs for an existing load balancer

Parameters

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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘virtualIps’<~Array>:

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

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

        • ‘type’<~String> - Type for the virtual IP e.g. ‘PUBLIC’

        • ‘ipVersion’<~String> - Version for virtual IP e.g. ‘IPV4’, ‘IPV6’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fog/hp/lb.rb', line 101

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] ||= "Load Balancer"
  @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::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



98
99
100
# File 'lib/fog/hp/lb.rb', line 98

def credentials
  @credentials
end

Instance Method Details

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/hp/requests/lb/create_load_balancer.rb', line 42

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 = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/hp/requests/lb/create_load_balancer_node.rb', line 24

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) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/fog/hp/requests/lb/delete_load_balancer.rb', line 12

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) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/fog/hp/requests/lb/delete_load_balancer_node.rb', line 13

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) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/fog/hp/requests/lb/get_load_balancer.rb', line 36

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) ⇒ Object

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’



20
21
22
23
24
25
26
# File 'lib/fog/hp/requests/lb/get_load_balancer_node.rb', line 20

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_algorithmsObject



13
14
15
16
17
18
19
# File 'lib/fog/hp/requests/lb/list_algorithms.rb', line 13

def list_algorithms
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'algorithms'
  )
end

#list_limitsObject



19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/lb/list_limits.rb', line 19

def list_limits
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'limits'
  )
end

#list_load_balancer_nodes(load_balancer_id) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/fog/hp/requests/lb/list_load_balancer_nodes.rb', line 17

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) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/lb/list_load_balancer_virtual_ips.rb', line 19

def list_load_balancer_virtual_ips(load_balancer_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "loadbalancers/#{load_balancer_id}/virtualips"
  )
end

#list_load_balancersObject



21
22
23
24
25
26
27
# File 'lib/fog/hp/requests/lb/list_load_balancers.rb', line 21

def list_load_balancers
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'loadbalancers'
  )
end

#list_protocolsObject



14
15
16
17
18
19
20
21
# File 'lib/fog/hp/requests/lb/list_protocols.rb', line 14

def list_protocols
  response = request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'protocols'
  )
  response
end

#list_versionsObject



6
7
8
9
10
11
12
# File 'lib/fog/hp/requests/lb/list_versions.rb', line 6

def list_versions
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => ''
  )
end

#reloadObject



138
139
140
# File 'lib/fog/hp/lb.rb', line 138

def reload
  @connection.reset
end

#request(params, parse_json = true, &block) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/fog/hp/lb.rb', line 142

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 = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/hp/requests/lb/update_load_balancer.rb', line 13

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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/lb/update_load_balancer_node.rb', line 14

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