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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/monkey/hp/lb.rb', line 112

def initialize(options={})
  # deprecate hp_account_id
  if options[:hp_account_id]
    Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.")
    options[:hp_access_key] = options.delete(:hp_account_id)
  end
  @hp_access_key = options[:hp_access_key]
  unless @hp_access_key
    raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.")
  end
  @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.



109
110
111
# File 'lib/monkey/hp/lb.rb', line 109

def credentials
  @credentials
end

Instance Method Details

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/monkey/hp/requests/lb/create_load_balancer.rb', line 26

def create_load_balancer(name, nodes, options={})
  data = {
    "name"  => name,
    "nodes" => nodes
  }
  options = Hash[options.map{ |k, v| [k.to_s, v] }]
  data['port'] = options['port'] if options['port']
  data['protocol'] = options['protocol'] if options['protocol']
  data['algorithm'] = options['algorithm'] if options['algorithm']
  unless options['virtualIps'].nil?
    unless options['virtualIps'].empty?
      data['virtualIps'] = []
      for vip in options['virtualIps']
        data['virtualIps'] << vip
      end
    end
  end

  response = request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'POST',
    :path    => "loadbalancers"
  )
  response

end

#create_load_balancer_node(load_balancer_id, options = {}) ⇒ Object



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

def create_load_balancer_node(load_balancer_id, options={})
  data = {}

  if options['nodes']
    data['nodes'] = []
    for node in options['nodes']
      hsh = node.dup
      hsh.delete(:load_balancer_id)
      data['nodes'] << hsh
    end
  end

  response = request(
    :body    => Fog::JSON.encode(data),
    :expects => 200,
    :method  => 'POST',
    :path    => "loadbalancers/#{load_balancer_id}/nodes"
  )

end

#delete_load_balancer(instance_id) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/monkey/hp/requests/lb/delete_load_balancer.rb', line 27

def delete_load_balancer(instance_id)
  response = request(
      :expects => 202,
      :method  => 'DELETE',
      :path    => "loadbalancers/#{instance_id}"
  )
  response
end

#delete_load_balancer_node(instance_id, node_id) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/monkey/hp/requests/lb/delete_load_balancer_node.rb', line 27

def delete_load_balancer_node(instance_id, node_id)
  response = request(
    :expects => [204,202],
    :method  => 'DELETE',
    :path    => "loadbalancers/#{instance_id}/nodes/#{node_id}"
  )
  response
end

#get_load_balancer(load_balancer_id) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/get_load_balancer.rb', line 26

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

#get_load_balancer_node(load_balancer_id, node_id) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/monkey/hp/requests/lb/get_load_balancer_node.rb', line 26

def get_load_balancer_node(load_balancer_id, node_id)
  response = request(
    :expects => 200,
    :method  => 'GET',
    :path    => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}"
  )
  response

end

#get_version(version_id) ⇒ Object

Get details for existing database flavor instance

Parameters

  • flavor_id<~Integer> - Id of the flavor to get

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • TBD



37
38
39
40
41
42
43
44
45
# File 'lib/monkey/hp/requests/lb/get_version.rb', line 37

def get_version(version_id)
  response = request(
    :expects => 200,
    :method  => 'GET',
    :path    => "/#{version_id}/",
    :version => true
  )
  response
end

#get_virtual_ips(load_balancer_id) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/get_virtual_ips.rb', line 26

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

#list_algorithmsObject



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/list_algorithms.rb', line 26

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

#list_limitsObject



27
28
29
30
31
32
33
34
# File 'lib/monkey/hp/requests/lb/list_limits.rb', line 27

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

#list_load_balancer_nodes(load_balancer_id) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb', line 26

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



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb', line 26

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

#list_load_balancersObject



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/list_load_balancers.rb', line 26

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

#list_protocolsObject



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/list_protocols.rb', line 26

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

#list_versionsObject



27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/list_versions.rb', line 27

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

#reloadObject



157
158
159
# File 'lib/monkey/hp/lb.rb', line 157

def reload
  @connection.reset
end

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



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/monkey/hp/lb.rb', line 161

def request(params, parse_json = true, &block)
  begin
    response = @connection.request(params.merge!({
                                                     :headers => {
                                                         'Content-Type' => '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::BlockStorage::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



26
27
28
29
30
31
32
33
# File 'lib/monkey/hp/requests/lb/update_load_balancer.rb', line 26

def update_load_balancer(load_balancer_id, options=())
  request(
    :body    => Fog::JSON.encode(options),
    :expects => [202,200],
    :method  => 'PUT',
    :path    => "loadbalancers/#{load_balancer_id}"
  )
end

#update_load_balancer_node(load_balancer_id, node_id, condition) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/monkey/hp/requests/lb/update_load_balancer_node.rb', line 26

def update_load_balancer_node(load_balancer_id, node_id, condition)
  data = {
    #ENABLED | DISABLED
    "condition" => condition
  }
  request(
    :body    => Fog::JSON.encode(data),
    :expects => [202,204],
    :method  => 'PUT',
    :path    => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}"
  )

end