Method: Fog::OpenStack.get_version

Defined in:
lib/fog/openstack.rb

.get_version(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fog/openstack.rb', line 101

def self.get_version(supported_versions, uri, auth_token, connection_options = {})
  version_cache = "#{uri}#{supported_versions}"
  return @version[version_cache] if @version && @version[version_cache]

  # To allow version discovery we need a "version less" endpoint
  path = uri.path.gsub(/\/v([1-9]+\d*)(\.[1-9]+\d*)*.*$/, '/')
  url = "#{uri.scheme}://#{uri.host}:#{uri.port}#{path}"
  connection = Fog::Core::Connection.new(url, false, connection_options)
  response = connection.request(
    :expects => [200, 204, 300],
    :headers => {'Content-Type' => 'application/json',
                 'Accept'       => 'application/json',
                 'X-Auth-Token' => auth_token},
    :method  => 'GET'
  )

  body = Fog::JSON.decode(response.body)

  @version                = {} unless @version
  @version[version_cache] = extract_version_from_body(body, supported_versions)
end