Class: Fog::Compute::Google::BackendService
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Google::BackendService
- Defined in:
- lib/fog/compute/google/models/backend_service.rb
Constant Summary collapse
- RUNNING_STATE =
"READY".freeze
Instance Method Summary collapse
- #add_backend(backend) ⇒ Object
- #destroy(async = true) ⇒ Object
- #get_health ⇒ Object
- #ready? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
Instance Method Details
#add_backend(backend) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/fog/compute/google/models/backend_service.rb', line 51 def add_backend(backend) # ensure backend is an array of hashes backend = [backend] unless backend.class == Array backend.map! { |resource| resource.class == String ? { "group" => resource } : resource } service.add_backend_service_backends(self, backend) reload end |
#destroy(async = true) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/fog/compute/google/models/backend_service.rb', line 38 def destroy(async = true) requires :name data = service.delete_backend_service(name) operation = Fog::Compute::Google::Operations.new(:service => service).get(data.name) operation.wait_for { ready? } unless async operation end |
#get_health ⇒ Object
47 48 49 |
# File 'lib/fog/compute/google/models/backend_service.rb', line 47 def get_health service.get_backend_service_health(self) end |
#ready? ⇒ Boolean
59 60 61 62 63 64 65 |
# File 'lib/fog/compute/google/models/backend_service.rb', line 59 def ready? service.get_backend_service(name) true rescue ::Google::Apis::ClientError => e raise e unless e.status_code == 404 false end |
#reload ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fog/compute/google/models/backend_service.rb', line 67 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 |
#save ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/compute/google/models/backend_service.rb', line 19 def save requires :name, :health_checks = { :description => description, :backends => backends, :fingerprint => fingerprint, :health_checks => health_checks, :port => port, :protocol => protocol, :timeout_sec => timeout_sec } data = service.insert_backend_service(name, **) operation = Fog::Compute::Google::Operations.new(:service => service).get(data.name) operation.wait_for { ready? } reload end |