fog-openstack 0.1.31 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +4 -1
  4. data/.travis.yml +5 -5
  5. data/.zuul.yaml +8 -8
  6. data/Rakefile +14 -4
  7. data/fog-openstack.gemspec +3 -2
  8. data/lib/fog/baremetal/openstack.rb +6 -24
  9. data/lib/fog/compute/openstack.rb +6 -27
  10. data/lib/fog/compute/openstack/requests/create_security_group.rb +1 -1
  11. data/lib/fog/compute/openstack/requests/create_server.rb +1 -1
  12. data/lib/fog/compute/openstack/requests/evacuate_server.rb +1 -5
  13. data/lib/fog/container_infra/openstack.rb +6 -25
  14. data/lib/fog/dns/openstack/v1.rb +5 -17
  15. data/lib/fog/dns/openstack/v2.rb +5 -22
  16. data/lib/fog/event/openstack.rb +5 -24
  17. data/lib/fog/identity/openstack.rb +24 -71
  18. data/lib/fog/identity/openstack/v2.rb +6 -4
  19. data/lib/fog/identity/openstack/v3.rb +5 -11
  20. data/lib/fog/image/openstack/v1.rb +8 -21
  21. data/lib/fog/image/openstack/v2.rb +8 -21
  22. data/lib/fog/image/openstack/v2/models/image.rb +1 -1
  23. data/lib/fog/introspection/openstack.rb +4 -19
  24. data/lib/fog/key_manager/openstack.rb +5 -47
  25. data/lib/fog/metering/openstack.rb +8 -23
  26. data/lib/fog/metric/openstack.rb +7 -26
  27. data/lib/fog/monitoring/openstack.rb +3 -12
  28. data/lib/fog/network/openstack.rb +5 -26
  29. data/lib/fog/network/openstack/requests/set_tenant.rb +0 -1
  30. data/lib/fog/nfv/openstack.rb +4 -24
  31. data/lib/fog/openstack.rb +17 -431
  32. data/lib/fog/openstack/auth/catalog.rb +64 -0
  33. data/lib/fog/openstack/auth/catalog/v2.rb +23 -0
  34. data/lib/fog/openstack/auth/catalog/v3.rb +23 -0
  35. data/lib/fog/openstack/auth/name.rb +65 -0
  36. data/lib/fog/openstack/auth/token.rb +69 -0
  37. data/lib/fog/openstack/auth/token/v2.rb +70 -0
  38. data/lib/fog/openstack/auth/token/v3.rb +116 -0
  39. data/lib/fog/openstack/core.rb +100 -76
  40. data/lib/fog/openstack/version.rb +1 -1
  41. data/lib/fog/orchestration/openstack.rb +4 -21
  42. data/lib/fog/planning/openstack.rb +13 -23
  43. data/lib/fog/shared_file_system/openstack.rb +10 -27
  44. data/lib/fog/storage/openstack.rb +6 -11
  45. data/lib/fog/volume/openstack.rb +1 -1
  46. data/lib/fog/volume/openstack/models/backup.rb +2 -2
  47. data/lib/fog/volume/openstack/requests/restore_backup.rb +2 -2
  48. data/lib/fog/volume/openstack/requests/update_volume.rb +12 -1
  49. data/lib/fog/volume/openstack/v1.rb +4 -21
  50. data/lib/fog/volume/openstack/v1/models/volume.rb +1 -2
  51. data/lib/fog/volume/openstack/v1/requests/update_volume.rb +0 -17
  52. data/lib/fog/volume/openstack/v2.rb +4 -21
  53. data/lib/fog/volume/openstack/v2/models/volume.rb +1 -1
  54. data/lib/fog/volume/openstack/v2/requests/update_volume.rb +0 -18
  55. data/lib/fog/workflow/openstack/v2.rb +5 -22
  56. data/playbooks/fog-openstack-unittest-spec/run.yaml +2 -1
  57. data/playbooks/fog-openstack-unittest-test/run.yaml +2 -1
  58. data/unit/auth/catalog_test.rb +252 -0
  59. data/unit/auth/name_test.rb +115 -0
  60. data/unit/auth/token_test.rb +478 -0
  61. data/unit/auth_helper.rb +102 -0
  62. data/unit/test_helper.rb +6 -0
  63. metadata +41 -16
  64. data/lib/fog/compute/openstack/requests/list_tenants.rb +0 -43
@@ -1,38 +1,32 @@
1
-
2
-
3
1
  module Fog
4
2
  module Identity
5
3
  class OpenStack < Fog::Service
6
4
  autoload :V2, 'fog/identity/openstack/v2'
7
5
  autoload :V3, 'fog/identity/openstack/v3'
8
6
 
9
- requires :openstack_auth_url
10
- recognizes :openstack_auth_token, :openstack_management_url, :persistent,
11
- :openstack_service_type, :openstack_service_name, :openstack_tenant,
12
- :openstack_endpoint_type, :openstack_region, :openstack_domain_id,
13
- :openstack_project_name, :openstack_domain_name,
14
- :openstack_user_domain, :openstack_project_domain,
15
- :openstack_user_domain_id, :openstack_project_domain_id,
16
- :openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username,
17
- :current_user, :current_user_id, :current_tenant, :openstack_cache_ttl,
18
- :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches
19
-
20
- # Fog::Identity::OpenStack.new() will return a Fog::Identity::OpenStack::V3 by default
21
7
  def self.new(args = {})
22
- version = '3'
23
- url = Fog.credentials[:openstack_auth_url] || args[:openstack_auth_url]
24
- if url
25
- uri = URI(url)
26
- version = '2.0' if uri.path =~ /v2\.0/
27
- end
28
-
29
- service = case version
30
- when '2.0'
31
- Fog::Identity::OpenStack::V2.new(args)
32
- else
33
- Fog::Identity::OpenStack::V3.new(args)
8
+ version = if args[:openstack_identity_api_version] =~ /(v)*2(\.0)*/i
9
+ '2.0'
10
+ elsif args[:openstack_auth_url] =~ /v3|v2(\.0)*/
11
+ # Deprecated from fog-openstack 0.2.0
12
+ # Will be removed in future after hard deprecation is enforced for a couple of releases
13
+ Fog::Logger.deprecation("An authentication URL including a version is deprecated")
14
+ case args[:openstack_auth_url]
15
+ when /v3/
16
+ args[:openstack_auth_url].gsub!(/\/v3(\/)*.*/, '')
17
+ 'v3'
18
+ when /v2(\.0)*/
19
+ args[:openstack_auth_url].gsub!(/\/v2(\.0)*(\/)*.*/, '')
20
+ '2.0'
21
+ end
34
22
  end
35
- service
23
+
24
+ case version
25
+ when '2.0'
26
+ Fog::Identity::OpenStack::V2.new(args)
27
+ else
28
+ Fog::Identity::OpenStack::V3.new(args)
29
+ end
36
30
  end
37
31
 
38
32
  class Mock
@@ -47,39 +41,10 @@ module Fog
47
41
  class Real
48
42
  include Fog::OpenStack::Core
49
43
 
50
- DEFAULT_SERVICE_TYPE_V3 = %w(identity_v3 identityv3 identity).collect(&:freeze).freeze
51
- DEFAULT_SERVICE_TYPE = %w(identity).collect(&:freeze).freeze
52
-
53
44
  def self.not_found_class
54
45
  Fog::Identity::OpenStack::NotFound
55
46
  end
56
47
 
57
- def initialize(options = {})
58
- if options.respond_to?(:config_service?) && options.config_service?
59
- configure(options)
60
- return
61
- end
62
-
63
- initialize_identity(options)
64
-
65
- @openstack_service_type = options[:openstack_service_type] || default_service_type(options)
66
- @openstack_service_name = options[:openstack_service_name]
67
-
68
- @connection_options = options[:connection_options] || {}
69
-
70
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
71
- initialize_endpoint_path_matches(options)
72
-
73
- authenticate
74
-
75
- if options[:openstack_identity_prefix]
76
- @path = "/#{options[:openstack_identity_prefix]}/#{@path}"
77
- end
78
-
79
- @persistent = options[:persistent] || false
80
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
81
- end
82
-
83
48
  def config_service?
84
49
  true
85
50
  end
@@ -88,23 +53,11 @@ module Fog
88
53
  self
89
54
  end
90
55
 
91
- private
92
-
93
- def default_service_type(options)
94
- unless options[:openstack_identity_prefix]
95
- if @openstack_auth_uri.path =~ %r{/v3} ||
96
- (options[:openstack_endpoint_path_matches] && options[:openstack_endpoint_path_matches] =~ '/v3')
97
- return DEFAULT_SERVICE_TYPE_V3
98
- end
99
- end
100
- DEFAULT_SERVICE_TYPE
56
+ def default_endpoint_type
57
+ 'admin'
101
58
  end
102
59
 
103
- def initialize_endpoint_path_matches(options)
104
- if options[:openstack_endpoint_path_matches]
105
- @openstack_endpoint_path_matches = options[:openstack_endpoint_path_matches]
106
- end
107
- end
60
+ private
108
61
 
109
62
  def configure(source)
110
63
  source.instance_variables.each do |v|
@@ -14,7 +14,7 @@ module Fog
14
14
  :openstack_project_name, :openstack_project_id,
15
15
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
16
16
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
17
- :openstack_identity_prefix, :openstack_endpoint_path_matches
17
+ :openstack_identity_api_version
18
18
 
19
19
  model_path 'fog/identity/openstack/v2/models'
20
20
  model :tenant
@@ -169,10 +169,12 @@ module Fog
169
169
  end
170
170
 
171
171
  class Real < Fog::Identity::OpenStack::Real
172
- private
172
+ def default_path_prefix
173
+ 'v2.0'
174
+ end
173
175
 
174
- def default_service_type(_)
175
- DEFAULT_SERVICE_TYPE
176
+ def default_service_type
177
+ %w[identity_v2 identityv2 identity]
176
178
  end
177
179
  end
178
180
  end
@@ -13,7 +13,7 @@ module Fog
13
13
  :openstack_user_domain_id, :openstack_project_domain_id,
14
14
  :openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username,
15
15
  :current_user, :current_user_id, :current_tenant,
16
- :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches, :openstack_cache_ttl
16
+ :provider, :openstack_identity_api_version, :openstack_cache_ttl
17
17
 
18
18
  model_path 'fog/identity/openstack/v3/models'
19
19
  model :domain
@@ -142,18 +142,12 @@ module Fog
142
142
  end
143
143
 
144
144
  class Real < Fog::Identity::OpenStack::Real
145
- private
146
-
147
- def default_service_type(_)
148
- DEFAULT_SERVICE_TYPE_V3
145
+ def default_path_prefix
146
+ 'v3'
149
147
  end
150
148
 
151
- def initialize_endpoint_path_matches(options)
152
- if options[:openstack_endpoint_path_matches]
153
- @openstack_endpoint_path_matches = options[:openstack_endpoint_path_matches]
154
- else
155
- @openstack_endpoint_path_matches = %r{/v3} unless options[:openstack_identity_prefix]
156
- end
149
+ def default_service_type
150
+ %w[identity_v3 identityv3 identity]
157
151
  end
158
152
  end
159
153
  end
@@ -16,7 +16,7 @@ module Fog
16
16
  :openstack_project_name, :openstack_project_id,
17
17
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
18
18
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
19
- :openstack_identity_prefix
19
+ :openstack_identity_api_version
20
20
 
21
21
  model_path 'fog/image/openstack/v1/models'
22
22
 
@@ -102,29 +102,16 @@ module Fog
102
102
  Fog::Image::OpenStack::NotFound
103
103
  end
104
104
 
105
- def initialize(options = {})
106
- initialize_identity options
107
-
108
- @openstack_service_type = options[:openstack_service_type] || ['image']
109
- @openstack_service_name = options[:openstack_service_name]
110
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
111
-
112
- @connection_options = options[:connection_options] || {}
113
-
114
- authenticate
115
- set_api_path
105
+ def default_endpoint_type
106
+ 'admin'
107
+ end
116
108
 
117
- @persistent = options[:persistent] || false
118
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
109
+ def default_path_prefix
110
+ 'v1'
119
111
  end
120
112
 
121
- def set_api_path
122
- unless @path.match(SUPPORTED_VERSIONS)
123
- @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
124
- @openstack_management_uri,
125
- @auth_token,
126
- @connection_options)
127
- end
113
+ def default_service_type
114
+ %w[image]
128
115
  end
129
116
  end
130
117
  end
@@ -16,7 +16,7 @@ module Fog
16
16
  :openstack_project_name, :openstack_project_id,
17
17
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
18
18
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
19
- :openstack_identity_prefix
19
+ :openstack_identity_api_version
20
20
 
21
21
  model_path 'fog/image/openstack/v2/models'
22
22
 
@@ -110,29 +110,16 @@ module Fog
110
110
  Fog::Image::OpenStack::NotFound
111
111
  end
112
112
 
113
- def initialize(options = {})
114
- initialize_identity options
115
-
116
- @openstack_service_type = options[:openstack_service_type] || ['image']
117
- @openstack_service_name = options[:openstack_service_name]
118
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
119
-
120
- @connection_options = options[:connection_options] || {}
121
-
122
- authenticate
123
- set_api_path
113
+ def default_endpoint_type
114
+ 'admin'
115
+ end
124
116
 
125
- @persistent = options[:persistent] || false
126
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
117
+ def default_path_prefix
118
+ 'v2'
127
119
  end
128
120
 
129
- def set_api_path
130
- unless @path.match(SUPPORTED_VERSIONS)
131
- @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
132
- @openstack_management_uri,
133
- @auth_token,
134
- @connection_options)
135
- end
121
+ def default_service_type
122
+ %w[image]
136
123
  end
137
124
  end
138
125
  end
@@ -47,7 +47,7 @@ module Fog
47
47
  elsif attributes.key?(method_sym.to_s)
48
48
  attributes[method_sym.to_s]
49
49
  elsif method_sym.to_s.end_with?('=')
50
- attributes[method_sym.to_s.gsub(/=$/, '')] = arguments[0]
50
+ attributes[method_sym.to_s.gsub(/=$/, '').to_sym] = arguments[0]
51
51
  else
52
52
  super
53
53
  end
@@ -57,8 +57,6 @@ module Fog
57
57
  def initialize(options = {})
58
58
  @auth_token = Fog::Mock.random_base64(64)
59
59
  @auth_token_expiration = (Time.now.utc + 86_400).iso8601
60
-
61
- initialize_identity options
62
60
  end
63
61
 
64
62
  def data
@@ -77,25 +75,12 @@ module Fog
77
75
  Fog::Introspection::OpenStack::NotFound
78
76
  end
79
77
 
80
- def initialize(options = {})
81
- initialize_identity options
82
-
83
- @openstack_service_type = options[:openstack_service_type] || ['baremetal-introspection']
84
- @openstack_service_name = options[:openstack_service_name]
85
-
86
- @connection_options = options[:connection_options] || {}
87
-
88
- authenticate
89
- set_api_path
90
-
91
- @persistent = options[:persistent] || false
92
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
78
+ def default_path_prefix
79
+ 'v1'
93
80
  end
94
81
 
95
- def set_api_path
96
- unless @path.match(SUPPORTED_VERSIONS)
97
- @path = "/v1"
98
- end
82
+ def default_service_type
83
+ %w[baremetal-introspection]
99
84
  end
100
85
  end
101
86
  end
@@ -13,7 +13,7 @@ module Fog
13
13
  :openstack_project_name, :openstack_project_id,
14
14
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
15
15
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
16
- :openstack_identity_prefix, :openstack_temp_url_key, :openstack_cache_ttl
16
+ :openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl
17
17
 
18
18
 
19
19
  ## MODELS
@@ -96,55 +96,13 @@ module Fog
96
96
  Fog::KeyManager::OpenStack::NotFound
97
97
  end
98
98
 
99
- def initialize(options = {})
100
- initialize_identity options
101
-
102
- @openstack_service_type = options[:openstack_service_type] || ['key-manager']
103
- @openstack_service_name = options[:openstack_service_name]
104
- @connection_options = options[:connection_options] || {}
105
-
106
- authenticate
107
- set_api_path
108
-
109
- @persistent = options[:persistent] || false
110
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
111
- end
112
-
113
- def set_api_path
114
- @path.sub!(%r{/$}, '')
115
- unless @path.match(SUPPORTED_VERSIONS)
116
- @path = supported_version(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options)
117
- end
99
+ def default_path_prefix
100
+ 'v1'
118
101
  end
119
102
 
120
- def supported_version(supported_versions, uri, auth_token, connection_options = {})
121
- connection = Fog::Core::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}", false, connection_options)
122
- response = connection.request({ :expects => [200, 204, 300],
123
- :headers => {'Content-Type' => 'application/json',
124
- 'Accept' => 'application/json',
125
- 'X-Auth-Token' => auth_token},
126
- :method => 'GET'
127
- })
128
-
129
- body = Fog::JSON.decode(response.body)
130
- version = nil
131
-
132
- versions = body.fetch('versions',{}).fetch('values',[])
133
- versions.each do |v|
134
- if v.fetch('id', "").match(supported_versions) &&
135
- ['current', 'supported', 'stable'].include?(v.fetch('status','').downcase)
136
- version = v['id']
137
- end
138
- end
139
-
140
- if !version || version.empty?
141
- raise Fog::OpenStack::Errors::ServiceUnavailable.new(
142
- "OpenStack service only supports API versions #{supported_versions.inspect}")
143
- end
144
-
145
- version
103
+ def default_service_type
104
+ %w[key-manager]
146
105
  end
147
-
148
106
  end
149
107
  end
150
108
  end
@@ -15,7 +15,7 @@ module Fog
15
15
  :openstack_project_name, :openstack_project_id,
16
16
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
17
17
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
18
- :openstack_identity_prefix
18
+ :openstack_identity_api_version
19
19
 
20
20
  model_path 'fog/metering/openstack/models'
21
21
 
@@ -100,31 +100,16 @@ module Fog
100
100
  Fog::Metering::OpenStack::NotFound
101
101
  end
102
102
 
103
- def initialize(options = {})
104
- initialize_identity options
105
-
106
- @openstack_service_type = options[:openstack_service_type] || ['metering']
107
- @openstack_service_name = options[:openstack_service_name]
108
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
109
-
110
- @connection_options = options[:connection_options] || {}
111
-
112
- authenticate
113
- set_api_path
103
+ def default_endpoint_type
104
+ 'admin'
105
+ end
114
106
 
115
- @persistent = options[:persistent] || false
116
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
107
+ def default_path_prefix
108
+ 'v2'
117
109
  end
118
110
 
119
- def set_api_path
120
- unless @path.match(SUPPORTED_VERSIONS)
121
- @path = "/" + Fog::OpenStack.get_supported_version(
122
- SUPPORTED_VERSIONS,
123
- @openstack_management_uri,
124
- @auth_token,
125
- @connection_options
126
- )
127
- end
111
+ def default_service_type
112
+ %w[metering]
128
113
  end
129
114
  end
130
115
  end
@@ -13,7 +13,7 @@ module Fog
13
13
  :openstack_project_name, :openstack_project_id,
14
14
  :openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
15
15
  :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
16
- :openstack_identity_prefix
16
+ :openstack_identity_api_version
17
17
 
18
18
  model_path 'fog/metric/openstack/models'
19
19
 
@@ -90,35 +90,16 @@ module Fog
90
90
  class Real
91
91
  include Fog::OpenStack::Core
92
92
 
93
- def self.not_found_class
94
- Fog::Metric::OpenStack::NotFound
93
+ def default_path_prefix
94
+ 'v1'
95
95
  end
96
96
 
97
- def initialize(options = {})
98
- initialize_identity options
99
-
100
- @openstack_service_type = options[:openstack_service_type] || ['metric']
101
- @openstack_service_name = options[:openstack_service_name]
102
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
103
-
104
- @connection_options = options[:connection_options] || {}
105
-
106
- authenticate
107
- set_api_path
108
-
109
- @persistent = options[:persistent] || false
110
- @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
97
+ def self.not_found_class
98
+ Fog::Metric::OpenStack::NotFound
111
99
  end
112
100
 
113
- def set_api_path
114
- unless @path.match(SUPPORTED_VERSIONS)
115
- @path = Fog::OpenStack.get_supported_version_path(
116
- SUPPORTED_VERSIONS,
117
- @openstack_management_uri,
118
- @auth_token,
119
- @connection_options
120
- )
121
- end
101
+ def default_service_type
102
+ %w[metric]
122
103
  end
123
104
  end
124
105
  end