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

Merge pull request #3069 from snyquist2/gce_l7

[google|compute] Add backend services resource for L7 load balancing
This commit is contained in:
Nat Welch 2014-07-25 09:46:41 +01:00
commit e62c5407e1
9 changed files with 260 additions and 0 deletions

View file

@ -30,6 +30,7 @@ module Fog
request :list_target_pools
request :list_forwarding_rules
request :list_routes
request :list_backend_services
request :get_server
request :get_address
@ -51,6 +52,8 @@ module Fog
request :get_forwarding_rule
request :get_project
request :get_route
request :get_backend_service
request :get_backend_service_health
request :delete_address
request :delete_disk
@ -66,6 +69,7 @@ module Fog
request :delete_target_pool
request :delete_forwarding_rule
request :delete_route
request :delete_backend_service
request :insert_address
request :insert_disk
@ -78,6 +82,7 @@ module Fog
request :insert_target_pool
request :insert_forwarding_rule
request :insert_route
request :insert_backend_service
request :set_metadata
request :set_tags
@ -151,6 +156,9 @@ module Fog
model :route
collection :routes
model :backend_service
collection :backend_services
module Shared
attr_reader :project, :api_version

View file

@ -0,0 +1,25 @@
require 'rubygems'
require 'fog'
def test
connection = Fog::Compute.new({ :provider => "google",
:google_project => "",
:google_client_email => "",
:google_key_location => ""
})
health = connection.http_health_checks.create({
:name => 'test-checks'
})
health.wait_for { health.ready? }
backend= connection.backend_services.create({
:name => 'backend-test',
:health_checks => [health.self_link],
:port => 8080,
:timeout_sec => 40,
:backends => [{'group' => 'resource_view self_link'}]
})
puts connection.backend_services.all
backend= connection.backend_services.get('backend-test')
backend.get_health
end
test

View file

@ -0,0 +1,80 @@
require 'fog/core/model'
module Fog
module Compute
class Google
class BackendService < Fog::Model
identity :name
attribute :backends, :aliases => 'backends'
attribute :creation_timestamp, :aliases => 'kind'
attribute :description, :aliases => 'description'
attribute :fingerprint, :aliases => 'fingerprint'
attribute :health_checks, :aliases => 'healthChecks'
attribute :id, :aliases => 'id'
attribute :kind, :aliases => 'kind'
attribute :port, :aliases => 'port'
attribute :protocol, :aliases => 'protocol'
attribute :self_link, :aliases => 'selfLink'
attribute :timeout_sec, :aliases => 'timeoutSec'
def save
requires :name, :health_checks
options = {
'description' => description,
'backends' => backends,
'fingerprint' => fingerprint,
'healthChecks' => health_checks,
'port' => port,
'protocol' => protocol,
'timeoutSec' => timeout_sec
}
data = service.insert_backend_service(name, options).body
operation = Fog::Compute::Google::Operations.new(:service => service).get(data['name'])
operation.wait_for { !pending? }
reload
end
def destroy(async=false)
requires :name
operation = service.delete_backend_service(name)
unless async
operation.wait_for { ready? }
end
operation
end
def get_health
service.get_backend_service_health self
end
def ready?
begin
service.get_backend_service(self.name)
true
rescue Fog::Errors::NotFound
false
end
end
def reload
requires :name
return unless data = begin
collection.get(name)
rescue Excon::Errors::SocketError
nil
end
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
RUNNING_STATE = "READY"
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'fog/core/collection'
require 'fog/google/models/compute/backend_service'
module Fog
module Compute
class Google
class BackendServices < Fog::Collection
model Fog::Compute::Google::BackendService
def all(filters={})
data = service.list_backend_service.body['items'] || []
load(data)
end
def get(identity)
response = service.get_backend_service(identity)
new(response.body) unless response.nil?
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class Google
class Mock
def delete_backend_service(backend_service_name)
Fog::Mock.not_implemented
end
end
class Real
def delete_backend_service(backend_service_name)
api_method = @compute.backend_services.delete
parameters = {
'project' => @project,
'backendService' => backend_service_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class Google
class Mock
def get_backend_service(service_name)
Fog::Mock::not_implemented
end
end
class Real
def get_backend_service(service_name)
api_method = @compute.backend_services.get
parameters = {
'project' => @project,
'backendService' => service_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
end
end
end
end

View file

@ -0,0 +1,27 @@
module Fog
module Compute
class Google
class Mock
def get_backend_service_health(backend_service)
Fog::Mock.not_implemented
end
end
class Real
def get_backend_service_health(backend_service)
api_method = @compute.backend_services.get_health
parameters = {
'project' => @project,
'backendService' => backend_service.name
}
health_results = backend_service.backends.map do |backend|
body = { 'group' => backend['group'] }
resp = build_response(build_result(api_method, parameters, body_object= body))
[backend['group'], resp.data[:body]['healthStatus']]
end
Hash[health_results]
end
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module Compute
class Google
class Mock
def insert_backend_service(backend_service_name)
Fog::Mock.not_implemented
end
end
class Real
def insert_backend_service(backend_service_name, opts = {})
api_method = @compute.backend_services.insert
parameters = {
'project' => @project
}
body_object = { 'name' => backend_service_name }
body_object.merge!(opts)
result = self.build_result(api_method, parameters, body_object=body_object)
response = self.build_response(result)
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class Google
class Mock
def list_backend_services
Fog::Mock.not_implemented
end
end
class Real
def list_backend_services
api_method = @compute.backend_services.list
parameters = {
'project' => @project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
end
end
end
end