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

Added backend services example and model classes

This commit is contained in:
snyquist2 2014-07-23 16:38:59 +00:00
parent 1569a3b6e3
commit 8f4d58e8bb
3 changed files with 127 additions and 0 deletions

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