Module: Fog::OpenStack
- Extended by:
- Provider
- Defined in:
- lib/fog/openstack.rb,
lib/fog/openstack/core.rb,
lib/fog/openstack/errors.rb,
lib/fog/openstack/version.rb,
lib/fog/planning/openstack.rb,
lib/fog/openstack/auth/name.rb,
lib/fog/openstack/auth/token.rb,
lib/fog/openstack/auth/catalog.rb,
lib/fog/openstack/models/model.rb,
lib/fog/openstack/auth/token/v2.rb,
lib/fog/openstack/auth/token/v3.rb,
lib/fog/openstack/auth/catalog/v2.rb,
lib/fog/openstack/auth/catalog/v3.rb,
lib/fog/openstack/models/collection.rb,
lib/fog/planning/openstack/models/plan.rb,
lib/fog/planning/openstack/models/role.rb,
lib/fog/planning/openstack/models/plans.rb,
lib/fog/planning/openstack/models/roles.rb,
lib/fog/planning/openstack/requests/get_plan.rb,
lib/fog/planning/openstack/requests/list_plans.rb,
lib/fog/planning/openstack/requests/list_roles.rb,
lib/fog/planning/openstack/requests/patch_plan.rb,
lib/fog/planning/openstack/requests/create_plan.rb,
lib/fog/planning/openstack/requests/delete_plan.rb,
lib/fog/planning/openstack/requests/add_role_to_plan.rb,
lib/fog/planning/openstack/requests/get_plan_templates.rb,
lib/fog/planning/openstack/requests/remove_role_from_plan.rb
Defined Under Namespace
Modules: Auth, Core, Errors Classes: Collection, Model, Planning
Constant Summary collapse
- VERSION =
'0.2.2'.freeze
Class Attribute Summary collapse
-
.token_cache ⇒ Object
Returns the value of attribute token_cache.
Class Method Summary collapse
-
.[](service) ⇒ Object
TODO: get rid of inconform self.[] & self.new & self.services.
- .clear_token_cache ⇒ Object
- .endpoint_region?(endpoint, region) ⇒ Boolean
-
.escape(str, extra_exclude_chars = '') ⇒ Object
CGI.escape, but without special treatment on spaces.
- .extract_version_from_body(body, supported_versions) ⇒ Object
- .get_supported_microversion(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object
- .get_supported_version(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object
- .get_supported_version_path(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object
- .get_version(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object
- .new(attributes) ⇒ Object
- .services ⇒ Object
- .version_raise(supported_versions) ⇒ Object
Class Attribute Details
.token_cache ⇒ Object
Returns the value of attribute token_cache.
121 122 123 |
# File 'lib/fog/openstack.rb', line 121 def token_cache @token_cache end |
Class Method Details
.[](service) ⇒ Object
TODO: get rid of inconform self.[] & self.new & self.services
120 121 122 |
# File 'lib/fog/planning/openstack.rb', line 120 def self.[](service) new(:service => service) end |
.clear_token_cache ⇒ Object
124 125 126 |
# File 'lib/fog/openstack.rb', line 124 def self.clear_token_cache Fog::OpenStack.token_cache = {} end |
.endpoint_region?(endpoint, region) ⇒ Boolean
128 129 130 |
# File 'lib/fog/openstack.rb', line 128 def self.endpoint_region?(endpoint, region) region.nil? || endpoint['region'] == region end |
.escape(str, extra_exclude_chars = '') ⇒ Object
CGI.escape, but without special treatment on spaces
155 156 157 158 159 |
# File 'lib/fog/openstack.rb', line 155 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) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/fog/openstack.rb', line 183 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 = {}) ⇒ Object
149 150 151 152 |
# File 'lib/fog/openstack.rb', line 149 def self.get_supported_microversion(supported_versions, uri, auth_token, = {}) supported_version = get_version(supported_versions, uri, auth_token, ) supported_version['version'] if supported_version end |
.get_supported_version(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/fog/openstack.rb', line 132 def self.get_supported_version(supported_versions, uri, auth_token, = {}) supported_version = get_version(supported_versions, uri, auth_token, ) 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 = {}) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/fog/openstack.rb', line 140 def self.get_supported_version_path(supported_versions, uri, auth_token, = {}) supported_version = get_version(supported_versions, uri, auth_token, ) 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 = {}) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/fog/openstack.rb', line 161 def self.get_version(supported_versions, uri, auth_token, = {}) 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, ) 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) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/fog/planning/openstack.rb', line 124 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) require "fog/#{service}/openstack" return Fog::OpenStack.const_get(service.to_s.capitalize).new(attributes) end raise ArgumentError, "Openstack has no #{service} service" end |
.services ⇒ Object
134 135 136 137 |
# File 'lib/fog/planning/openstack.rb', line 134 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) ⇒ Object
203 204 205 206 |
# File 'lib/fog/openstack.rb', line 203 def self.version_raise(supported_versions) raise Fog::OpenStack::Errors::ServiceUnavailable, "OpenStack service only supports API versions #{supported_versions.inspect}" end |