Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
27 changes: 27 additions & 0 deletions
27
lib/fog/google/requests/compute/get_backend_service_health.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |