misty 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +87 -88
- data/lib/misty.rb +115 -1
- data/lib/misty/auth/catalog.rb +38 -0
- data/lib/misty/auth/catalog/v2.rb +15 -0
- data/lib/misty/auth/catalog/v3.rb +15 -0
- data/lib/misty/auth/token.rb +70 -0
- data/lib/misty/auth/token/v2.rb +63 -0
- data/lib/misty/auth/token/v3.rb +90 -0
- data/lib/misty/cloud.rb +74 -15
- data/lib/misty/config.rb +37 -43
- data/lib/misty/errors.rb +25 -5
- data/lib/misty/helper.rb +26 -0
- data/lib/misty/http/header.rb +3 -6
- data/lib/misty/http/method_builder.rb +2 -2
- data/lib/misty/http/request.rb +3 -3
- data/lib/misty/microversion.rb +12 -1
- data/lib/misty/misty.rb +7 -62
- data/lib/misty/openstack.rb +39 -0
- data/lib/misty/openstack/{aodh → api/aodh}/aodh_v2.rb +1 -1
- data/lib/misty/openstack/api/aodh/v2.rb +19 -0
- data/lib/misty/openstack/api/barbican/barbican_v1.rb +42 -0
- data/lib/misty/openstack/api/barbican/v1.rb +19 -0
- data/lib/misty/openstack/api/blazar/blazar_v1.rb +16 -0
- data/lib/misty/openstack/api/blazar/v1.rb +19 -0
- data/lib/misty/openstack/{ceilometer → api/ceilometer}/ceilometer_v2.rb +1 -1
- data/lib/misty/openstack/api/ceilometer/v2.rb +19 -0
- data/lib/misty/openstack/{cinder → api/cinder}/cinder_v1.rb +1 -1
- data/lib/misty/openstack/{cinder → api/cinder}/cinder_v2.rb +3 -3
- data/lib/misty/openstack/{cinder → api/cinder}/cinder_v3.rb +7 -4
- data/lib/misty/openstack/api/cinder/v1.rb +23 -0
- data/lib/misty/openstack/api/cinder/v2.rb +24 -0
- data/lib/misty/openstack/api/cinder/v3.rb +29 -0
- data/lib/misty/openstack/{designate → api/designate}/designate_v2.rb +2 -2
- data/lib/misty/openstack/api/designate/v2.rb +19 -0
- data/lib/misty/openstack/{freezer → api/freezer}/freezer_v1.rb +2 -2
- data/lib/misty/openstack/api/freezer/v1.rb +19 -0
- data/lib/misty/openstack/{glance → api/glance}/glance_v1.rb +1 -1
- data/lib/misty/openstack/{glance → api/glance}/glance_v2.rb +1 -1
- data/lib/misty/openstack/api/glance/v1.rb +19 -0
- data/lib/misty/openstack/api/glance/v2.rb +24 -0
- data/lib/misty/openstack/api/gnocchi/gnocchi_v1.rb +39 -0
- data/lib/misty/openstack/api/gnocchi/v1.rb +19 -0
- data/lib/misty/openstack/{heat → api/heat}/heat_v1.rb +1 -1
- data/lib/misty/openstack/api/heat/v1.rb +23 -0
- data/lib/misty/openstack/{ironic → api/ironic}/ironic_v1.rb +8 -2
- data/lib/misty/openstack/api/ironic/v1.rb +25 -0
- data/lib/misty/openstack/{karbor → api/karbor}/karbor_v1.rb +2 -2
- data/lib/misty/openstack/api/karbor/v1.rb +19 -0
- data/lib/misty/openstack/{keystone → api/keystone}/keystone_v2_0.rb +1 -1
- data/lib/misty/openstack/api/keystone/keystone_v2_0_ext.rb +14 -0
- data/lib/misty/openstack/{keystone → api/keystone}/keystone_v3.rb +35 -3
- data/lib/misty/openstack/{keystone → api/keystone}/keystone_v3_ext.rb +7 -9
- data/lib/misty/openstack/api/keystone/v2_0.rb +23 -0
- data/lib/misty/openstack/api/keystone/v3.rb +23 -0
- data/lib/misty/openstack/{magnum → api/magnum}/magnum_v1.rb +2 -2
- data/lib/misty/openstack/api/magnum/v1.rb +21 -0
- data/lib/misty/openstack/{manila → api/manila}/manila_v2.rb +7 -3
- data/lib/misty/openstack/api/manila/v2.rb +25 -0
- data/lib/misty/openstack/api/masakari/masakari_v1_0.rb +22 -0
- data/lib/misty/openstack/api/masakari/v1_0.rb +19 -0
- data/lib/misty/openstack/api/mistral/mistral_v2.rb +44 -0
- data/lib/misty/openstack/api/mistral/v2.rb +19 -0
- data/lib/misty/openstack/api/monasca/monasca_v2_0.rb +28 -0
- data/lib/misty/openstack/api/monasca/v2_0.rb +19 -0
- data/lib/misty/openstack/{murano → api/murano}/murano_v1.rb +1 -1
- data/lib/misty/openstack/api/murano/v1.rb +19 -0
- data/lib/misty/openstack/{neutron → api/neutron}/neutron_v2_0.rb +11 -12
- data/lib/misty/openstack/api/neutron/v2_0.rb +19 -0
- data/lib/misty/openstack/{nova → api/nova}/nova_v2_1.rb +1 -2
- data/lib/misty/openstack/api/nova/v2_1.rb +33 -0
- data/lib/misty/openstack/{octavia → api/octavia}/octavia_v2_0.rb +4 -3
- data/lib/misty/openstack/api/octavia/v2_0.rb +19 -0
- data/lib/misty/openstack/api/panko/panko_v2.rb +14 -0
- data/lib/misty/openstack/api/panko/v2.rb +19 -0
- data/lib/misty/openstack/api/placement/placement_v2_1.rb +50 -0
- data/lib/misty/openstack/api/placement/v2_1.rb +21 -0
- data/lib/misty/openstack/{sahara → api/sahara}/sahara_v1_1.rb +2 -2
- data/lib/misty/openstack/api/sahara/v1_1.rb +19 -0
- data/lib/misty/openstack/{searchlight → api/searchlight}/searchlight_v1.rb +2 -2
- data/lib/misty/openstack/api/searchlight/v1.rb +19 -0
- data/lib/misty/openstack/{senlin → api/senlin}/senlin_v1.rb +2 -2
- data/lib/misty/openstack/api/senlin/v1.rb +19 -0
- data/lib/misty/openstack/{swift → api/swift}/swift_v1.rb +2 -2
- data/lib/misty/openstack/api/swift/v1.rb +34 -0
- data/lib/misty/openstack/{tacker → api/tacker}/tacker_v1_0.rb +2 -2
- data/lib/misty/openstack/api/tacker/v1_0.rb +19 -0
- data/lib/misty/openstack/{trove → api/trove}/trove_v1_0.rb +23 -8
- data/lib/misty/openstack/api/trove/v1_0.rb +19 -0
- data/lib/misty/openstack/api/watcher/v1.rb +19 -0
- data/lib/misty/openstack/api/watcher/watcher_v1.rb +38 -0
- data/lib/misty/openstack/api/zaqar/v2.rb +19 -0
- data/lib/misty/openstack/{zaqar → api/zaqar}/zaqar_v2.rb +2 -2
- data/lib/misty/openstack/api/zun/v1.rb +19 -0
- data/lib/misty/openstack/api/zun/zun_v1.rb +55 -0
- data/lib/misty/openstack/service.rb +18 -15
- data/lib/misty/openstack/service_pack.rb +18 -0
- data/lib/misty/service.rb +4 -6
- data/lib/misty/services.rb +11 -10
- data/lib/misty/version.rb +1 -1
- data/test/integration/compute_test.rb +2 -2
- data/test/integration/{networking_test.rb → network_test.rb} +10 -10
- data/test/integration/orchestration_test.rb +4 -4
- data/test/integration/vcr/{networking_using_neutron_v2_0.yml → network_using_neutron_v2_0.yml} +0 -0
- data/test/unit/auth/catalog_test.rb +99 -0
- data/test/unit/{auth_test.rb → auth/token_test.rb} +79 -45
- data/test/unit/cloud/config_test.rb +79 -41
- data/test/unit/cloud/requests_test.rb +6 -6
- data/test/unit/cloud/services_test.rb +23 -23
- data/test/unit/cloud_test.rb +10 -10
- data/test/unit/http/method_builder_test.rb +13 -23
- data/test/unit/http/request_test.rb +1 -1
- data/test/unit/microversion_test.rb +13 -16
- data/test/unit/misty_test.rb +51 -49
- data/test/unit/openstack/APIs_test.rb +5 -9
- data/test/unit/openstack/extension_test.rb +6 -6
- data/test/unit/openstack/service_test.rb +2 -10
- data/test/unit/service_helper.rb +3 -8
- data/test/unit/services_test.rb +5 -5
- metadata +91 -66
- data/lib/misty/auth.rb +0 -91
- data/lib/misty/auth/auth_v2.rb +0 -65
- data/lib/misty/auth/auth_v3.rb +0 -89
- data/lib/misty/autoload.rb +0 -99
- data/lib/misty/client_pack.rb +0 -16
- data/lib/misty/openstack/aodh/v2.rb +0 -17
- data/lib/misty/openstack/ceilometer/v2.rb +0 -17
- data/lib/misty/openstack/cinder/v1.rb +0 -21
- data/lib/misty/openstack/cinder/v2.rb +0 -22
- data/lib/misty/openstack/cinder/v3.rb +0 -31
- data/lib/misty/openstack/designate/v2.rb +0 -17
- data/lib/misty/openstack/freezer/v1.rb +0 -17
- data/lib/misty/openstack/glance/v1.rb +0 -17
- data/lib/misty/openstack/glance/v2.rb +0 -17
- data/lib/misty/openstack/heat/v1.rb +0 -21
- data/lib/misty/openstack/ironic/v1.rb +0 -27
- data/lib/misty/openstack/karbor/v1.rb +0 -17
- data/lib/misty/openstack/keystone/keystone_v2_0_ext.rb +0 -18
- data/lib/misty/openstack/keystone/v2_0.rb +0 -21
- data/lib/misty/openstack/keystone/v3.rb +0 -21
- data/lib/misty/openstack/magnum/v1.rb +0 -23
- data/lib/misty/openstack/manila/v2.rb +0 -27
- data/lib/misty/openstack/murano/v1.rb +0 -17
- data/lib/misty/openstack/neutron/v2_0.rb +0 -17
- data/lib/misty/openstack/nova/v2_1.rb +0 -42
- data/lib/misty/openstack/octavia/v2_0.rb +0 -17
- data/lib/misty/openstack/sahara/v1_1.rb +0 -17
- data/lib/misty/openstack/searchlight/v1.rb +0 -17
- data/lib/misty/openstack/senlin/v1.rb +0 -17
- data/lib/misty/openstack/swift/v1.rb +0 -32
- data/lib/misty/openstack/tacker/v1_0.rb +0 -17
- data/lib/misty/openstack/trove/v1_0.rb +0 -17
- data/lib/misty/openstack/zaqar/v2.rb +0 -17
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'misty/http/net_http'
|
2
|
+
module Misty
|
3
|
+
module Auth
|
4
|
+
module Token
|
5
|
+
include Misty::HTTP::NetHTTP
|
6
|
+
attr_reader :catalog, :token
|
7
|
+
|
8
|
+
# Default Domain ID
|
9
|
+
DOMAIN_ID = 'default'
|
10
|
+
|
11
|
+
def self.build(auth)
|
12
|
+
if auth[:tenant_id] || auth[:tenant]
|
13
|
+
Misty::Auth::Token::V2.new(auth)
|
14
|
+
else
|
15
|
+
Misty::Auth::Token::V3.new(auth)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(auth)
|
20
|
+
@log = auth[:log]
|
21
|
+
|
22
|
+
if auth[:context] && auth[:context][:token] && auth[:context][:expires] && auth[:context][:catalog]
|
23
|
+
# Bypass authentication
|
24
|
+
@catalog = Misty::Auth::Catalog.new(auth[:context][:catalog])
|
25
|
+
@expires = auth[:context][:expires]
|
26
|
+
@token = auth[:context][:token]
|
27
|
+
else
|
28
|
+
raise URLError, 'No URL provided' if auth[:url].nil? || auth[:url].empty?
|
29
|
+
@creds = {
|
30
|
+
:data => set_credentials(auth),
|
31
|
+
:ssl_verify_mode => auth[:ssl_verify_mode].nil? ? Misty::Config::SSL_VERIFY_MODE : auth[:ssl_verify_mode],
|
32
|
+
:uri => URI.parse(auth[:url])
|
33
|
+
}
|
34
|
+
set(authenticate(@creds))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def get
|
39
|
+
set(authenticate(@creds)) if expired?
|
40
|
+
@token
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def authenticate(creds)
|
46
|
+
Misty::HTTP::NetHTTP.http_request(
|
47
|
+
creds[:uri], ssl_verify_mode: creds[:ssl_verify_mode], log: @log
|
48
|
+
) do |connection|
|
49
|
+
response = connection.post(path, creds[:data].to_json,
|
50
|
+
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
|
51
|
+
unless response.code =~ /200|201/
|
52
|
+
raise AuthenticationError, "Response code=#{response.code}, Msg=#{response.msg}"
|
53
|
+
end
|
54
|
+
response
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def expired?
|
59
|
+
if @expires.nil? || @expires.empty?
|
60
|
+
raise ExpiryError, 'Missing token expiration data'
|
61
|
+
end
|
62
|
+
Time.parse(@expires) < Time.now.utc
|
63
|
+
end
|
64
|
+
|
65
|
+
def refresh
|
66
|
+
raise StandardError, "__method__ not implemented yet!"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'misty/auth/token'
|
2
|
+
require 'misty/auth/name'
|
3
|
+
|
4
|
+
module Misty
|
5
|
+
module Auth
|
6
|
+
module Token
|
7
|
+
class V2
|
8
|
+
include Misty::Auth::Token
|
9
|
+
|
10
|
+
def credentials
|
11
|
+
if @token
|
12
|
+
identity = { 'token': { 'id': @token } }
|
13
|
+
else
|
14
|
+
raise CredentialsError, "#{self.class}: User name is required" if @user.name.nil?
|
15
|
+
raise CredentialsError, "#{self.class}: User password is required" if @user.password.nil?
|
16
|
+
identity = { 'passwordCredentials': user_credentials }
|
17
|
+
end
|
18
|
+
|
19
|
+
if @tenant.id
|
20
|
+
identity.merge!('tenantId': @tenant.id)
|
21
|
+
elsif @tenant.name
|
22
|
+
identity.merge!('tenantName': @tenant.name)
|
23
|
+
else
|
24
|
+
raise CredentialsError, "#{self.class}: No tenant available"
|
25
|
+
end
|
26
|
+
|
27
|
+
{ 'auth': identity }
|
28
|
+
end
|
29
|
+
|
30
|
+
def path
|
31
|
+
'/v2.0/tokens'
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_credentials
|
35
|
+
{
|
36
|
+
'username': @user.name,
|
37
|
+
'password': @user.password
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def set(response)
|
42
|
+
payload = JSON.load(response.body)
|
43
|
+
@token = payload['access']['token']['id']
|
44
|
+
@expires = payload['access']['token']['expires']
|
45
|
+
catalog = payload['access']['serviceCatalog']
|
46
|
+
@catalog = Misty::Auth::Catalog::V2.new(catalog)
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_credentials(auth)
|
50
|
+
if auth[:token]
|
51
|
+
@token = auth[:token]
|
52
|
+
else
|
53
|
+
@user = Misty::Auth::User.new(auth[:user_id], auth[:user])
|
54
|
+
@user.password = auth[:password]
|
55
|
+
end
|
56
|
+
|
57
|
+
@tenant = Misty::Auth::Name.new(auth[:tenant_id], auth[:tenant])
|
58
|
+
credentials
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'misty/auth/token'
|
2
|
+
require 'misty/auth/name'
|
3
|
+
|
4
|
+
module Misty
|
5
|
+
module Auth
|
6
|
+
module Token
|
7
|
+
class V3
|
8
|
+
include Misty::Auth::Token
|
9
|
+
|
10
|
+
def credentials
|
11
|
+
if @token
|
12
|
+
identity = {
|
13
|
+
'methods': ['token'],
|
14
|
+
'token': { 'id': @token }
|
15
|
+
}
|
16
|
+
else
|
17
|
+
identity = {
|
18
|
+
'methods': ['password'],
|
19
|
+
'password': @user.identity
|
20
|
+
}
|
21
|
+
end
|
22
|
+
{
|
23
|
+
'auth': {
|
24
|
+
'identity': identity,
|
25
|
+
'scope': scope
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def path
|
31
|
+
'/v3/auth/tokens'
|
32
|
+
end
|
33
|
+
|
34
|
+
def scope
|
35
|
+
return @project.identity if @project
|
36
|
+
return @domain.identity if @domain
|
37
|
+
raise DomainScopeError, "#{self.class}: No scope available"
|
38
|
+
end
|
39
|
+
|
40
|
+
def set(response)
|
41
|
+
payload = JSON.load(response.body)
|
42
|
+
@token = response['x-subject-token']
|
43
|
+
@expires = payload['token']['expires_at']
|
44
|
+
catalog = payload['token']['catalog']
|
45
|
+
@catalog = Misty::Auth::Catalog::V3.new(catalog)
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_credentials(auth)
|
49
|
+
if auth[:project_id] || auth[:project]
|
50
|
+
if auth[:project_domain_id].nil? && auth[:project_domain].nil?
|
51
|
+
project_domain_id = DOMAIN_ID
|
52
|
+
else
|
53
|
+
project_domain_id = auth[:project_domain_id] if auth[:project_domain_id]
|
54
|
+
project_domain = auth[:project_domain] if auth[:project_domain]
|
55
|
+
end
|
56
|
+
|
57
|
+
@project = Misty::Auth::ProjectScope.new(auth[:project_id], auth[:project])
|
58
|
+
@project.domain = Misty::Auth::Name.new(project_domain_id, auth[:project_domain])
|
59
|
+
else
|
60
|
+
# scope: domain
|
61
|
+
if auth[:domain_id] || auth[:domain]
|
62
|
+
@domain = Misty::Auth::DomainScope.new(auth[:domain_id], auth[:domain])
|
63
|
+
else
|
64
|
+
# Use default Domain
|
65
|
+
@domain = Misty::Auth::DomainScope.new(DOMAIN_ID, nil)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if auth[:token]
|
70
|
+
@token = auth[:token]
|
71
|
+
else
|
72
|
+
@user = Misty::Auth::User.new(auth[:user_id], auth[:user])
|
73
|
+
|
74
|
+
if auth[:user_domain_id].nil? && auth[:user_domain].nil?
|
75
|
+
user_domain_id = DOMAIN_ID
|
76
|
+
else
|
77
|
+
user_domain_id = auth[:user_domain_id] if auth[:user_domain_id]
|
78
|
+
user_domain = auth[:user_domain] if auth[:user_domain]
|
79
|
+
end
|
80
|
+
|
81
|
+
@user.domain = Misty::Auth::Name.new(user_domain_id, user_domain)
|
82
|
+
@user.password = auth[:password]
|
83
|
+
end
|
84
|
+
|
85
|
+
credentials
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/misty/cloud.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'misty/config'
|
2
|
-
require 'misty/auth/auth_v2'
|
3
|
-
require 'misty/auth/auth_v3'
|
4
2
|
require 'misty/http/header'
|
5
3
|
|
6
4
|
module Misty
|
@@ -22,10 +20,10 @@ module Misty
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def build_service(method)
|
25
|
-
service = Misty.services.find {|service| service.
|
23
|
+
service = Misty.services.find {|service| service.type == method}
|
26
24
|
service_config = @config.get_service(method)
|
27
|
-
|
28
|
-
klass = Object.const_get("Misty::Openstack::#{service.project.capitalize}::#{
|
25
|
+
api_version = self.class.dot_to_underscore(service.default_version(service_config[:config][:api_version]))
|
26
|
+
klass = Object.const_get("Misty::Openstack::API::#{service.project.capitalize}::#{api_version.capitalize}")
|
29
27
|
klass.new(service_config)
|
30
28
|
end
|
31
29
|
|
@@ -77,6 +75,12 @@ module Misty
|
|
77
75
|
@container_infrastructure_management
|
78
76
|
end
|
79
77
|
|
78
|
+
def container_service(arg = {})
|
79
|
+
@container_service ||= build_service(__method__)
|
80
|
+
@container_service.request_config(args)
|
81
|
+
@container_service
|
82
|
+
end
|
83
|
+
|
80
84
|
def data_processing(arg = {})
|
81
85
|
@data_processing ||= build_service(__method__)
|
82
86
|
@data_processing.request_config(arg)
|
@@ -101,6 +105,12 @@ module Misty
|
|
101
105
|
@dns
|
102
106
|
end
|
103
107
|
|
108
|
+
def event(arg = {})
|
109
|
+
@event ||= build_service(__method__)
|
110
|
+
@event.request_config(args)
|
111
|
+
@event
|
112
|
+
end
|
113
|
+
|
104
114
|
def identity(arg = {})
|
105
115
|
@identity ||= build_service(__method__)
|
106
116
|
@identity.request_config(arg)
|
@@ -113,6 +123,18 @@ module Misty
|
|
113
123
|
@image
|
114
124
|
end
|
115
125
|
|
126
|
+
def instance_ha(arg = {})
|
127
|
+
@instance_ha ||= build_service(__method__)
|
128
|
+
@instance_ha.request_config(args)
|
129
|
+
@instance_ha
|
130
|
+
end
|
131
|
+
|
132
|
+
def key_manager(arg = {})
|
133
|
+
@key_manager ||= build_service(__method__)
|
134
|
+
@key_manager.request_config(args)
|
135
|
+
@key_manager
|
136
|
+
end
|
137
|
+
|
116
138
|
def load_balancer(arg = {})
|
117
139
|
@load_balancer ||= build_service(__method__)
|
118
140
|
@load_balancer.request_config(arg)
|
@@ -131,10 +153,22 @@ module Misty
|
|
131
153
|
@metering
|
132
154
|
end
|
133
155
|
|
134
|
-
def
|
135
|
-
@
|
136
|
-
@
|
137
|
-
@
|
156
|
+
def metric(arg = {})
|
157
|
+
@metric ||= build_service(__method__)
|
158
|
+
@metric.request_config(args)
|
159
|
+
@metric
|
160
|
+
end
|
161
|
+
|
162
|
+
def monitoring(arg = {})
|
163
|
+
@monitoring ||= build_service(__method__)
|
164
|
+
@monitoring.request_config(args)
|
165
|
+
@monitoring
|
166
|
+
end
|
167
|
+
|
168
|
+
def network(arg = {})
|
169
|
+
@network ||= build_service(__method__)
|
170
|
+
@network.request_config(arg)
|
171
|
+
@network
|
138
172
|
end
|
139
173
|
|
140
174
|
def nfv_orchestration(arg = {})
|
@@ -155,6 +189,24 @@ module Misty
|
|
155
189
|
@orchestration
|
156
190
|
end
|
157
191
|
|
192
|
+
def placement(arg = {})
|
193
|
+
@placement ||= build_service(__method__)
|
194
|
+
@placement.request_config(args)
|
195
|
+
@placement
|
196
|
+
end
|
197
|
+
|
198
|
+
def reservation(arg = {})
|
199
|
+
@reservation ||= build_service(__method__)
|
200
|
+
@reservation.request_config(args)
|
201
|
+
@reservation
|
202
|
+
end
|
203
|
+
|
204
|
+
def resource_optimization(arg = {})
|
205
|
+
@resource_optimization ||= build_service(__method__)
|
206
|
+
@resource_optimization.request_config(args)
|
207
|
+
@resource_optimization
|
208
|
+
end
|
209
|
+
|
158
210
|
def search(arg = {})
|
159
211
|
@search ||= build_service(__method__)
|
160
212
|
@search.request_config(arg)
|
@@ -167,26 +219,33 @@ module Misty
|
|
167
219
|
@shared_file_systems
|
168
220
|
end
|
169
221
|
|
222
|
+
def workflow(arg = {})
|
223
|
+
@workflow ||= build_service(__method__)
|
224
|
+
@workflow.request_config(args)
|
225
|
+
@workflow
|
226
|
+
end
|
227
|
+
|
170
228
|
alias domain_name_server dns
|
171
229
|
alias volume block_storage
|
172
230
|
|
173
231
|
private
|
174
232
|
|
175
|
-
def method_missing(method_name
|
233
|
+
def method_missing(method_name, arg = {})
|
176
234
|
services_avail = []
|
177
|
-
Misty.services.
|
178
|
-
services_avail <<
|
235
|
+
Misty.services.types.each do |serv|
|
236
|
+
services_avail << serv if /^#{method_name}/.match(serv)
|
179
237
|
end
|
180
238
|
|
181
239
|
if services_avail.size == 1
|
182
|
-
|
183
|
-
self.
|
184
|
-
return self.instance_variable_get("@#{services_avail[0]}")
|
240
|
+
type = services_avail[0]
|
241
|
+
raise NoMethodError, "No such Cloud Service: #{method_name}" unless self.class.method_defined?(type)
|
185
242
|
elsif services_avail.size > 1
|
186
243
|
raise NoMethodError, "Ambiguous Cloud Service: #{method_name}"
|
187
244
|
else
|
188
245
|
raise NoMethodError, "No such Cloud Service: #{method_name}"
|
189
246
|
end
|
247
|
+
|
248
|
+
send(type, arg)
|
190
249
|
end
|
191
250
|
end
|
192
251
|
end
|
data/lib/misty/config.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
|
-
require 'misty/auth/
|
3
|
-
require 'misty/auth/auth_v3'
|
4
|
-
require 'misty/http/header'
|
2
|
+
require 'misty/auth/token'
|
5
3
|
|
6
4
|
module Misty
|
7
5
|
class Config
|
@@ -15,7 +13,7 @@ module Misty
|
|
15
13
|
INTERFACE = 'public'
|
16
14
|
|
17
15
|
# Valid endpoint interfaces
|
18
|
-
INTERFACES = %w
|
16
|
+
INTERFACES = %w(admin public internal)
|
19
17
|
|
20
18
|
# Default Log file
|
21
19
|
LOG_FILE = '/dev/null'
|
@@ -24,34 +22,25 @@ module Misty
|
|
24
22
|
LOG_LEVEL = Logger::INFO
|
25
23
|
|
26
24
|
# Default Region
|
27
|
-
|
25
|
+
REGION = 'regionOne'
|
28
26
|
|
29
27
|
# Default when uri.scheme is https
|
30
28
|
SSL_VERIFY_MODE = true
|
31
29
|
|
32
|
-
|
33
|
-
#
|
34
|
-
# * +arg+ - +Hash+ of configuration options
|
35
|
-
|
36
|
-
attr_reader :auth, :log, :services
|
30
|
+
attr_reader :catalog, :token, :log, :services
|
37
31
|
|
38
32
|
def initialize(arg)
|
39
33
|
raise CredentialsError if arg.nil? || arg.empty? || arg[:auth].nil? || arg[:auth].empty?
|
40
|
-
@auth = Misty::Auth.build(arg[:auth]) # TODO: pass @log
|
41
34
|
@log = set_log(arg[:log_file], arg[:log_level])
|
42
35
|
@globals = set_config(arg)
|
43
|
-
@services =
|
44
|
-
|
45
|
-
|
46
|
-
Misty::SERVICES.each do |serv|
|
47
|
-
@services[e] = k if serv[:name] == e
|
48
|
-
end
|
49
|
-
end
|
36
|
+
@services = set_services(arg)
|
37
|
+
arg[:log] = @log
|
38
|
+
@token = Misty::Auth::Token.build(arg[:auth])
|
50
39
|
end
|
51
40
|
|
52
41
|
def get_service(method)
|
53
42
|
set = {}
|
54
|
-
set[:
|
43
|
+
set[:token] = @token
|
55
44
|
set[:log] = @log
|
56
45
|
service_config = @services.key?(method) ? @services[method] : {}
|
57
46
|
if service_config
|
@@ -65,54 +54,51 @@ module Misty
|
|
65
54
|
|
66
55
|
def set_service(arg)
|
67
56
|
set = {}
|
68
|
-
set[:base_path] = arg[:base_path] ? arg[:base_path] : nil
|
69
|
-
set[:base_url] = arg[:base_url] ? arg[:base_url] : nil
|
70
|
-
set[:version] = arg[:version] ? arg[:version] : nil
|
71
57
|
set[:api_version] = arg[:api_version] ? arg[:api_version] : nil
|
58
|
+
set[:base_path] = arg[:base_path] ? arg[:base_path].chomp('/') : nil
|
59
|
+
set[:endpoint] = arg[:endpoint] ? arg[:endpoint] : nil
|
60
|
+
set[:service_name] = arg[:service_name] ? arg[:service_name] : nil
|
61
|
+
set[:version] = arg[:version] ? arg[:version] : nil
|
72
62
|
set
|
73
63
|
end
|
74
64
|
|
75
65
|
private
|
76
66
|
|
77
|
-
def get_defaults
|
78
|
-
set = {}
|
79
|
-
set[:content_type] = CONTENT_TYPE
|
80
|
-
set[:headers] = HTTP::Header.new('Accept' => 'application/json; q=1.0')
|
81
|
-
set[:interface] = INTERFACE
|
82
|
-
set[:region_id] = REGION_ID
|
83
|
-
set[:ssl_verify_mode] = SSL_VERIFY_MODE
|
84
|
-
set
|
85
|
-
end
|
86
|
-
|
87
67
|
def set_config(arg = {}, defaults = get_defaults)
|
88
68
|
set = {}
|
89
69
|
set[:content_type] = set_content_type(arg[:content_type], defaults[:content_type])
|
90
70
|
set[:headers] = set_headers(arg[:headers], defaults[:headers])
|
91
71
|
set[:interface] = set_interface(arg[:interface], defaults[:interface])
|
92
|
-
set[:
|
72
|
+
set[:region] = set_region(arg[:region], defaults[:region])
|
93
73
|
set[:ssl_verify_mode] = set_ssl_verify_mode(arg[:ssl_verify_mode], defaults[:ssl_verify_mode])
|
94
74
|
set
|
95
75
|
end
|
96
76
|
|
97
|
-
|
98
77
|
def set_content_type(val, default)
|
99
78
|
res = val.nil? ? default : val
|
100
79
|
raise InvalidDataError, "Config ':content_type' must be one of #{CONTENT_TYPES}" unless CONTENT_TYPES.include?(res)
|
101
80
|
res
|
102
81
|
end
|
103
82
|
|
83
|
+
def get_defaults
|
84
|
+
set = {}
|
85
|
+
set[:content_type] = CONTENT_TYPE
|
86
|
+
set[:headers] = HTTP::Header.new('Accept' => 'application/json; q=1.0')
|
87
|
+
set[:interface] = INTERFACE
|
88
|
+
set[:region] = REGION
|
89
|
+
set[:ssl_verify_mode] = SSL_VERIFY_MODE
|
90
|
+
set
|
91
|
+
end
|
92
|
+
|
104
93
|
def set_headers(val, default)
|
105
|
-
res =
|
106
|
-
|
107
|
-
|
108
|
-
else default
|
109
|
-
default
|
110
|
-
end
|
94
|
+
res = HTTP::Header.new
|
95
|
+
res.add(default.get)
|
96
|
+
res.add(val) if !val.nil? && !val.empty?
|
111
97
|
res
|
112
98
|
end
|
113
99
|
|
114
100
|
def set_interface(val, default)
|
115
|
-
|
101
|
+
res = val.nil? ? default : val
|
116
102
|
raise InvalidDataError, "Config ':interface' must be one of #{INTERFACES}" unless INTERFACES.include?(res)
|
117
103
|
res
|
118
104
|
end
|
@@ -123,12 +109,20 @@ module Misty
|
|
123
109
|
log
|
124
110
|
end
|
125
111
|
|
126
|
-
def
|
112
|
+
def set_region(val, default)
|
127
113
|
res = val.nil? ? default : val
|
128
|
-
raise InvalidDataError, "Config ':
|
114
|
+
raise InvalidDataError, "Config ':region' must be a String" unless res.kind_of? String
|
129
115
|
res
|
130
116
|
end
|
131
117
|
|
118
|
+
def set_services(arg)
|
119
|
+
set = {}
|
120
|
+
arg.each do |e, k|
|
121
|
+
set[e] = k if Misty.services.find {|s| s.type == e}
|
122
|
+
end
|
123
|
+
set
|
124
|
+
end
|
125
|
+
|
132
126
|
def set_ssl_verify_mode(val, default)
|
133
127
|
res = val.nil? ? default : val
|
134
128
|
raise InvalidDataError, "Config ':ssl_verify_mode' must be a Boolean" unless res == !!res
|