Module: Fog::Compute::Google::Shared

Included in:
Mock, Real
Defined in:
lib/fog/google/compute.rb,
lib/fog/google/requests/compute/delete_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



81
82
83
# File 'lib/fog/google/compute.rb', line 81

def api_version
  @api_version
end

#projectObject (readonly)

Returns the value of attribute project.



81
82
83
# File 'lib/fog/google/compute.rb', line 81

def project
  @project
end

Instance Method Details

#backoff_if_unfound(&block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fog/google/compute.rb', line 110

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) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fog/google/compute.rb', line 88

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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/delete_server.rb', line 6

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

#shared_initialize(options = {}) ⇒ Object



83
84
85
86
# File 'lib/fog/google/compute.rb', line 83

def shared_initialize(options = {})
  @project = options[:google_project]
  @api_version = 'v1'
end