module Aviator
- Author
-
Mark Maglana (mmaglana@gmail.com)
- Copyright
-
Copyright © 2014 Mark Maglana
- License
-
Distributed under the MIT license
- Homepage
Constants
- VERSION
Public Instance Methods
base_url()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 37 def base_url if session_data[:base_url] session_data[:base_url] elsif keystone_v2_style_session_data? && keystone_v2_style_service_info? extract_base_url_from_keystone_v2_session_data elsif keystone_v3_style_session_data? && keystone_v3_style_service_info? extract_base_url_from_keystone_v3_session_data elsif session_data[:auth_service] && session_data[:auth_service][:host_uri] && session_data[:auth_service][:api_version] version = session_data[:auth_service][:api_version].to_s == "v2" ? "v2.0" : session_data[:auth_service][:api_version] "#{ session_data[:auth_service][:host_uri] }/#{ version }" elsif session_data[:auth_service] && session_data[:auth_service][:host_uri] session_data[:auth_service][:host_uri] else raise Aviator::Service::MissingServiceEndpointError.new(service.to_s, self.class) end end
body()
click to toggle source
# File lib/aviator/openstack/compute/requests/v2/admin/confirm_server_resize.rb, line 13 def body { :confirmResize => nil } end
build_service_type_string()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 60 def build_service_type_string api_versions_without_a_suffix = [ [:compute, :v2], [:ec2, :v1], [:identity, :v2], [:image, :v1], [:metering, :v1], [:s3, :v1], [:volume, :v1] ] if api_versions_without_a_suffix.include? [service, api_version] service.to_s else "#{ service }#{ api_version }" end end
compact_hash(hash, opts = {})
click to toggle source
Removes nil elements from hash Adapted from stackoverflow.com/a/14773555/402145
# File lib/aviator/openstack/identity/requests/v3/public/create_token.rb, line 45 def compact_hash(hash, opts = {}) opts[:recurse] ||= true hash.inject({}) do |new_hash, (k,v)| if !v.nil? new_hash[k] = opts[:recurse] && v.kind_of?(Hash) ? compact_hash(v, opts) : v end new_hash end end
define_request(request_name, options={ :inherit => [:request] }, &block)
click to toggle source
# File lib/aviator/core/request_builder.rb, line 96 def define_request(request_name, options={ :inherit => [:request] }, &block) RequestBuilder.define_request self, request_name, options, &block end
domain_hash()
click to toggle source
# File lib/aviator/openstack/identity/requests/v3/public/create_token.rb, line 56 def domain_hash compact_hash({ :id => params[:domain_id], :name => params[:domain_name] }) end
extract_base_url_from_keystone_v2_session_data()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 79 def extract_base_url_from_keystone_v2_session_data service_info = session_data[:body][:access][:serviceCatalog].find{ |s| s[:type] == build_service_type_string } service_info[:endpoints][0]["#{ endpoint_type }URL".to_sym] end
extract_base_url_from_keystone_v3_session_data()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 85 def extract_base_url_from_keystone_v3_session_data service_info = session_data[:body][:token][:catalog].select{ |s| s[:type] == build_service_type_string } endpoints = service_info.find{ |s| s.keys.include? "endpoints" }['endpoints'] endpoints.find{ |s| s['interface'] == endpoint_type.to_s }['url'] end
headers()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 10 def headers {}.tap do |h| if self.anonymous? # do nothing elsif session_data.has_key? :service_token # service_token is the token that one would bootstrap OpenStack # with during the installation process. This token can be used # directly and does not require authentication beforehand. h['X-Auth-Token'] = session_data[:service_token] elsif keystone_v2_style_session_data? h['X-Auth-Token'] = session_data[:body][:access][:token][:id] elsif keystone_v3_style_session_data? h['X-Auth-Token'] = session_data[:headers]['x-subject-token'] else raise "Unknown session data format!" end end end
http_method()
click to toggle source
# File lib/aviator/openstack/compute/requests/v2/admin/confirm_server_resize.rb, line 25 def http_method :post end
keystone_v2_style_service_info?()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 93 def keystone_v2_style_service_info? not session_data[:body][:access][:serviceCatalog].find{ |s| s[:type] == build_service_type_string }.nil? end
keystone_v2_style_session_data?()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 98 def keystone_v2_style_session_data? session_data.has_key?(:body) && session_data[:body].has_key?(:access) end
keystone_v3_style_service_info?()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 103 def keystone_v3_style_service_info? not session_data[:body][:token][:catalog].find{ |s| s[:type] == build_service_type_string }.nil? end
keystone_v3_style_session_data?()
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 108 def keystone_v3_style_session_data? session_data.has_key?(:headers) && session_data[:headers].has_key?("x-subject-token") end
params_to_querystring(param_names)
click to toggle source
# File lib/aviator/openstack/common/requests/v0/public/base.rb, line 113 def params_to_querystring(param_names) filters = [] param_names.each do |param_name| filters << "#{ param_name }=#{ params[param_name] }" if params[param_name] end filters.empty? ? "" : "?#{ filters.join('&') }" end
password_auth_body()
click to toggle source
# File lib/aviator/openstack/identity/requests/v3/public/create_token.rb, line 64 def password_auth_body p = { :auth => { :identity => { :methods => ['password'], :password => { :user => compact_hash({ :id => params[:user_id], :name => params[:username], :password => params[:password] }) } } } } if params[:domain_name] || params[:domain_id] p[:auth][:identity][:password][:user][:domain] = domain_hash end if params[:tenant_name] || params[:tenant_id] || params[:domain_name] || params[:domain_id] p[:auth][:scope] = scope_hash end p end
scope_hash()
click to toggle source
# File lib/aviator/openstack/identity/requests/v3/public/create_token.rb, line 91 def scope_hash p = {} if params[:tenant_name] || params[:tenant_id] p[:project] = compact_hash({ :id => params[:tenant_id], :name => params[:tenant_name] }) p[:project][:domain] = domain_hash if params[:domain_name] || params[:domain_id] elsif params[:domain_name] || params[:domain_id] p[:domain] = domain_hash end p end
token_auth_body()
click to toggle source
# File lib/aviator/openstack/identity/requests/v3/public/create_token.rb, line 109 def token_auth_body p = { :auth => { :identity => { :methods => ['token'], :token => { :id => params[:token_id] } } } } p[:auth][:scope] = scope_hash if params[:tenant_name] || params[:tenant_id] p end
url()
click to toggle source
# File lib/aviator/openstack/compute/requests/v2/admin/confirm_server_resize.rb, line 30 def url "#{ base_url }/servers/#{ params[:id] }/action" end