Skip to content

Commit

Permalink
Refactors bootstraping
Browse files Browse the repository at this point in the history
  • Loading branch information
gildub committed Aug 21, 2018
1 parent 833a843 commit cfca6a7
Show file tree
Hide file tree
Showing 58 changed files with 587 additions and 1,261 deletions.
28 changes: 4 additions & 24 deletions lib/fog/baremetal/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,35 +248,15 @@ def credentials
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(baremetal).collect(&:freeze).freeze

# NOTE: uncommenting this should be treated as api-change!
# def self.not_found_class
# Fog::Baremetal::OpenStack::NotFound
# end

def initialize(options = {})
initialize_identity options

@openstack_service_type = options[:openstack_service_type] || ['baremetal']
@openstack_service_name = options[:openstack_service_name]

@connection_options = options[:connection_options] || {}

authenticate
set_api_path

@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

private

def set_api_path
unless @path.match(SUPPORTED_VERSIONS)
@path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS,
@openstack_management_uri,
@auth_token,
@connection_options)
end
def default_path_prefix
'v1'
end
end
end
Expand Down
26 changes: 7 additions & 19 deletions lib/fog/compute/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,33 +379,21 @@ def reset_data
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(compute).collect(&:freeze).freeze

def self.not_found_class
Fog::Compute::OpenStack::NotFound
end

def default_path_prefix
'v2.1'
end

def initialize(options = {})
@supported_versions = SUPPORTED_VERSIONS
@supported_microversion = SUPPORTED_MICROVERSION
@microversion_key = 'X-OpenStack-Nova-API-Version'

initialize_identity options

@openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity'

@openstack_service_type = options[:openstack_service_type] || %w(nova compute)
@openstack_service_name = options[:openstack_service_name]

@connection_options = options[:connection_options] || {}

authenticate

unless @path =~ %r{/(v2|v2\.0|v2\.1)}
raise Fog::OpenStack::Errors::ServiceUnavailable,
"OpenStack compute binding only supports version v2 and v2.1"
end

@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
super
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/fog/compute/openstack/requests/list_tenants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Compute
class OpenStack
class Real
def list_tenants
# TODO: replace with standard request (this is the only place using @identity_connection)
response = @identity_connection.request(:expects => [200, 204],
:headers => {'Content-Type' => 'application/json',
'Accept' => 'application/json',
Expand Down
29 changes: 4 additions & 25 deletions lib/fog/container_infra/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,41 +122,20 @@ def credentials
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(container-infra).collect(&:freeze).freeze

def self.not_found_class
Fog::ContainerInfra::OpenStack::NotFound
end

def initialize(options = {})
initialize_identity options

@openstack_service_type = options[:openstack_service_type] || ['container-infra']
@openstack_service_name = options[:openstack_service_name]
@openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'

@connection_options = options[:connection_options] || {}

authenticate
set_api_path

@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
def default_path_prefix
'v1'
end

def request(options = {})
options[:headers] = {'OpenStack-API-Version' => "container-infra #{SUPPORTED_MICROVERSION}"}
super(options)
end

def set_api_path
unless @path.match(SUPPORTED_VERSIONS)
@path = Fog::OpenStack.get_supported_version_path(
SUPPORTED_VERSIONS,
@openstack_management_uri,
@auth_token,
@connection_options
)
end
end
end
end
end
Expand Down
22 changes: 4 additions & 18 deletions lib/fog/dns/openstack/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,14 @@ def credentials
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(dns).collect(&:freeze).freeze

def self.not_found_class
Fog::DNS::OpenStack::NotFound
end

def initialize(options = {})
initialize_identity options

@openstack_service_type = options[:openstack_service_type] || ['dns']
@openstack_service_name = options[:openstack_service_name]

@connection_options = options[:connection_options] || {}

authenticate
set_api_path
@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

def set_api_path
# version explicitly set to allow usage also in 'DEPRECATED' mitaka version,
# where f.i. quota modification was not possible at the time of creation
@path = '/v1' unless @path =~ /v1/
def default_path_prefix
'v1'
end
end
end
Expand Down
27 changes: 4 additions & 23 deletions lib/fog/dns/openstack/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,14 @@ def credentials
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(dns).collect(&:freeze).freeze

def self.not_found_class
Fog::DNS::OpenStack::NotFound
end

def initialize(options = {})
initialize_identity options

@openstack_service_type = options[:openstack_service_type] || ['dns']
@openstack_service_name = options[:openstack_service_name]

@connection_options = options[:connection_options] || {}

authenticate
set_api_path
@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}/", @persistent, @connection_options)
end

def set_api_path
unless @path.match(SUPPORTED_VERSIONS)
@path = Fog::OpenStack.get_supported_version_path(
SUPPORTED_VERSIONS,
@openstack_management_uri,
@auth_token,
@connection_options
)
end
def default_path_prefix
'v2'
end
end
end
Expand Down
29 changes: 4 additions & 25 deletions lib/fog/event/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,14 @@ def credentials
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(event).collect(&:freeze).freeze

def self.not_found_class
Fog::Event::OpenStack::NotFound
end

def initialize(options = {})
initialize_identity options

@openstack_service_type = options[:openstack_service_type] || ['event']
@openstack_service_name = options[:openstack_service_name]
@openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'

@connection_options = options[:connection_options] || {}

authenticate
set_api_path

@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

def set_api_path
unless @path.match(SUPPORTED_VERSIONS)
@path = "/" + Fog::OpenStack.get_supported_version(
SUPPORTED_VERSIONS,
@openstack_management_uri,
@auth_token,
@connection_options
)
end
def default_path_prefix
'v2'
end
end
end
Expand Down
47 changes: 3 additions & 44 deletions lib/fog/identity/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,10 @@ def initialize(options = {})
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE_V3 = %w(identity_v3 identityv3 identity).collect(&:freeze).freeze
DEFAULT_SERVICE_TYPE = %w(identity).collect(&:freeze).freeze

def self.not_found_class
Fog::Identity::OpenStack::NotFound
end

def initialize(options = {})
if options.respond_to?(:config_service?) && options.config_service?
configure(options)
return
end

initialize_identity(options)

@openstack_service_type = options[:openstack_service_type] || default_service_type(options)
@openstack_service_name = options[:openstack_service_name]

@connection_options = options[:connection_options] || {}

@openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
initialize_endpoint_path_matches(options)

authenticate

if options[:openstack_identity_prefix]
@path = "/#{options[:openstack_identity_prefix]}/#{@path}"
end

@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

def config_service?
true
end
Expand All @@ -89,23 +60,11 @@ def config
self
end

private

def default_service_type(options)
unless options[:openstack_identity_prefix]
if @openstack_auth_uri.path =~ %r{/v3} ||
(options[:openstack_endpoint_path_matches] && options[:openstack_endpoint_path_matches] =~ '/v3')
return DEFAULT_SERVICE_TYPE_V3
end
end
DEFAULT_SERVICE_TYPE
def default_endpoint_type
'admin'
end

def initialize_endpoint_path_matches(options)
if options[:openstack_endpoint_path_matches]
@openstack_endpoint_path_matches = options[:openstack_endpoint_path_matches]
end
end
private

def configure(source)
source.instance_variables.each do |v|
Expand Down
6 changes: 3 additions & 3 deletions lib/fog/identity/openstack/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def credentials
end

class Real < Fog::Identity::OpenStack::Real
private
DEFAULT_SERVICE_TYPE = %w(identity_v2 identityv2 identity).collect(&:freeze).freeze

def default_service_type(_)
DEFAULT_SERVICE_TYPE
def default_path_prefix
'v2.0'
end
end
end
Expand Down
14 changes: 3 additions & 11 deletions lib/fog/identity/openstack/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,10 @@ def self.get_api_version(uri, connection_options = {})
end

class Real < Fog::Identity::OpenStack::Real
private
DEFAULT_SERVICE_TYPE = %w(identity_v3 identityv3 identity).collect(&:freeze).freeze

def default_service_type(_)
DEFAULT_SERVICE_TYPE_V3
end

def initialize_endpoint_path_matches(options)
if options[:openstack_endpoint_path_matches]
@openstack_endpoint_path_matches = options[:openstack_endpoint_path_matches]
else
@openstack_endpoint_path_matches = %r{/v3} unless options[:openstack_identity_prefix]
end
def default_path_prefix
'v3'
end
end
end
Expand Down
27 changes: 6 additions & 21 deletions lib/fog/image/openstack/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,18 @@ def credentials
class Real
include Fog::OpenStack::Core

DEFAULT_SERVICE_TYPE = %w(image).collect(&:freeze).freeze

def self.not_found_class
Fog::Image::OpenStack::NotFound
end

def initialize(options = {})
initialize_identity options

@openstack_service_type = options[:openstack_service_type] || ['image']
@openstack_service_name = options[:openstack_service_name]
@openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'

@connection_options = options[:connection_options] || {}

authenticate
set_api_path

@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
def default_endpoint_type
'admin'
end

def set_api_path
unless @path.match(SUPPORTED_VERSIONS)
@path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
@openstack_management_uri,
@auth_token,
@connection_options)
end
def default_path_prefix
'v1'
end
end
end
Expand Down

0 comments on commit cfca6a7

Please sign in to comment.