misty 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -23
  3. data/lib/misty/auth.rb +24 -19
  4. data/lib/misty/auth/auth_v2.rb +12 -12
  5. data/lib/misty/auth/auth_v3.rb +15 -15
  6. data/lib/misty/autoload.rb +27 -27
  7. data/lib/misty/cloud.rb +2 -1
  8. data/lib/misty/http/client.rb +17 -15
  9. data/lib/misty/http/method_builder.rb +1 -1
  10. data/lib/misty/http/net_http.rb +12 -7
  11. data/lib/misty/http/request.rb +13 -7
  12. data/lib/misty/misty.rb +30 -30
  13. data/lib/misty/openstack/aodh/v2.rb +1 -1
  14. data/lib/misty/openstack/ceilometer/v2.rb +1 -1
  15. data/lib/misty/openstack/cinder/v1.rb +2 -2
  16. data/lib/misty/openstack/cinder/v2.rb +2 -2
  17. data/lib/misty/openstack/cinder/v3.rb +2 -2
  18. data/lib/misty/openstack/designate/v2.rb +1 -1
  19. data/lib/misty/openstack/freezer/v1.rb +1 -1
  20. data/lib/misty/openstack/glance/v1.rb +1 -1
  21. data/lib/misty/openstack/glance/v2.rb +1 -1
  22. data/lib/misty/openstack/heat/v1.rb +2 -2
  23. data/lib/misty/openstack/ironic/v1.rb +2 -2
  24. data/lib/misty/openstack/karbor/v1.rb +1 -1
  25. data/lib/misty/openstack/keystone/v2_0.rb +2 -2
  26. data/lib/misty/openstack/keystone/v3.rb +2 -2
  27. data/lib/misty/openstack/magnum/v1.rb +2 -2
  28. data/lib/misty/openstack/manila/v2.rb +2 -2
  29. data/lib/misty/openstack/microversion.rb +9 -9
  30. data/lib/misty/openstack/murano/v1.rb +1 -1
  31. data/lib/misty/openstack/neutron/v2_0.rb +1 -1
  32. data/lib/misty/openstack/nova/v2_1.rb +4 -4
  33. data/lib/misty/openstack/octavia/v2_0.rb +1 -1
  34. data/lib/misty/openstack/sahara/v1_1.rb +1 -1
  35. data/lib/misty/openstack/searchlight/v1.rb +1 -1
  36. data/lib/misty/openstack/senlin/v1.rb +1 -1
  37. data/lib/misty/openstack/swift/v1.rb +1 -1
  38. data/lib/misty/openstack/tacker/v1_0.rb +1 -1
  39. data/lib/misty/openstack/trove/v1_0.rb +1 -1
  40. data/lib/misty/openstack/zaqar/v2.rb +1 -1
  41. data/lib/misty/services.rb +1 -1
  42. data/lib/misty/version.rb +1 -1
  43. data/test/integration/compute_test.rb +17 -17
  44. data/test/integration/network_test.rb +16 -16
  45. data/test/integration/orchestration_test.rb +51 -51
  46. data/test/integration/test_helper.rb +7 -7
  47. data/test/unit/auth/name_test.rb +53 -53
  48. data/test/unit/auth_test.rb +151 -152
  49. data/test/unit/cloud/requests_test.rb +58 -58
  50. data/test/unit/cloud/services_test.rb +62 -62
  51. data/test/unit/cloud_test.rb +48 -48
  52. data/test/unit/http/client_test.rb +21 -28
  53. data/test/unit/http/direct_test.rb +31 -31
  54. data/test/unit/http/method_builder_test.rb +42 -42
  55. data/test/unit/http/request_test.rb +33 -33
  56. data/test/unit/misty_test.rb +28 -28
  57. data/test/unit/openstack/APIs_test.rb +3 -3
  58. data/test/unit/openstack/microversion_test.rb +14 -14
  59. data/test/unit/service_helper.rb +4 -4
  60. data/test/unit/services_test.rb +5 -5
  61. data/test/unit/test_helper.rb +1 -1
  62. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1677bc6d745dc6d7e0fd3623c5aad22e833bba31
4
- data.tar.gz: 0554f06362e16e60981a6586c548b5ccd3173bce
3
+ metadata.gz: 90247f6d9f8410d55769850fbb2e2e6332e35e7d
4
+ data.tar.gz: 73c5cb98cf6826bfe7256e90e592498b25ab9500
5
5
  SHA512:
6
- metadata.gz: 1cd973ec3cc1f5ea5b9abf0d3abb98c9bb06edd0b7e9f432b87a3c025f0a0d48cb5414863c9fbd628f8cbb54a75cf0f59f4e8c04b0bf53625f981548803836d8
7
- data.tar.gz: d331411fea6186a116f35d1ca49103e191e5795d0adec2ab726679b67b58c5f4d70109b1f4a9fd7026d9a27135bada848db2bc16d2b4c498eedbb964c3a75dbb
6
+ metadata.gz: d0cc5cfae68ecfe28122303f1f7b0a909faf9baf33441db4d85700e2e86c08f68e4dba0465476621a91b63eb1c7d1fe4530b9cf7f4753438c1bdb6b448d1bce5
7
+ data.tar.gz: bb19851c6bd284bc0ef9d74eb740f84300f714fb33beb6ee16b6f94e3d86630bb59d622270ef3daed9d54753681b8b9cfbb5e3143638f5b0de23ba40b06be5c2
data/README.md CHANGED
@@ -46,11 +46,11 @@ gem install misty
46
46
  require 'misty'
47
47
 
48
48
  auth_v3 = {
49
- :url => "http://localhost:5000",
50
- :user => "admin",
51
- :password => "secret",
52
- :domain => "default",
53
- :project => "admin",
49
+ :url => 'http://localhost:5000',
50
+ :user => 'admin',
51
+ :password => 'secret',
52
+ :domain => 'default',
53
+ :project => 'admin',
54
54
  :project_domain_id => 'default'
55
55
  }
56
56
 
@@ -59,7 +59,7 @@ openstack = Misty::Cloud.new(:auth => auth_v3)
59
59
  puts openstack.compute.list_servers.body
60
60
  puts openstack.compute.list_flavors.body
61
61
  networks = openstack.network.list_networks
62
- network_id = networks.body["networks"][0]['id']
62
+ network_id = networks.body['networks'][0]['id']
63
63
  network = openstack.network.show_network_details(network_id)
64
64
  puts network.body
65
65
  ```
@@ -76,7 +76,7 @@ Each service name (i.e. `compute`) is the object handling API requests.
76
76
  openstack = Misty::Cloud.new(:auth => { ... })
77
77
  openstack.compute.list_servers
78
78
  openstack.network.list_networks
79
- openstack.network.create_network("network": {"name": "my-network"})
79
+ openstack.network.create_network('network': {'name': 'my-network'})
80
80
  ```
81
81
 
82
82
  To obtain the list of supported services:
@@ -197,12 +197,12 @@ Keystone v3 is default recommended version:
197
197
 
198
198
  ```ruby
199
199
  auth = {
200
- :url => "http://localhost:5000",
201
- :user => "admin",
202
- :user_domain => "default",
203
- :password => "secret",
204
- :project => "admin",
205
- :project_domain => "default"
200
+ :url => 'http://localhost:5000',
201
+ :user => 'admin',
202
+ :user_domain => 'default',
203
+ :password => 'secret',
204
+ :project => 'admin',
205
+ :project_domain => 'default'
206
206
  }
207
207
  }
208
208
  ```
@@ -211,10 +211,10 @@ Alternatively, using IDs:
211
211
 
212
212
  ```ruby
213
213
  auth = {
214
- :url => "http://localhost:5000",
215
- :user_id => "48985e6b8da145699d411f12a3459fca",
216
- :password => "secret",
217
- :project_id => "8e1e232f6cbb4116bbef715d8a0afe6e",
214
+ :url => 'http://localhost:5000',
215
+ :user_id => '48985e6b8da145699d411f12a3459fca',
216
+ :password => 'secret',
217
+ :project_id => '8e1e232f6cbb4116bbef715d8a0afe6e',
218
218
  }
219
219
  }
220
220
  ```
@@ -223,10 +223,10 @@ Provide the tenant details, Misty will detect it's using v2.0 for authentication
223
223
 
224
224
  ```ruby
225
225
  auth = {
226
- :url => "http://localhost:5000",
227
- :user => "admin",
228
- :password => "secret",
229
- :tenant => "admin",
226
+ :url => 'http://localhost:5000',
227
+ :user => 'admin',
228
+ :password => 'secret',
229
+ :tenant => 'admin',
230
230
  }
231
231
  ```
232
232
  ### Logging parameters
@@ -300,13 +300,13 @@ The following options are available:
300
300
 
301
301
  Example:
302
302
  ```ruby
303
- openstack = Misty::Cloud.new(:auth => auth, :log_level => 0, :identity => {:region_id => "regionTwo"}, :compute => {:version => "2.27", :interface => "admin"})
303
+ openstack = Misty::Cloud.new(:auth => auth, :log_level => 0, :identity => {:region_id => 'regionTwo'}, :compute => {:version => '2.27', :interface => 'admin'})
304
304
  ```
305
305
 
306
306
  ## Direct REST HTTP Methods
307
307
  To send requests directly use the 'get', 'delete', 'post' and 'put' methods directly:
308
308
  ```ruby
309
- openstack.network.post("/v2.0/qos/policies/48985e6b8da145699d411f12a3459fca/dscp_marking_rules", data)
309
+ openstack.network.post('/v2.0/qos/policies/48985e6b8da145699d411f12a3459fca/dscp_marking_rules', data)
310
310
  ```
311
311
  # Requirements
312
312
 
@@ -17,48 +17,53 @@ module Misty
17
17
  attr_reader :catalog, :token
18
18
 
19
19
  def self.factory(auth, config)
20
- http = nil
21
- unless auth[:context]
22
- raise URLError, "No URL provided" unless auth[:url] && !auth[:url].empty?
23
- http = Misty::HTTP::NetHTTP.net_http(URI.parse(auth[:url]), config.ssl_verify_mode, config.log)
24
- end
25
-
26
- if auth[:tenant_id] || auth[:tenant]
27
- return Misty::AuthV2.new(auth, http)
28
- else
29
- return Misty::AuthV3.new(auth, http)
30
- end
20
+ version = auth[:tenant_id] || auth[:tenant] ? 'V2' : 'V3'
21
+ klass = Object.const_get("Misty::Auth#{version}")
22
+ klass.new(auth, config)
31
23
  end
32
24
 
33
- def initialize(auth, http)
25
+ def initialize(auth, config)
34
26
  if auth[:context]
35
27
  # bypass the authentication by given token catalog and expire date
36
28
  @token = auth[:context][:token]
37
29
  @catalog = auth[:context][:catalog]
38
30
  @expires = auth[:context][:expires]
39
31
  else
40
- @http = http
32
+ raise URLError, 'No URL provided' if auth[:url].nil? || auth[:url].empty?
33
+ @uri = URI.parse(auth[:url])
34
+ @config = config
41
35
  # autheticate
42
36
  @credentials = set_credentials(auth)
43
37
  @token, @catalog, @expires = set(authenticate)
44
38
  end
39
+ #byebug unless config.is_a?(Misty::Cloud::Config)
45
40
  end
46
41
 
47
42
  def authenticate
48
- response = @http.post(self.class.path, @credentials.to_json, Misty::HEADER_JSON)
49
- raise AuthenticationError, "Response code=#{response.code}, Msg=#{response.msg}" unless response.code =~ /200|201/
50
- response
43
+ Misty::HTTP::NetHTTP.http_request(
44
+ @uri, ssl_verify_mode: @config.ssl_verify_mode, log: @config.log
45
+ ) do |connection|
46
+ response = connection.post(self.class.path, @credentials.to_json,
47
+ Misty::HEADER_JSON)
48
+ unless response.code =~ /200|201/
49
+ raise AuthenticationError,
50
+ "Response code=#{response.code}, Msg=#{response.msg}"
51
+ end
52
+ response
53
+ end
51
54
  end
52
55
 
53
56
  def expired?
54
- raise ExpiryError, "Missing token expiration data" if @expires.nil? || @expires.empty?
57
+ if @expires.nil? || @expires.empty?
58
+ raise ExpiryError, 'Missing token expiration data'
59
+ end
55
60
  Time.parse(@expires) < Time.now.utc
56
61
  end
57
62
 
58
63
  def get_endpoint(service_names, region, interface)
59
64
  @catalog.each do |catalog|
60
- if service_names.include? catalog["type"]
61
- return catalog_endpoints(catalog["endpoints"], region, interface)
65
+ if service_names.include? catalog['type']
66
+ return catalog_endpoints(catalog['endpoints'], region, interface)
62
67
  end
63
68
  end
64
69
  raise CatalogError, "No service found with either #{service_names} name, region #{region}, interface #{interface}"
@@ -3,12 +3,12 @@ require 'misty/auth'
3
3
  module Misty
4
4
  class AuthV2 < Misty::Auth
5
5
  def self.path
6
- "/v2.0/tokens"
6
+ '/v2.0/tokens'
7
7
  end
8
8
 
9
9
  def catalog_endpoints(endpoints, region, interface)
10
10
  endpoints.each do |endpoint|
11
- if endpoint["region"] == region && endpoint["#{interface}URL"]
11
+ if endpoint['region'] == region && endpoint["#{interface}URL"]
12
12
  return endpoint["#{interface}URL"]
13
13
  end
14
14
  end
@@ -16,28 +16,28 @@ module Misty
16
16
 
17
17
  def credentials
18
18
  if @token
19
- identity = { "token": { "id": @token } }
19
+ identity = { 'token': { 'id': @token } }
20
20
  else
21
21
  raise Misty::Auth::CredentialsError, "#{self.class}: User name is required" if @user.name.nil?
22
22
  raise Misty::Auth::CredentialsError, "#{self.class}: User password is required" if @user.password.nil?
23
- identity = { "passwordCredentials": user_credentials }
23
+ identity = { 'passwordCredentials': user_credentials }
24
24
  end
25
25
 
26
26
  if @tenant.id
27
- identity.merge!("tenantId": @tenant.id)
27
+ identity.merge!('tenantId': @tenant.id)
28
28
  elsif @tenant.name
29
- identity.merge!("tenantName": @tenant.name)
29
+ identity.merge!('tenantName': @tenant.name)
30
30
  else
31
31
  raise Misty::Auth::CredentialsError, "#{self.class}: No tenant available"
32
32
  end
33
33
 
34
- { "auth": identity }
34
+ { 'auth': identity }
35
35
  end
36
36
 
37
37
  def user_credentials
38
38
  {
39
- "username": @user.name,
40
- "password": @user.password
39
+ 'username': @user.name,
40
+ 'password': @user.password
41
41
  }
42
42
  end
43
43
 
@@ -49,9 +49,9 @@ module Misty
49
49
 
50
50
  def set(response)
51
51
  payload = JSON.load(response.body)
52
- token = payload["access"]["token"]["id"]
53
- catalog = payload["access"]["serviceCatalog"]
54
- expires = payload["access"]["token"]["expires"]
52
+ token = payload['access']['token']['id']
53
+ catalog = payload['access']['serviceCatalog']
54
+ expires = payload['access']['token']['expires']
55
55
  [token, catalog, expires]
56
56
  end
57
57
 
@@ -3,13 +3,13 @@ require 'misty/auth'
3
3
  module Misty
4
4
  class AuthV3 < Misty::Auth
5
5
  def self.path
6
- "/v3/auth/tokens"
6
+ '/v3/auth/tokens'
7
7
  end
8
8
 
9
9
  def catalog_endpoints(endpoints, region, interface)
10
10
  endpoints.each do |endpoint|
11
- if endpoint["region_id"] == region && endpoint["interface"] == interface
12
- return endpoint["url"]
11
+ if endpoint['region_id'] == region && endpoint['interface'] == interface
12
+ return endpoint['url']
13
13
  end
14
14
  end
15
15
  end
@@ -17,27 +17,27 @@ module Misty
17
17
  def credentials
18
18
  if @token
19
19
  identity = {
20
- "methods": ["token"],
21
- "token": { "id": @token }
20
+ 'methods': ['token'],
21
+ 'token': { 'id': @token }
22
22
  }
23
23
  else
24
24
  identity = {
25
- "methods": ["password"],
26
- "password": @user.identity
25
+ 'methods': ['password'],
26
+ 'password': @user.identity
27
27
  }
28
28
  end
29
29
  {
30
- "auth": {
31
- "identity": identity,
32
- "scope": scope
30
+ 'auth': {
31
+ 'identity': identity,
32
+ 'scope': scope
33
33
  }
34
34
  }
35
35
  end
36
36
 
37
37
  def get_endpoint_url(endpoints, region, interface)
38
- endpoint = endpoints.select { |ep| ep["region_id"] == region && ep["interface"] == interface }
38
+ endpoint = endpoints.select { |ep| ep['region_id'] == region && ep['interface'] == interface }
39
39
  raise CatalogError, "No endpoint available for region '#{region}' and interface '#{interface}'" unless endpoint
40
- endpoint[0]["url"]
40
+ endpoint[0]['url']
41
41
  end
42
42
 
43
43
  def scope
@@ -48,9 +48,9 @@ module Misty
48
48
 
49
49
  def set(response)
50
50
  payload = JSON.load(response.body)
51
- token = response["x-subject-token"]
52
- catalog = payload["token"]["catalog"]
53
- expires = payload["token"]["expires_at"]
51
+ token = response['x-subject-token']
52
+ catalog = payload['token']['catalog']
53
+ expires = payload['token']['expires_at']
54
54
  [token, catalog, expires]
55
55
  end
56
56
 
@@ -1,99 +1,99 @@
1
1
  module Misty
2
2
  module Openstack
3
3
  module Aodh
4
- autoload :V2, "misty/openstack/aodh/v2"
4
+ autoload :V2, 'misty/openstack/aodh/v2'
5
5
  end
6
6
 
7
7
  module Ceilometer
8
- autoload :V2, "misty/openstack/ceilometer/v2"
8
+ autoload :V2, 'misty/openstack/ceilometer/v2'
9
9
  end
10
10
 
11
11
  module Cinder
12
- autoload :V1, "misty/openstack/cinder/v1"
13
- autoload :V2, "misty/openstack/cinder/v2"
14
- autoload :V3, "misty/openstack/cinder/v3"
12
+ autoload :V1, 'misty/openstack/cinder/v1'
13
+ autoload :V2, 'misty/openstack/cinder/v2'
14
+ autoload :V3, 'misty/openstack/cinder/v3'
15
15
  end
16
16
 
17
17
  module Designate
18
- autoload :V2, "misty/openstack/designate/v2"
18
+ autoload :V2, 'misty/openstack/designate/v2'
19
19
  end
20
20
 
21
21
  module Freezer
22
- autoload :V1, "misty/openstack/freezer/v1"
22
+ autoload :V1, 'misty/openstack/freezer/v1'
23
23
  end
24
24
 
25
25
  module Glance
26
- autoload :V1, "misty/openstack/glance/v1"
27
- autoload :V2, "misty/openstack/glance/v2"
26
+ autoload :V1, 'misty/openstack/glance/v1'
27
+ autoload :V2, 'misty/openstack/glance/v2'
28
28
  end
29
29
 
30
30
  module Heat
31
- autoload :V1, "misty/openstack/heat/v1"
31
+ autoload :V1, 'misty/openstack/heat/v1'
32
32
  end
33
33
 
34
34
  module Ironic
35
- autoload :V1, "misty/openstack/ironic/v1"
35
+ autoload :V1, 'misty/openstack/ironic/v1'
36
36
  end
37
37
 
38
38
  module Karbor
39
- autoload :V1, "misty/openstack/karbor/v1"
39
+ autoload :V1, 'misty/openstack/karbor/v1'
40
40
  end
41
41
 
42
42
  module Keystone
43
- autoload :V3, "misty/openstack/keystone/v3"
44
- autoload :V2_0, "misty/openstack/keystone/v2_0"
43
+ autoload :V3, 'misty/openstack/keystone/v3'
44
+ autoload :V2_0, 'misty/openstack/keystone/v2_0'
45
45
  end
46
46
 
47
47
  module Magnum
48
- autoload :V1, "misty/openstack/magnum/v1"
48
+ autoload :V1, 'misty/openstack/magnum/v1'
49
49
  end
50
50
 
51
51
  module Manila
52
- autoload :V2, "misty/openstack/manila/v2"
52
+ autoload :V2, 'misty/openstack/manila/v2'
53
53
  end
54
54
 
55
55
  module Murano
56
- autoload :V1, "misty/openstack/murano/v1"
56
+ autoload :V1, 'misty/openstack/murano/v1'
57
57
  end
58
58
 
59
59
  module Neutron
60
- autoload :V2_0, "misty/openstack/neutron/v2_0"
60
+ autoload :V2_0, 'misty/openstack/neutron/v2_0'
61
61
  end
62
62
 
63
63
  module Nova
64
- autoload :V2_1, "misty/openstack/nova/v2_1"
64
+ autoload :V2_1, 'misty/openstack/nova/v2_1'
65
65
  end
66
66
 
67
67
  module Octavia
68
- autoload :V2_0, "misty/openstack/octavia/v2_0"
68
+ autoload :V2_0, 'misty/openstack/octavia/v2_0'
69
69
  end
70
70
 
71
71
  module Sahara
72
- autoload :V1_1, "misty/openstack/sahara/v1_1"
72
+ autoload :V1_1, 'misty/openstack/sahara/v1_1'
73
73
  end
74
74
 
75
75
  module Searchlight
76
- autoload :V1, "misty/openstack/searchlight/v1"
76
+ autoload :V1, 'misty/openstack/searchlight/v1'
77
77
  end
78
78
 
79
79
  module Senlin
80
- autoload :V1, "misty/openstack/senlin/v1"
80
+ autoload :V1, 'misty/openstack/senlin/v1'
81
81
  end
82
82
 
83
83
  module Swift
84
- autoload :V1, "misty/openstack/swift/v1"
84
+ autoload :V1, 'misty/openstack/swift/v1'
85
85
  end
86
86
 
87
87
  module Tacker
88
- autoload :V1_0, "misty/openstack/tacker/v1_0"
88
+ autoload :V1_0, 'misty/openstack/tacker/v1_0'
89
89
  end
90
90
 
91
91
  module Trove
92
- autoload :V1_0, "misty/openstack/trove/v1_0"
92
+ autoload :V1_0, 'misty/openstack/trove/v1_0'
93
93
  end
94
94
 
95
95
  module Zaqar
96
- autoload :V2, "misty/openstack/zaqar/v2"
96
+ autoload :V2, 'misty/openstack/zaqar/v2'
97
97
  end
98
98
  end
99
99
  end
@@ -4,7 +4,7 @@ require 'misty/auth/auth_v3'
4
4
  module Misty
5
5
  class Cloud
6
6
  class Config
7
- attr_accessor :auth, :content_type, :interface, :log, :region_id, :ssl_verify_mode
7
+ attr_accessor :auth, :content_type, :interface, :log, :region_id, :ssl_verify_mode, :headers
8
8
  end
9
9
 
10
10
  attr_reader :auth
@@ -27,6 +27,7 @@ module Misty
27
27
  config.log.level = params[:log_level] ? params[:log_level] : Misty::LOG_LEVEL
28
28
  config.region_id = params[:region_id] ? params[:region_id] : Misty::REGION_ID
29
29
  config.ssl_verify_mode = params.key?(:ssl_verify_mode) ? params[:ssl_verify_mode] : Misty::SSL_VERIFY_MODE
30
+ config.headers = params[:headers]
30
31
  config
31
32
  end
32
33