2013-03-01 18:46:56 -05:00
|
|
|
module Fog
|
|
|
|
module HP
|
2013-03-05 11:25:30 -05:00
|
|
|
class LB
|
2013-10-09 18:49:44 -04:00
|
|
|
|
|
|
|
# Create a new load balancer
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * 'name'<~String> - Name of the load balancer
|
|
|
|
# * 'nodes'<~ArrayOfHash> - Nodes for the load balancer
|
|
|
|
# * 'address'<~String> - Address for the node
|
|
|
|
# * 'port'<~String> - Port for the node
|
|
|
|
# * options<~Hash>:
|
|
|
|
# * 'port'<~String> - Port for the load balancer, defaults to '80'
|
|
|
|
# * 'protocol'<~String> - Protocol for the load balancer, defaults to 'HTTP'
|
|
|
|
# * 'algorithm'<~String> - Algorithm for the load balancer, defaults to 'ROUND_ROBIN'
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'id'<~String> - UUID of the load balancer
|
|
|
|
# * 'name'<~String> - Name of the load balancer
|
|
|
|
# * 'protocol'<~String> - Protocol for the load balancer
|
|
|
|
# * 'port'<~String> - Port for the load balancer
|
|
|
|
# * 'algorithm'<~String> - Algorithm for the load balancer
|
|
|
|
# * 'status'<~String> - Status for the load balancer
|
|
|
|
# * 'created'<~String> - created date time stamp
|
|
|
|
# * 'updated'<~String> - updated date time stamp
|
|
|
|
# * 'nodes'<~ArrayOfHash> - Nodes for the load balancer
|
|
|
|
# * 'address'<~String> - Address for the node
|
|
|
|
# * 'port'<~String> - Port for the node
|
2013-03-05 11:25:30 -05:00
|
|
|
class Real
|
|
|
|
def create_load_balancer(name, nodes, options={})
|
2013-10-09 18:49:44 -04:00
|
|
|
### Inconsistent behavior. Should be passing in as a 'loadbalancer' => {'name', 'nodes'}
|
2013-03-05 11:25:30 -05:00
|
|
|
data = {
|
2013-10-09 18:49:44 -04:00
|
|
|
'name' => name,
|
|
|
|
'nodes' => nodes
|
2013-03-05 11:25:30 -05:00
|
|
|
}
|
2013-10-09 18:49:44 -04:00
|
|
|
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
|
2013-03-05 11:25:30 -05:00
|
|
|
end
|
|
|
|
end
|
2013-03-04 15:33:54 -05:00
|
|
|
|
2013-03-05 11:25:30 -05:00
|
|
|
response = request(
|
|
|
|
:body => Fog::JSON.encode(data),
|
2013-05-21 17:09:13 -04:00
|
|
|
:expects => 202,
|
2013-03-05 11:25:30 -05:00
|
|
|
:method => 'POST',
|
2013-10-09 18:49:44 -04:00
|
|
|
:path => 'loadbalancers'
|
2013-03-05 11:25:30 -05:00
|
|
|
)
|
|
|
|
response
|
2013-03-01 18:46:56 -05:00
|
|
|
end
|
2013-03-05 11:25:30 -05:00
|
|
|
end
|
2013-10-09 18:49:44 -04:00
|
|
|
|
2013-03-05 11:25:30 -05:00
|
|
|
class Mock
|
|
|
|
def create_load_balancer(name, nodes, options={})
|
2013-10-09 18:49:44 -04:00
|
|
|
### Call: {"name" => "my-shiny-lb1", "nodes" => [{"address" => "15.185.1.1", "port" => "80"}]}
|
2013-03-05 11:25:30 -05:00
|
|
|
response = Excon::Response.new
|
2013-10-09 18:49:44 -04:00
|
|
|
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']
|
|
|
|
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
|
2013-03-04 15:33:54 -05:00
|
|
|
|
2013-10-09 18:49:44 -04:00
|
|
|
self.data[:lbs][data['id']] = data
|
|
|
|
response.body = data
|
2013-03-05 11:25:30 -05:00
|
|
|
response
|
2013-03-01 18:46:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-21 17:09:13 -04:00
|
|
|
end
|