module Fog::OpenStack

Constants

VERSION

Attributes

token_cache[RW]

Public Class Methods

[](service) click to toggle source

TODO: get rid of inconform self.[] & self.new & self.services

# File lib/fog/openstack/planning.rb, line 118
def self.[](service)
  new(:service => service)
end
clear_token_cache() click to toggle source
# File lib/fog/openstack.rb, line 64
def self.clear_token_cache
  Fog::OpenStack.token_cache = {}
end
endpoint_region?(endpoint, region) click to toggle source
# File lib/fog/openstack.rb, line 68
def self.endpoint_region?(endpoint, region)
  region.nil? || endpoint['region'] == region
end
escape(str, extra_exclude_chars = '') click to toggle source

CGI.escape, but without special treatment on spaces

# File lib/fog/openstack.rb, line 95
def self.escape(str, extra_exclude_chars = '')
  str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
    '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
  end
end
extract_version_from_body(body, supported_versions) click to toggle source
# 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
get_supported_microversion(supported_versions, uri, auth_token, connection_options = {}) click to toggle source
# File lib/fog/openstack.rb, line 89
def self.get_supported_microversion(supported_versions, uri, auth_token, connection_options = {})
  supported_version = get_version(supported_versions, uri, auth_token, connection_options)
  supported_version['version'] if supported_version
end
get_supported_version(supported_versions, uri, auth_token, connection_options = {}) click to toggle source
# File lib/fog/openstack.rb, line 72
def self.get_supported_version(supported_versions, uri, auth_token, connection_options = {})
  supported_version = get_version(supported_versions, uri, auth_token, connection_options)
  version = supported_version['id'] if supported_version
  version_raise(supported_versions) if version.nil?

  version
end
get_supported_version_path(supported_versions, uri, auth_token, connection_options = {}) click to toggle source
# File lib/fog/openstack.rb, line 80
def self.get_supported_version_path(supported_versions, uri, auth_token, connection_options = {})
  supported_version = get_version(supported_versions, uri, auth_token, connection_options)
  link = supported_version['links'].find { |l| l['rel'] == 'self' } if supported_version
  path = URI.parse(link['href']).path if link
  version_raise(supported_versions) if path.nil?

  path.chomp '/'
end
get_version(supported_versions, uri, auth_token, connection_options = {}) click to toggle source
# 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
new(attributes) click to toggle source
# File lib/fog/openstack/planning.rb, line 122
def self.new(attributes)
  attributes = attributes.dup # Prevent delete from having side effects
  service = attributes.delete(:service).to_s.downcase.to_sym
  if services.include?(service)
    return Fog::OpenStack.const_get(service.to_s.capitalize).new(attributes)
  end
  raise ArgumentError, "Openstack has no #{service} service"
end
services() click to toggle source
# File lib/fog/openstack/planning.rb, line 131
def self.services
  # Ruby 1.8.7 compatibility for select returning Array of Arrays (pairs)
  Hash[Fog.services.select { |_service, providers| providers.include?(:openstack) }].keys
end
version_raise(supported_versions) click to toggle source
# File lib/fog/openstack.rb, line 143
def self.version_raise(supported_versions)
  raise Fog::OpenStack::Errors::ServiceUnavailable,
        "OpenStack service only supports API versions #{supported_versions.inspect}"
end