misty 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +39 -23
- data/lib/misty/cloud.rb +22 -17
- data/lib/misty/http/client.rb +9 -9
- data/lib/misty/http/request.rb +9 -9
- data/lib/misty/misty.rb +14 -0
- data/lib/misty/version.rb +1 -1
- data/test/unit/cloud_test.rb +14 -0
- data/test/unit/openstack/microversion_test.rb +2 -2
- data/test/unit/service_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83575874d30a942a02efcc8c425c0b866a5785c0
|
4
|
+
data.tar.gz: 0f1e48ace0eb01ddce6b877fe6ffb8b1b7ab27dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62ba32820ad2cb2614041f8fb7db9dc024ec85bd3508cb8eb3d6796efeb02f8f7d4e5a8235a625bb9ea10368327514c63a5ec904f7318e95a328f5907219f531
|
7
|
+
data.tar.gz: 8af6446a5b734974dbda856e54c629594e2192585e139e1aad9ce92fa64b70724fe19934245bf135bcbf7dc40a338b2858b7af1e0b0f2aed83ea8f87aded20f8
|
data/README.md
CHANGED
@@ -119,7 +119,7 @@ openstack.compute.requests
|
|
119
119
|
|
120
120
|
## Setup
|
121
121
|
|
122
|
-
### Authentication
|
122
|
+
### Authentication information parameter
|
123
123
|
The URL and credentials details are necessary to authenticate with the identity server (Keystone).
|
124
124
|
|
125
125
|
To provide a Keystone V3, which is the default recommended version:
|
@@ -142,14 +142,7 @@ auth = {
|
|
142
142
|
:tenant => "admin",
|
143
143
|
}
|
144
144
|
```
|
145
|
-
|
146
|
-
### Global options
|
147
|
-
Besides the authentication details, the following options which apply for the whole cloud
|
148
|
-
|
149
|
-
* :content_type
|
150
|
-
Format of the body of the successful HTTP responses to be JSON or Ruby structures.
|
151
|
-
Value is symbol. Allowed value is `:json`.
|
152
|
-
By default response body are converted to Ruby structures.
|
145
|
+
### Logging parameters
|
153
146
|
* :log_file
|
154
147
|
File name and path for log file.
|
155
148
|
Value is file path or IO object - Default is `./misty.log`.
|
@@ -161,8 +154,28 @@ Besides the authentication details, the following options which apply for the wh
|
|
161
154
|
openstack = Misty::Cloud.new(:auth => auth, :content_type => :ruby, :log_file => STDOUT)
|
162
155
|
```
|
163
156
|
|
157
|
+
#### Global parameters
|
158
|
+
The following options are applied to each service unless specifically provided for a service.
|
159
|
+
|
160
|
+
* :region_id
|
161
|
+
Type: String
|
162
|
+
Default: "regionOne"
|
163
|
+
* :interface
|
164
|
+
Type: String
|
165
|
+
Allowed values: "public", "internal", "admin"
|
166
|
+
Default: "public"
|
167
|
+
* :ssl_verify_mode
|
168
|
+
When using SSL mode (defined by URI scheme => "https://")
|
169
|
+
Type: Boolean
|
170
|
+
Default: `true`
|
171
|
+
* :content_type
|
172
|
+
Format of the body of the successful HTTP responses to be JSON or Ruby structures.
|
173
|
+
Type: Symbol
|
174
|
+
Allowed values: `:json`, `:ruby`
|
175
|
+
Default: `:ruby`
|
176
|
+
|
164
177
|
### Services Options
|
165
|
-
Each service can get
|
178
|
+
Each service can get parameters to be specified.
|
166
179
|
|
167
180
|
```ruby
|
168
181
|
openstack = Misty::Cloud.new(:auth => auth, :identity => {}, :compute => {})
|
@@ -170,30 +183,33 @@ openstack = Misty::Cloud.new(:auth => auth, :identity => {}, :compute => {})
|
|
170
183
|
|
171
184
|
The following options are available:
|
172
185
|
* :api_version
|
173
|
-
|
174
|
-
|
186
|
+
Type: String
|
187
|
+
Default: The latest supported version - See Misty.services for other versions.
|
175
188
|
* :base_path
|
176
189
|
Allows to force the base path for every URL requests.
|
177
|
-
|
190
|
+
Type: String
|
178
191
|
* :base_url
|
179
192
|
Allows to force the base URL for every requests.
|
180
|
-
|
193
|
+
Type: String
|
181
194
|
* :interface
|
182
195
|
Allows to provide an alternate interface. Allowed values are "public", "internal" or "admin"
|
183
|
-
|
196
|
+
Type: String
|
197
|
+
Default: Determined from global value
|
184
198
|
* :region_id
|
185
|
-
|
186
|
-
Default
|
199
|
+
Type: String
|
200
|
+
Default: Determined from global value
|
187
201
|
* :service_names
|
188
|
-
|
189
|
-
|
202
|
+
Allows to use a difference name for the service. For instance "identity3" for the identity service.
|
203
|
+
Type: String
|
204
|
+
Default: Determined from Misty.services
|
190
205
|
* :ssl_verify_mode
|
191
|
-
|
192
|
-
|
206
|
+
Type: Boolean
|
207
|
+
Default: Determined from global value
|
193
208
|
* :version
|
194
209
|
Version to be used when microversion is supported by the service.
|
195
|
-
|
196
|
-
Allowed values
|
210
|
+
Type: String
|
211
|
+
Allowed values: "CURRENT", "LATEST", "SUPPORTED", or a version number such as "2.0" or "3"
|
212
|
+
Default: `"CURRENT"`
|
197
213
|
|
198
214
|
Example:
|
199
215
|
```ruby
|
data/lib/misty/cloud.rb
CHANGED
@@ -3,7 +3,7 @@ require 'misty/auth/auth_v3'
|
|
3
3
|
|
4
4
|
module Misty
|
5
5
|
class Cloud
|
6
|
-
Setup = Struct.new(:auth, :content_type, :log)
|
6
|
+
Setup = Struct.new(:auth, :content_type, :log, :interface, :region_id, :ssl_verify_mode)
|
7
7
|
|
8
8
|
Options = Struct.new(:alarming, :baremetal, :block_storage, :clustering, :compute, :container, :data_processing,
|
9
9
|
:database, :data_protection, :dns, :identity, :image, :messaging, :metering, :network, :object_storage,
|
@@ -11,27 +11,32 @@ module Misty
|
|
11
11
|
|
12
12
|
attr_reader :services
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@
|
16
|
-
@cloud.auth = Misty::Auth.factory(options[:auth])
|
17
|
-
@cloud.content_type = options[:content_type] ? options[:content_type] : nil
|
18
|
-
@cloud.log = Logger.new(options[:log_file] ? options[:log_file] : Misty::LOG_FILE)
|
19
|
-
@cloud.log.level = options[:log_level] ? options[:log_level] : Misty::LOG_LEVEL
|
20
|
-
|
14
|
+
def initialize(params = {:auth => {}})
|
15
|
+
@setup = self.class.setup(params)
|
21
16
|
@options = Options.new
|
22
|
-
|
23
|
-
|
24
|
-
end
|
17
|
+
@services = setup_services(params)
|
18
|
+
end
|
25
19
|
|
26
|
-
|
20
|
+
def self.setup(params)
|
21
|
+
setup = Setup.new
|
22
|
+
setup.auth = Misty::Auth.factory(params[:auth])
|
23
|
+
setup.content_type = params[:content_type] ? params[:content_type] : Misty::CONTENT_TYPE
|
24
|
+
setup.interface = params[:interface] ? params[:interface] : Misty::INTERFACE
|
25
|
+
setup.log = Logger.new(params[:log_file] ? params[:log_file] : Misty::LOG_FILE)
|
26
|
+
setup.log.level = params[:log_level] ? params[:log_level] : Misty::LOG_LEVEL
|
27
|
+
setup.region_id = params[:region_id] ? params[:region_id] : Misty::REGION_ID
|
28
|
+
setup.ssl_verify_mode = params[:ssl_verify_mode] ? params[:ssl_verify_mode] : Misty::SSL_VERIFY_MODE
|
29
|
+
setup
|
27
30
|
end
|
28
31
|
|
29
|
-
def setup_services(
|
32
|
+
def setup_services(params)
|
30
33
|
services = {}
|
31
34
|
Misty.services.each do |service|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
@options.send("#{service.name}=".to_sym, params[service.name] ? params[service.name] : {})
|
36
|
+
|
37
|
+
if params[service.name] && params[service.name][:api_version] \
|
38
|
+
&& service.versions.include?(params[service.name][:api_version])
|
39
|
+
services.merge!(service.name => {service.project => params[service.name][:api_version]})
|
35
40
|
else
|
36
41
|
# Highest version is used by default!
|
37
42
|
services.merge!(service.name => {service.project => service.versions.sort[-1]})
|
@@ -45,7 +50,7 @@ module Misty
|
|
45
50
|
version = @services[service_name].fetch(project)
|
46
51
|
version = self.class.dot_to_underscore(version)
|
47
52
|
klass = Object.const_get("Misty::Openstack::#{project.capitalize}::#{version.capitalize}")
|
48
|
-
klass.new(@
|
53
|
+
klass.new(@setup, @options[service_name])
|
49
54
|
end
|
50
55
|
|
51
56
|
def self.dot_to_underscore(val)
|
data/lib/misty/http/client.rb
CHANGED
@@ -43,10 +43,10 @@ module Misty
|
|
43
43
|
# :ssl_verify_mode => true
|
44
44
|
# (micro)version: Can be numbered (3.1) or by state (CURRENT, LATEST or SUPPORTED)
|
45
45
|
# :version => "CURRENT"
|
46
|
-
def initialize(
|
47
|
-
@
|
46
|
+
def initialize(setup, options)
|
47
|
+
@setup = setup
|
48
48
|
@options = setup(options)
|
49
|
-
@uri = URI.parse(@
|
49
|
+
@uri = URI.parse(@setup.auth.get_endpoint(@options.service_names, @options.region_id, @options.interface))
|
50
50
|
@base_path = @options.base_path ? @options.base_path : @uri.path
|
51
51
|
@base_path = @base_path.chomp("/")
|
52
52
|
@http = net_http(@uri)
|
@@ -70,7 +70,7 @@ module Misty
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def headers
|
73
|
-
h = headers_default.merge("X-Auth-Token" => "#{@
|
73
|
+
h = headers_default.merge("X-Auth-Token" => "#{@setup.auth.get_token}")
|
74
74
|
h.merge!(microversion_header) if microversion
|
75
75
|
h
|
76
76
|
end
|
@@ -83,7 +83,7 @@ module Misty
|
|
83
83
|
|
84
84
|
def net_http(uri)
|
85
85
|
http = Net::HTTP.new(uri.host, uri.port)
|
86
|
-
http.set_debug_output($stdout) if @
|
86
|
+
http.set_debug_output($stdout) if @setup.log.level == Logger::DEBUG
|
87
87
|
if uri.scheme == "https"
|
88
88
|
http.use_ssl = true
|
89
89
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @options[:ssl_verify_mode]
|
@@ -95,14 +95,14 @@ module Misty
|
|
95
95
|
options = Options.new()
|
96
96
|
options.base_path = params[:base_path] ? params[:base_path] : nil
|
97
97
|
options.base_url = params[:base_url] ? params[:base_url] : nil
|
98
|
-
options.interface = params[:interface] ? params[:interface] :
|
99
|
-
options.region_id = params[:region_id] ? params[:region_id] :
|
98
|
+
options.interface = params[:interface] ? params[:interface] : @setup.interface
|
99
|
+
options.region_id = params[:region_id] ? params[:region_id] : @setup.region_id
|
100
100
|
options.service_names = params[:service_name] ? self.class.service_names << params[:service_name] : self.class.service_names
|
101
|
-
options.ssl_verify_mode = params[:ssl_verify_mode] ? params[:ssl_verify_mode] :
|
101
|
+
options.ssl_verify_mode = params[:ssl_verify_mode] ? params[:ssl_verify_mode] : @setup.ssl_verify_mode
|
102
102
|
options.version = params[:version] ? params[:version] : "CURRENT"
|
103
103
|
|
104
104
|
unless INTERFACES.include?(options.interface)
|
105
|
-
raise InvalidDataError, "Options ':interface'must be one of #{INTERFACES}"
|
105
|
+
raise InvalidDataError, "Options ':interface' must be one of #{INTERFACES}"
|
106
106
|
end
|
107
107
|
|
108
108
|
unless options.ssl_verify_mode == !!options.ssl_verify_mode
|
data/lib/misty/http/request.rb
CHANGED
@@ -2,7 +2,7 @@ module Misty
|
|
2
2
|
module HTTP
|
3
3
|
module Request
|
4
4
|
def decode?(response)
|
5
|
-
if @
|
5
|
+
if @setup.content_type != :json && response.code =~ /2??/ && !response.is_a?(Net::HTTPNoContent) \
|
6
6
|
&& !response.is_a?(Net::HTTPResetContent) && response.header["content-type"] \
|
7
7
|
&& response.header["content-type"].include?("application/json")
|
8
8
|
true
|
@@ -16,51 +16,51 @@ module Misty
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def http_delete(path, headers)
|
19
|
-
@
|
19
|
+
@setup.log.info(http_to_s(path, headers))
|
20
20
|
request = Net::HTTP::Delete.new(path, headers)
|
21
21
|
http(request)
|
22
22
|
end
|
23
23
|
|
24
24
|
def http_copy(path, headers)
|
25
|
-
@
|
25
|
+
@setup.log.info(http_to_s(path, headers))
|
26
26
|
request = Net::HTTP::Copy.new(path, headers)
|
27
27
|
http(request)
|
28
28
|
end
|
29
29
|
|
30
30
|
def http_get(path, headers)
|
31
|
-
@
|
31
|
+
@setup.log.info(http_to_s(path, headers))
|
32
32
|
request = Net::HTTP::Get.new(path, headers)
|
33
33
|
http(request)
|
34
34
|
end
|
35
35
|
|
36
36
|
def http_head(path, headers)
|
37
|
-
@
|
37
|
+
@setup.log.info(http_to_s(path, headers))
|
38
38
|
request = Net::HTTP::Head.new(path, headers)
|
39
39
|
http(request)
|
40
40
|
end
|
41
41
|
|
42
42
|
def http_options(path, headers)
|
43
|
-
@
|
43
|
+
@setup.log.info(http_to_s(path, headers))
|
44
44
|
request = Net::HTTP::Options.new(path, headers)
|
45
45
|
http(request)
|
46
46
|
end
|
47
47
|
|
48
48
|
def http_patch(path, headers, data)
|
49
|
-
@
|
49
|
+
@setup.log.info(http_to_s(path, headers, data))
|
50
50
|
request = Net::HTTP::Patch.new(path, headers)
|
51
51
|
request.body = Misty.to_json(data)
|
52
52
|
http(request)
|
53
53
|
end
|
54
54
|
|
55
55
|
def http_post(path, headers, data)
|
56
|
-
@
|
56
|
+
@setup.log.info(http_to_s(path, headers, data))
|
57
57
|
request = Net::HTTP::Post.new(path, headers)
|
58
58
|
request.body = Misty.to_json(data)
|
59
59
|
http(request)
|
60
60
|
end
|
61
61
|
|
62
62
|
def http_put(path, headers, data)
|
63
|
-
@
|
63
|
+
@setup.log.info(http_to_s(path, headers, data))
|
64
64
|
request = Net::HTTP::Put.new(path, headers)
|
65
65
|
request.body = Misty.to_json(data)
|
66
66
|
http(request)
|
data/lib/misty/misty.rb
CHANGED
@@ -9,6 +9,20 @@ module Misty
|
|
9
9
|
# Default log level. Use :log_level option to override
|
10
10
|
LOG_LEVEL = Logger::INFO
|
11
11
|
|
12
|
+
# Default content type for REST responses
|
13
|
+
# JSON format: :json
|
14
|
+
# Ruby structures: :ruby
|
15
|
+
CONTENT_TYPE = :ruby
|
16
|
+
|
17
|
+
# Default Interface
|
18
|
+
INTERFACE = "public"
|
19
|
+
|
20
|
+
# Default Region ID
|
21
|
+
REGION_ID = "regionOne"
|
22
|
+
|
23
|
+
# Default mode when SSL is used (uri.scheme == "https")
|
24
|
+
SSL_VERIFY_MODE = true
|
25
|
+
|
12
26
|
Service = Struct.new(:name, :project, :versions) do
|
13
27
|
def to_s
|
14
28
|
"#{name}: #{project} => #{versions}"
|
data/lib/misty/version.rb
CHANGED
data/test/unit/cloud_test.rb
CHANGED
@@ -51,6 +51,20 @@ describe Misty::Cloud do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
describe "#setup" do
|
55
|
+
it "sets up default values" do
|
56
|
+
Misty::Auth.stub :factory, nil do
|
57
|
+
setup = Misty::Cloud.setup({})
|
58
|
+
setup.must_be_kind_of Struct
|
59
|
+
setup.content_type.must_equal Misty::CONTENT_TYPE
|
60
|
+
setup.log.must_be_kind_of Logger
|
61
|
+
setup.interface.must_equal Misty::INTERFACE
|
62
|
+
setup.region_id.must_equal Misty::REGION_ID
|
63
|
+
setup.ssl_verify_mode.must_equal Misty::SSL_VERIFY_MODE
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
54
68
|
describe "#new" do
|
55
69
|
describe "fails" do
|
56
70
|
it "when no credentials" do
|
@@ -31,13 +31,13 @@ describe Misty::HTTP::Microversion do
|
|
31
31
|
"token_id"
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
setup = Misty::Cloud::Setup.new(auth, :ruby, Logger.new('/dev/null'), Misty::INTERFACE, Misty::REGION_ID, Misty::SSL_VERIFY_MODE)
|
35
35
|
|
36
36
|
stub_request(:get, "http://localhost/").
|
37
37
|
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}).
|
38
38
|
to_return(:status => 200, :body => JSON.dump(versions_data), :headers => {})
|
39
39
|
|
40
|
-
Misty::Openstack::Nova::V2_1.new(
|
40
|
+
Misty::Openstack::Nova::V2_1.new(setup, {})
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "#version_get" do
|
data/test/unit/service_helper.rb
CHANGED
@@ -15,7 +15,7 @@ def service(content_type = :ruby)
|
|
15
15
|
"token_id"
|
16
16
|
end
|
17
17
|
|
18
|
-
setup = Misty::Cloud::Setup.new(auth, content_type, Logger.new('/dev/null'))
|
18
|
+
setup = Misty::Cloud::Setup.new(auth, content_type, Logger.new('/dev/null'), Misty::INTERFACE, Misty::REGION_ID, Misty::SSL_VERIFY_MODE)
|
19
19
|
|
20
20
|
stub_request(:get, "http://localhost/").
|
21
21
|
with(:headers => request_header).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: misty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilles Dubreuil
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|