misty 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -23
- data/lib/misty/auth.rb +24 -19
- data/lib/misty/auth/auth_v2.rb +12 -12
- data/lib/misty/auth/auth_v3.rb +15 -15
- data/lib/misty/autoload.rb +27 -27
- data/lib/misty/cloud.rb +2 -1
- data/lib/misty/http/client.rb +17 -15
- data/lib/misty/http/method_builder.rb +1 -1
- data/lib/misty/http/net_http.rb +12 -7
- data/lib/misty/http/request.rb +13 -7
- data/lib/misty/misty.rb +30 -30
- data/lib/misty/openstack/aodh/v2.rb +1 -1
- data/lib/misty/openstack/ceilometer/v2.rb +1 -1
- data/lib/misty/openstack/cinder/v1.rb +2 -2
- data/lib/misty/openstack/cinder/v2.rb +2 -2
- data/lib/misty/openstack/cinder/v3.rb +2 -2
- data/lib/misty/openstack/designate/v2.rb +1 -1
- data/lib/misty/openstack/freezer/v1.rb +1 -1
- data/lib/misty/openstack/glance/v1.rb +1 -1
- data/lib/misty/openstack/glance/v2.rb +1 -1
- data/lib/misty/openstack/heat/v1.rb +2 -2
- data/lib/misty/openstack/ironic/v1.rb +2 -2
- data/lib/misty/openstack/karbor/v1.rb +1 -1
- data/lib/misty/openstack/keystone/v2_0.rb +2 -2
- data/lib/misty/openstack/keystone/v3.rb +2 -2
- data/lib/misty/openstack/magnum/v1.rb +2 -2
- data/lib/misty/openstack/manila/v2.rb +2 -2
- data/lib/misty/openstack/microversion.rb +9 -9
- data/lib/misty/openstack/murano/v1.rb +1 -1
- data/lib/misty/openstack/neutron/v2_0.rb +1 -1
- data/lib/misty/openstack/nova/v2_1.rb +4 -4
- data/lib/misty/openstack/octavia/v2_0.rb +1 -1
- data/lib/misty/openstack/sahara/v1_1.rb +1 -1
- data/lib/misty/openstack/searchlight/v1.rb +1 -1
- data/lib/misty/openstack/senlin/v1.rb +1 -1
- data/lib/misty/openstack/swift/v1.rb +1 -1
- data/lib/misty/openstack/tacker/v1_0.rb +1 -1
- data/lib/misty/openstack/trove/v1_0.rb +1 -1
- data/lib/misty/openstack/zaqar/v2.rb +1 -1
- data/lib/misty/services.rb +1 -1
- data/lib/misty/version.rb +1 -1
- data/test/integration/compute_test.rb +17 -17
- data/test/integration/network_test.rb +16 -16
- data/test/integration/orchestration_test.rb +51 -51
- data/test/integration/test_helper.rb +7 -7
- data/test/unit/auth/name_test.rb +53 -53
- data/test/unit/auth_test.rb +151 -152
- data/test/unit/cloud/requests_test.rb +58 -58
- data/test/unit/cloud/services_test.rb +62 -62
- data/test/unit/cloud_test.rb +48 -48
- data/test/unit/http/client_test.rb +21 -28
- data/test/unit/http/direct_test.rb +31 -31
- data/test/unit/http/method_builder_test.rb +42 -42
- data/test/unit/http/request_test.rb +33 -33
- data/test/unit/misty_test.rb +28 -28
- data/test/unit/openstack/APIs_test.rb +3 -3
- data/test/unit/openstack/microversion_test.rb +14 -14
- data/test/unit/service_helper.rb +4 -4
- data/test/unit/services_test.rb +5 -5
- data/test/unit/test_helper.rb +1 -1
- metadata +4 -4
data/lib/misty/http/client.rb
CHANGED
@@ -7,7 +7,8 @@ module Misty
|
|
7
7
|
module HTTP
|
8
8
|
class Client
|
9
9
|
class Options
|
10
|
-
attr_accessor :base_path, :base_url, :interface, :region_id,
|
10
|
+
attr_accessor :base_path, :base_url, :interface, :region_id,
|
11
|
+
:service_names, :ssl_verify_mode, :version, :headers
|
11
12
|
end
|
12
13
|
|
13
14
|
class InvalidDataError < StandardError; end
|
@@ -53,8 +54,7 @@ module Misty
|
|
53
54
|
@options = setup(options)
|
54
55
|
@uri = URI.parse(@auth.get_endpoint(@options.service_names, @options.region_id, @options.interface))
|
55
56
|
@base_path = @options.base_path ? @options.base_path : @uri.path
|
56
|
-
@base_path = @base_path.chomp(
|
57
|
-
@http = Misty::HTTP::NetHTTP.net_http(@uri, @options.ssl_verify_mode, @config.log)
|
57
|
+
@base_path = @base_path.chomp('/')
|
58
58
|
@version = nil
|
59
59
|
@microversion = false
|
60
60
|
end
|
@@ -63,11 +63,11 @@ module Misty
|
|
63
63
|
# When a catalog provides a base path and the Service API definition containts the generic equivalent as prefix
|
64
64
|
# then the preifx is redundant and must be removed from the path.
|
65
65
|
# For example:
|
66
|
-
# Catalog provides
|
67
|
-
# and Service API has
|
68
|
-
# then the path prefix is ignored and path is only
|
66
|
+
# Catalog provides 'http://192.0.2.21:8004/v1/48985e6b8da145699d411f12a3459fca'
|
67
|
+
# and Service API has '/v1/{tenant_id}/stacks'
|
68
|
+
# then the path prefix is ignored and path is only '/stacks'
|
69
69
|
def self.prefix_path_to_ignore
|
70
|
-
|
70
|
+
''
|
71
71
|
end
|
72
72
|
|
73
73
|
def headers_default
|
@@ -75,8 +75,9 @@ module Misty
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def headers
|
78
|
-
h = headers_default.merge(
|
78
|
+
h = headers_default.merge('X-Auth-Token' => @auth.get_token.to_s)
|
79
79
|
h.merge!(microversion_header) if microversion
|
80
|
+
h.merge!(@options.headers) if @options.headers
|
80
81
|
h
|
81
82
|
end
|
82
83
|
|
@@ -88,13 +89,14 @@ module Misty
|
|
88
89
|
|
89
90
|
def setup(params)
|
90
91
|
options = Options.new()
|
91
|
-
options.base_path
|
92
|
-
options.base_url
|
93
|
-
options.interface
|
94
|
-
options.region_id
|
95
|
-
options.service_names
|
96
|
-
options.ssl_verify_mode
|
97
|
-
options.
|
92
|
+
options.base_path = params[:base_path] ? params[:base_path] : nil
|
93
|
+
options.base_url = params[:base_url] ? params[:base_url] : nil
|
94
|
+
options.interface = params[:interface] ? params[:interface] : @config.interface
|
95
|
+
options.region_id = params[:region_id] ? params[:region_id] : @config.region_id
|
96
|
+
options.service_names = params[:service_name] ? self.class.service_names << params[:service_name] : self.class.service_names
|
97
|
+
options.ssl_verify_mode = params[:ssl_verify_mode] ? params[:ssl_verify_mode] : @config.ssl_verify_mode
|
98
|
+
options.headers = params[:headers] ? params[:headers] : @config.headers
|
99
|
+
options.version = params[:version] ? params[:version] : 'CURRENT'
|
98
100
|
|
99
101
|
unless INTERFACES.include?(options.interface)
|
100
102
|
raise InvalidDataError, "Options ':interface' must be one of #{INTERFACES}"
|
@@ -69,7 +69,7 @@ module Misty
|
|
69
69
|
subpath = /(.*)(\{.*\})(.*)/.match(str)
|
70
70
|
return str unless subpath
|
71
71
|
arg = args.pop
|
72
|
-
raise ArgumentError,
|
72
|
+
raise ArgumentError, 'Not enough arguments' unless arg
|
73
73
|
return inject_elements(subpath[1], args) + arg + subpath[3]
|
74
74
|
end
|
75
75
|
|
data/lib/misty/http/net_http.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
module Misty
|
2
2
|
module HTTP
|
3
|
+
# This class implements the http request routine.
|
3
4
|
module NetHTTP
|
4
|
-
def self.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def self.http_request(uri, options = {})
|
6
|
+
http_options = {}
|
7
|
+
if uri.scheme == 'https'
|
8
|
+
http_options[:use_ssl] = true
|
9
|
+
if options[:ssl_verify_mode] && options[:ssl_verify_mode] == false
|
10
|
+
http_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Net::HTTP.start(uri.host, uri.port, http_options) do |connection|
|
15
|
+
yield(connection)
|
10
16
|
end
|
11
|
-
http
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/lib/misty/http/request.rb
CHANGED
@@ -2,17 +2,23 @@ module Misty
|
|
2
2
|
module HTTP
|
3
3
|
module Request
|
4
4
|
def decode?(response)
|
5
|
-
|
6
|
-
|
7
|
-
&& response.header[
|
8
|
-
|
5
|
+
return false if response.body.nil? || response.body.empty?
|
6
|
+
if @config.content_type != :json && response.code =~ /2??/ && !response.is_a?(Net::HTTPNoContent) \
|
7
|
+
&& !response.is_a?(Net::HTTPResetContent) && response.header['content-type'] \
|
8
|
+
&& response.header['content-type'].include?('application/json')
|
9
|
+
return true
|
9
10
|
end
|
11
|
+
false
|
10
12
|
end
|
11
13
|
|
12
14
|
def http(request)
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
Misty::HTTP::NetHTTP.http_request(
|
16
|
+
@uri, ssl_verify_mode: @options.ssl_verify_mode, log: @config.log
|
17
|
+
) do |connection|
|
18
|
+
response = connection.request(request)
|
19
|
+
response.body = JSON.parse(response.body) if decode?(response)
|
20
|
+
response
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
def http_delete(path, headers)
|
data/lib/misty/misty.rb
CHANGED
@@ -2,12 +2,12 @@ require 'misty/services'
|
|
2
2
|
|
3
3
|
module Misty
|
4
4
|
HEADER_JSON = {
|
5
|
-
|
6
|
-
|
5
|
+
'Content-Type' => 'application/json',
|
6
|
+
'Accept' => 'application/json'
|
7
7
|
}
|
8
8
|
|
9
9
|
# Default log file. Use :log_file option to override
|
10
|
-
LOG_FILE =
|
10
|
+
LOG_FILE = 'misty.log'
|
11
11
|
# Default log level. Use :log_level option to override
|
12
12
|
LOG_LEVEL = Logger::INFO
|
13
13
|
|
@@ -17,42 +17,42 @@ module Misty
|
|
17
17
|
CONTENT_TYPE = :ruby
|
18
18
|
|
19
19
|
# Defaults Domain ID
|
20
|
-
DOMAIN_ID =
|
20
|
+
DOMAIN_ID = 'default'
|
21
21
|
|
22
22
|
# Default Interface
|
23
|
-
INTERFACE =
|
23
|
+
INTERFACE = 'public'
|
24
24
|
|
25
25
|
# Default Region ID
|
26
|
-
REGION_ID =
|
26
|
+
REGION_ID = 'regionOne'
|
27
27
|
|
28
|
-
# Default mode when SSL is used (uri.scheme ==
|
28
|
+
# Default mode when SSL is used (uri.scheme == 'https')
|
29
29
|
SSL_VERIFY_MODE = true
|
30
30
|
|
31
31
|
def self.services
|
32
32
|
services = Misty::Services.new
|
33
|
-
services.add(:application_catalog, :murano, [
|
34
|
-
services.add(:alarming, :aodh, [
|
35
|
-
services.add(:backup, :freezer, [
|
36
|
-
services.add(:baremetal, :ironic, [
|
37
|
-
services.add(:block_storage, :cinder, [
|
38
|
-
services.add(:clustering, :senlin, [
|
39
|
-
services.add(:compute, :nova, [
|
40
|
-
services.add(:container, :magnum, [
|
41
|
-
services.add(:data_processing, :sahara, [
|
42
|
-
services.add(:data_protection, :karbor, [
|
43
|
-
services.add(:database, :trove, [
|
44
|
-
services.add(:dns, :designate, [
|
45
|
-
services.add(:identity, :keystone, [
|
46
|
-
services.add(:image, :glance, [
|
47
|
-
services.add(:load_balancer, :octavia, [
|
48
|
-
services.add(:messaging, :zaqar, [
|
49
|
-
services.add(:metering, :ceilometer, [
|
50
|
-
services.add(:networking, :neutron, [
|
51
|
-
services.add(:nfv_orchestration, :tacker, [
|
52
|
-
services.add(:object_storage, :swift, [
|
53
|
-
services.add(:orchestration, :heat, [
|
54
|
-
services.add(:search, :searchlight, [
|
55
|
-
services.add(:shared_file_systems, :manila, [
|
33
|
+
services.add(:application_catalog, :murano, ['v1'])
|
34
|
+
services.add(:alarming, :aodh, ['v2'])
|
35
|
+
services.add(:backup, :freezer, ['v1'])
|
36
|
+
services.add(:baremetal, :ironic, ['v1'])
|
37
|
+
services.add(:block_storage, :cinder, ['v3', 'v2', 'v1'])
|
38
|
+
services.add(:clustering, :senlin, ['v1'])
|
39
|
+
services.add(:compute, :nova, ['v2.1'])
|
40
|
+
services.add(:container, :magnum, ['v1'])
|
41
|
+
services.add(:data_processing, :sahara, ['v1.1'])
|
42
|
+
services.add(:data_protection, :karbor, ['v1'])
|
43
|
+
services.add(:database, :trove, ['v1.0'])
|
44
|
+
services.add(:dns, :designate, ['v2'])
|
45
|
+
services.add(:identity, :keystone, ['v3', 'v2.0'])
|
46
|
+
services.add(:image, :glance, ['v2', 'v1'])
|
47
|
+
services.add(:load_balancer, :octavia, ['v2.0'])
|
48
|
+
services.add(:messaging, :zaqar, ['v2'])
|
49
|
+
services.add(:metering, :ceilometer, ['v2'])
|
50
|
+
services.add(:networking, :neutron, ['v2.0'])
|
51
|
+
services.add(:nfv_orchestration, :tacker, ['v1.0'])
|
52
|
+
services.add(:object_storage, :swift, ['v1'])
|
53
|
+
services.add(:orchestration, :heat, ['v1'])
|
54
|
+
services.add(:search, :searchlight, ['v1'])
|
55
|
+
services.add(:shared_file_systems, :manila, ['v2'])
|
56
56
|
services
|
57
57
|
end
|
58
58
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require
|
2
|
+
require 'misty/openstack/cinder/cinder_v1'
|
3
3
|
|
4
4
|
module Misty
|
5
5
|
module Openstack
|
@@ -12,7 +12,7 @@ module Misty
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.prefix_path_to_ignore
|
15
|
-
|
15
|
+
'/v1/{admin_tenant_id}/'
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.service_names
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require
|
2
|
+
require 'misty/openstack/cinder/cinder_v2'
|
3
3
|
|
4
4
|
module Misty
|
5
5
|
module Openstack
|
@@ -12,7 +12,7 @@ module Misty
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.prefix_path_to_ignore
|
15
|
-
|
15
|
+
'/v2/{tenant_id}'
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.service_names
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require
|
2
|
+
require 'misty/openstack/cinder/cinder_v3'
|
3
3
|
|
4
4
|
module Misty
|
5
5
|
module Openstack
|
@@ -12,7 +12,7 @@ module Misty
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.prefix_path_to_ignore
|
15
|
-
|
15
|
+
'/v3/{tenant_id}'
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.service_names
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require
|
2
|
+
require 'misty/openstack/heat/heat_v1'
|
3
3
|
|
4
4
|
module Misty
|
5
5
|
module Openstack
|
@@ -12,7 +12,7 @@ module Misty
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.prefix_path_to_ignore
|
15
|
-
|
15
|
+
'/v1/{tenant_id}'
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.service_names
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'misty/http/client'
|
2
2
|
require 'misty/openstack/microversion'
|
3
|
-
require
|
3
|
+
require 'misty/openstack/ironic/ironic_v1'
|
4
4
|
|
5
5
|
module Misty
|
6
6
|
module Openstack
|
@@ -18,7 +18,7 @@ module Misty
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def microversion_header
|
21
|
-
{
|
21
|
+
{ 'X-Openstack-Ironic-API-Version' => "#{@version}" }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'misty/openstack/keystone/keystone_v2_0'
|
3
|
+
require 'misty/openstack/keystone/keystone_v2_0_ext'
|
4
4
|
|
5
5
|
module Misty
|
6
6
|
module Openstack
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'misty/openstack/keystone/keystone_v3'
|
3
|
+
require 'misty/openstack/keystone/keystone_v3_ext'
|
4
4
|
|
5
5
|
module Misty
|
6
6
|
module Openstack
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'misty/http/client'
|
2
2
|
require 'misty/openstack/microversion'
|
3
|
-
require
|
3
|
+
require 'misty/openstack/magnum/magnum_v1'
|
4
4
|
|
5
5
|
module Misty
|
6
6
|
module Openstack
|
@@ -18,7 +18,7 @@ module Misty
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def microversion_header
|
21
|
-
{
|
21
|
+
{'X-Openstack-API-Version' => "#{baseclass.downcase} #{@version}" }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'misty/http/client'
|
2
2
|
require 'misty/openstack/microversion'
|
3
|
-
require
|
3
|
+
require 'misty/openstack/manila/manila_v2'
|
4
4
|
|
5
5
|
module Misty
|
6
6
|
module Openstack
|
@@ -18,7 +18,7 @@ module Misty
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def microversion_header
|
21
|
-
{
|
21
|
+
{ 'X-Openstack-Manila-API-Version' => "#{@version}" }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -28,7 +28,7 @@ module Misty
|
|
28
28
|
|
29
29
|
def version_by_number(number)
|
30
30
|
versions.each do |version|
|
31
|
-
return number if version[
|
31
|
+
return number if version['min_version'] <= number && version['version'] >= number
|
32
32
|
end
|
33
33
|
raise VersionError, "Version #{number} is out of range of available versions #{versions}"
|
34
34
|
end
|
@@ -36,25 +36,25 @@ module Misty
|
|
36
36
|
def version_by_state(state)
|
37
37
|
version_details = nil
|
38
38
|
versions.each do |version|
|
39
|
-
if version[
|
39
|
+
if version['status'] == state
|
40
40
|
version_details = version
|
41
41
|
break
|
42
42
|
end
|
43
43
|
end
|
44
44
|
raise VersionError, "Version #{state} is not available among #{versions}" if version_details.nil?
|
45
|
-
if version_details[
|
45
|
+
if version_details['version'].empty?
|
46
46
|
@microversion = false
|
47
|
-
return
|
47
|
+
return ''
|
48
48
|
end
|
49
|
-
version_details[
|
49
|
+
version_details['version']
|
50
50
|
end
|
51
51
|
|
52
52
|
def versions_fetch
|
53
|
-
|
54
|
-
response = @http.request request
|
53
|
+
response = http_get('/', headers_default)
|
55
54
|
raise VersionError, "Code: #{response.code}, Message: #{response.msg}" unless response.code =~ /2??/
|
56
|
-
|
57
|
-
|
55
|
+
data = response.body.is_a?(Hash) ? response.body : JSON.parse(response.body)
|
56
|
+
list = data['versions']
|
57
|
+
raise VersionError, 'Missing version data' unless list
|
58
58
|
list
|
59
59
|
end
|
60
60
|
end
|