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.



75
76
77
# File 'lib/fog/google/compute.rb', line 75

def api_version
  @api_version
end

#projectObject (readonly)

Returns the value of attribute project.



75
76
77
# File 'lib/fog/google/compute.rb', line 75

def project
  @project
end

Instance Method Details

#backoff_if_unfound(&block) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fog/google/compute.rb', line 100

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fog/google/compute.rb', line 82

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"]
    msg = response.body["error"]["errors"].map{|error| error["message"]}.join(", ")
    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



77
78
79
80
# File 'lib/fog/google/compute.rb', line 77

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