Class: Fog::Compute::Google::TargetPool
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Google::TargetPool
- Defined in:
- lib/fog/compute/google/models/target_pool.rb
Constant Summary collapse
- RUNNING_STATE =
"READY"
Instance Method Summary collapse
- #add_health_check(health_check) ⇒ Object
- #add_instance(instance) ⇒ Object
- #destroy(async = true) ⇒ Object
- #get_health(instance_name = nil) ⇒ Object
- #ready? ⇒ Boolean
- #region_name ⇒ Object
- #reload ⇒ Object
- #remove_health_check(health_check) ⇒ Object
- #remove_instance(instance) ⇒ Object
- #save ⇒ Object
Instance Method Details
#add_health_check(health_check) ⇒ Object
64 65 66 67 68 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 64 def add_health_check(health_check) health_check = health_check.self_link unless health_check.class == String service.add_target_pool_health_checks(self, [health_check]) reload end |
#add_instance(instance) ⇒ Object
52 53 54 55 56 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 52 def add_instance(instance) instance = instance.self_link unless instance.class == String service.add_target_pool_instances(self, [instance]) reload end |
#destroy(async = true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 38 def destroy(async = true) requires :name, :region operation = service.delete_target_pool(name, region) unless async # wait until "DONE" to ensure the operation doesn't fail, raises # exception on error Fog.wait_for do operation = service.get_region_operation(region, operation.body["name"]) operation.body["status"] == "DONE" end end operation end |
#get_health(instance_name = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 76 def get_health(instance_name = nil) if instance_name instance = service.servers.get(instance_name) health_results = [service.get_target_pool_health(self, instance.self_link)] else health_results = instances.map do |instance_selflink| service.get_target_pool_health(self, instance_selflink) end end Hash[health_results] end |
#ready? ⇒ Boolean
88 89 90 91 92 93 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 88 def ready? service.get_target_pool(name, region) true rescue Fog::Errors::NotFound false end |
#region_name ⇒ Object
95 96 97 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 95 def region_name region.nil? ? nil : region.split("/")[-1] end |
#reload ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 99 def reload requires :name, :region return unless data = begin collection.get(name, region) rescue Excon::Errors::SocketError nil end new_attributes = data.attributes merge_attributes(new_attributes) self end |
#remove_health_check(health_check) ⇒ Object
70 71 72 73 74 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 70 def remove_health_check(health_check) health_check = health_check.self_link unless health_check.class == String service.remove_target_pool_health_checks(self, [health_check]) reload end |
#remove_instance(instance) ⇒ Object
58 59 60 61 62 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 58 def remove_instance(instance) instance = instance.self_link unless instance.class == String service.remove_target_pool_instances(self, [instance]) reload 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/target_pool.rb', line 19 def save requires :name, :region = { "description" => description, "region" => region, "healthChecks" => health_checks, "instances" => instances, "sessionAffinity" => session_affinity, "failoverRatio" => failover_ratio, "backupPool" => backup_pool } data = service.insert_target_pool(name, region, ).body operation = Fog::Compute::Google::Operations.new(:service => service).get(data["name"], nil, data["region"]) operation.wait_for { !pending? } reload end |