Method: Fog::OpenStack.extract_version_from_body

Defined in:
lib/fog/openstack.rb

.extract_version_from_body(body, supported_versions) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fog/openstack.rb', line 123

def self.extract_version_from_body(body, supported_versions)
  versions = []
  unless body['versions'].nil? || body['versions'].empty?
    versions = body['versions'].kind_of?(Array) ? body['versions'] : body['versions']['values']
  end
  # Some version API would return single endpoint rather than endpoints list, try to get it via 'version'.
  unless body['version'].nil? or versions.length != 0
    versions = [body['version']]
  end
  version = nil

  # order is important, preferred status should be first
  %w(CURRENT stable SUPPORTED DEPRECATED).each do |status|
    version = versions.find { |x| x['id'].match(supported_versions) && (x['status'] == status) }
    break if version
  end

  version
end