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".freeze
Instance Method Summary collapse
- #add_health_check(health_check, async = true) ⇒ Object
- #add_instance(instance, async = true) ⇒ Object
- #destroy(async = true) ⇒ Object
-
#get_health(instance_name = nil) ⇒ Object
Get most recent health checks for each IP for instances.
- #ready? ⇒ Boolean
- #region_name ⇒ Object
- #reload ⇒ Object
- #remove_health_check(health_check, async = true) ⇒ Object
- #remove_instance(instance, async = true) ⇒ Object
- #save ⇒ Object
- #set_backup(backup = nil) ⇒ Object
Instance Method Details
#add_health_check(health_check, async = true) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 68 def add_health_check(health_check, async = true) requires :identity, :region health_check = health_check.self_link unless health_check.class == String data = service.add_target_pool_health_checks(identity, region, [health_check]) operation = Fog::Compute::Google::Operations .new(:service => service) .get(data.name, nil, data.region) operation.wait_for { ready? } unless async reload end |
#add_instance(instance, async = true) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 42 def add_instance(instance, async = true) requires :identity instance = instance.self_link unless instance.class == String data = service.add_target_pool_instances(identity, region, [instance]) operation = Fog::Compute::Google::Operations .new(:service => service) .get(data.name, nil, data.region) operation.wait_for { ready? } unless async reload end |
#destroy(async = true) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 32 def destroy(async = true) requires :identity, :region data = service.delete_target_pool(identity, region) operation = Fog::Compute::Google::Operations .new(:service => service) .get(data.name, nil, data.region) operation.wait_for { ready? } unless async operation end |
#get_health(instance_name = nil) ⇒ Object
Get most recent health checks for each IP for instances.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 100 def get_health(instance_name = nil) requires :identity, :region if instance_name instance = service.servers.get(instance_name) data = service.get_target_pool_health(identity, region, instance.self_link) .to_h[:health_status] || [] results = [instance.self_link, data] else results = instances.map do |self_link| data = service.get_target_pool_health(identity, region, self_link) .to_h[:health_status] || [] [self_link, data] end end Hash[results] end |
#ready? ⇒ Boolean
130 131 132 133 134 135 136 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 130 def ready? service.get_target_pool(name, region) true rescue ::Google::Apis::ClientError => e raise e unless e.status_code == 404 false end |
#region_name ⇒ Object
138 139 140 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 138 def region_name region.nil? ? nil : region.split("/")[-1] end |
#reload ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 142 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, async = true) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 81 def remove_health_check(health_check, async = true) requires :identity, :region health_check = health_check.self_link unless health_check.class == String data = service.remove_target_pool_health_checks(identity, region, [health_check]) operation = Fog::Compute::Google::Operations .new(:service => service) .get(data.name, nil, data.region) operation.wait_for { ready? } unless async reload end |
#remove_instance(instance, async = true) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 54 def remove_instance(instance, async = true) requires :identity instance = instance.self_link unless instance.class == String data = service.remove_target_pool_instances(identity, region, [instance]) operation = Fog::Compute::Google::Operations .new(:service => service) .get(data.name, nil, data.region) operation.wait_for { ready? } unless async reload end |
#save ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 19 def save requires :name, :region data = service.insert_target_pool( name, region, attributes.reject { |_k, v| v.nil? } ) operation = Fog::Compute::Google::Operations .new(:service => service) .get(data.name, nil, data.region) operation.wait_for { !pending? } reload end |
#set_backup(backup = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fog/compute/google/models/target_pool.rb', line 118 def set_backup(backup = nil) requires :identity, :region backup ||= backup_pool service.set_target_pool_backup( identity, region, backup, :failover_ratio => failover_ratio ) reload end |