module Fog::Compute::Google::Shared
Attributes
api_version[R]
project[R]
Public Instance Methods
backoff_if_unfound(&block)
click to toggle source
# File lib/fog/google/compute.rb, line 181 def backoff_if_unfound(&block) retries_remaining = 10 sleep_time = 0.1 begin result = block.call rescue Exception => msg if msg.to_s.include? 'was not found' and retries_remaining > 0 retries_remaining -= 1 sleep sleep_time sleep_time *= 1.6 retry else raise msg end end result end
build_excon_response(body, status=200)
click to toggle source
# File lib/fog/google/compute.rb, line 159 def build_excon_response(body, status=200) response = Excon::Response.new response.body = body if response.body and response.body["error"] response.status = response.body["error"]["code"] if response.body["error"]["errors"] msg = response.body["error"]["errors"].map{|error| error["message"]}.join(", ") else msg = "Error [#{response.body["error"]["code"]}]: #{response.body["error"]["message"] || "GCE didn't return an error message"}" end case response.status when 404 raise Fog::Errors::NotFound.new(msg) else raise Fog::Errors::Error.new(msg) end else response.status = status end response end
find_zone(zone_name)
click to toggle source
# File lib/fog/google/requests/compute/delete_server.rb, line 5 def find_zone(zone_name) if zone_name.nil? list_zones.body['items'].each do |zone| if get_server(server_name, zone['name']).status == 200 return zone['name'] end end else if zone_name.is_a? Excon::Response return zone_name.body["name"] end end return zone_name end