1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

update LBaaS to what works with the current version in pro

This commit is contained in:
howete 2013-05-21 15:09:13 -06:00 committed by Rupak Ganguly
parent 68945be16e
commit 2eeb7055e0
17 changed files with 113 additions and 76 deletions

View file

@ -5,7 +5,7 @@ module Fog
class LB < Fog::Service
requires :hp_secret_key, :hp_tenant_id, :hp_avl_zone
recognizes :hp_auth_uri
recognizes :hp_auth_uri, :credentials
recognizes :persistent, :connection_options
recognizes :hp_use_upass_auth_style, :hp_auth_version, :user_agent
recognizes :hp_access_key, :hp_account_id # :hp_account_id is deprecated use hp_access_key instead
@ -84,6 +84,7 @@ module Fog
end
class Real
attr_reader :credentials
def initialize(options={})
@ -163,4 +164,4 @@ module Fog
end
end
end
end

View file

@ -4,11 +4,8 @@ module Fog
module HP
class LB
class Algorithm < Fog::Model
identity :name
end
end
end
end

View file

@ -8,12 +8,12 @@ module Fog
model Fog::HP::LB::Algorithm
def all
data = connection.list_algorithms.body['algorithms']
data = service.list_algorithms.body['algorithms']
load(data)
end
def get(record_id)
record = connection.get_algorithm_details(record_id).body['algorithm']
record = service.get_algorithm_details(record_id).body['algorithm']
new(record)
rescue Fog::HP::LB::NotFound
nil
@ -22,4 +22,4 @@ module Fog
end
end
end
end
end

View file

@ -20,13 +20,10 @@ module Fog
#}
#}
def all
data = connection.list_load_limits.body['limits']['absolute']['values']
load(data)
data = service.list_limits.body['limits']['absolute']['values']
load([data])
end
end
end
end
end
end

View file

@ -3,26 +3,47 @@ require 'fog/core/model'
module Fog
module HP
class LB
#"name" : "lb-site1",
# "id" : "71",
# "protocol" : "HTTP",
# "port" : "80",
# "algorithm" : "LEAST_CONNECTIONS",
# "status" : "ACTIVE",
# "created" : "2010-11-30T03:23:42Z",
# "updated" : "2010-11-30T03:23:44Z"
class LoadBalancer < Fog::Model
class LoadBalancer < Fog::Model
identity :id
attribute :name
attribute :protocol
attribute :port
attribute :algorithm
attribute :status
attribute :nodes
attribute :virtualIps
attribute :created_at, :aliases => 'created'
attribute :updated_at , :aliases => 'updated'
def destroy
requires :id
service.delete_load_balancer(id)
true
end
def ready?
self.status == 'ACTIVE'
end
def save
identity ? update : create
end
private
def create
merge_attributes(service.create_load_balancer(name, nodes, attributes).body)
true
end
def update
requires :id
merge_attributes(service.update_load_balancer(id, attributes).body)
true
end
end
end
end
end
end

View file

@ -8,12 +8,12 @@ module Fog
model Fog::HP::LB::LoadBalancer
def all
data = connection.list_load_balancers.body['load_balancers']
data = service.list_load_balancers.body['loadBalancers']
load(data)
end
def get(record_id)
record = connection.get_load_balancer_details(record_id).body['load_balancer']
record = service.get_load_balancer_details(record_id).body['load_balancer']
new(record)
rescue Fog::HP::LB::NotFound
nil
@ -22,4 +22,4 @@ module Fog
end
end
end
end
end

View file

@ -10,9 +10,39 @@ module Fog
attribute :port
attribute :condition
attribute :status
attribute :load_balancer_id
def destroy
requires :id
requires :load_balancer_id
service.delete_load_balancer_node(load_balancer_id, id)
true
end
def ready?
self.status == 'ACTIVE'
end
def save
identity ? update : create
end
private
def create
requires :load_balancer_id
merge_attributes(service.create_load_balancer_node(load_balancer_id, {'nodes' => [attributes]}).body)
true
end
def update
requires :id
requires :load_balancer_id
service.update_load_balancer_node(load_balancer_id, id, attributes[:condition])
true
end
end
end
end
end
end

View file

@ -8,12 +8,13 @@ module Fog
model Fog::HP::LB::Node
def all
data = connection.list_nodes.body['nodes']
data = service.list_load_balancer_nodes(@attributes[:load_balancer_id]).body['nodes']
load(data)
self.each{ |x| x.load_balancer_id = @attributes[:load_balancer_id] }
end
def get(record_id)
record = connection.get_node_details(record_id).body['node']
record = service.get_load_balancer_node(@attributes[:load_balancer_id], record_id).body['node']
new(record)
rescue Fog::HP::LB::NotFound
nil
@ -22,4 +23,4 @@ module Fog
end
end
end
end
end

View file

@ -9,4 +9,4 @@ module Fog
end
end
end
end
end

View file

@ -8,12 +8,12 @@ module Fog
model Fog::HP::LB::Protocol
def all
data = connection.list_protocols.body['protocols']
data = service.list_protocols.body['protocols']
load(data)
end
def get(record_id)
record = connection.get_protocol_details(record_id).body['protocol']
record = service.get_protocol_details(record_id).body['protocol']
new(record)
rescue Fog::HP::LB::NotFound
nil
@ -22,4 +22,4 @@ module Fog
end
end
end
end
end

View file

@ -8,12 +8,12 @@ module Fog
model Fog::HP::LB::Version
def all
data = connection.list_versions.body['versions']
data = service.list_versions.body['versions']
load(data)
end
def get(record_id)
record = connection.get_versions(record_id).body['version']
record = service.get_versions(record_id).body['version']
new(record)
rescue Fog::HP::LB::NotFound
nil
@ -22,4 +22,4 @@ module Fog
end
end
end
end
end

View file

@ -8,12 +8,12 @@ module Fog
model Fog::HP::LB::VirtualIp
def all
data = connection.list_virtual_ips.body['virtual_ips']
data = service.list_virtual_ips.body['virtual_ips']
load(data)
end
def get(record_id)
record = connection.get_virtual_ip_details(record_id).body['virtual_ip']
record = service.get_virtual_ip_details(record_id).body['virtual_ip']
new(record)
rescue Fog::HP::LB::NotFound
nil
@ -22,4 +22,4 @@ module Fog
end
end
end
end
end

View file

@ -3,34 +3,28 @@ module Fog
class LB
class Real
def create_load_balancer(name, nodes, options={})
#required
# name
#at least one node
data = {
"name" => name,
"nodes" => nodes
}
if options['port']
data['port'] = options['port']
end
if options['protocol']
data['protocol'] = options['protocol']
end
if options['virtualIps']
data['virtualIps'] = []
for vip in options['virtualIps']
data['virtualIps'] << vip
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 => 200,
:expects => 202,
:method => 'POST',
:path => "loadbalancers/#{load_balancer_id}"
:path => "loadbalancers"
)
response
@ -46,4 +40,4 @@ module Fog
end
end
end
end
end

View file

@ -2,25 +2,21 @@ module Fog
module HP
class LB
class Real
#example node...
#{
# "address" : "10.2.2.2",
# "port" : "88",
# "condition" : "DISABLED"
#}
def create_load_balancer_node(load_balancer_id, options={})
data = {}
if options['nodes']
data['nodes'] = []
for node in options['nodes']
data['nodes'] << node
hsh = node.dup
hsh.delete(:load_balancer_id)
data['nodes'] << hsh
end
end
response = request(
:body => Fog::JSON.encode(data),
:expects => 202,
:expects => 200,
:method => 'POST',
:path => "loadbalancers/#{load_balancer_id}/nodes"
)
@ -38,4 +34,4 @@ module Fog
end
end
end
end

View file

@ -5,7 +5,7 @@ module Fog
def delete_load_balancer_node(instance_id, node_id)
response = request(
:expects => 202,
:expects => [204,202],
:method => 'DELETE',
:path => "loadbalancers/#{instance_id}/nodes/#{node_id}"
)
@ -36,4 +36,4 @@ module Fog
end
end
end
end
end

View file

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

View file

@ -9,7 +9,7 @@ module Fog
}
request(
:body => Fog::JSON.encode(data),
:expects => 202,
:expects => [202,204],
:method => 'PUT',
:path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}"
)
@ -26,4 +26,4 @@ module Fog
end
end
end
end
end