ovirt-engine-sdk 4.1.13 → 4.2.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.adoc +2 -96
- data/README.adoc +22 -74
- data/ext/ovirtsdk4c/ov_http_client.c +27 -140
- data/ext/ovirtsdk4c/ov_http_client.h +1 -6
- data/ext/ovirtsdk4c/ov_http_request.c +40 -79
- data/ext/ovirtsdk4c/ov_http_request.h +10 -11
- data/ext/ovirtsdk4c/ov_http_response.c +0 -14
- data/ext/ovirtsdk4c/ov_http_transfer.c +0 -11
- data/ext/ovirtsdk4c/ov_module.h +2 -2
- data/lib/ovirtsdk4/connection.rb +57 -122
- data/lib/ovirtsdk4/probe.rb +2 -55
- data/lib/ovirtsdk4/reader.rb +3 -3
- data/lib/ovirtsdk4/readers.rb +91 -206
- data/lib/ovirtsdk4/service.rb +31 -104
- data/lib/ovirtsdk4/services.rb +9612 -7822
- data/lib/ovirtsdk4/types.rb +225 -491
- data/lib/ovirtsdk4/version.rb +1 -1
- data/lib/ovirtsdk4/writers.rb +36 -73
- metadata +5 -5
@@ -28,12 +28,9 @@ extern VALUE ov_http_client_class;
|
|
28
28
|
|
29
29
|
/* Content: */
|
30
30
|
typedef struct {
|
31
|
-
/* The libcurl multi handle
|
31
|
+
/* The libcurl multi handle: */
|
32
32
|
CURLM* handle;
|
33
33
|
|
34
|
-
/* The libcurl share handle, used to share cookie data between multiple requests: */
|
35
|
-
CURLSH* share;
|
36
|
-
|
37
34
|
/* The logger: */
|
38
35
|
VALUE log;
|
39
36
|
|
@@ -54,8 +51,6 @@ typedef struct {
|
|
54
51
|
char* proxy_username;
|
55
52
|
char* proxy_password;
|
56
53
|
int timeout;
|
57
|
-
int connect_timeout;
|
58
|
-
char* cookies;
|
59
54
|
} ov_http_client_object;
|
60
55
|
|
61
56
|
/* Macro to get the pointer: */
|
@@ -40,7 +40,6 @@ static VALUE TOKEN_SYMBOL;
|
|
40
40
|
static VALUE KERBEROS_SYMBOL;
|
41
41
|
static VALUE BODY_SYMBOL;
|
42
42
|
static VALUE TIMEOUT_SYMBOL;
|
43
|
-
static VALUE CONNECT_TIMEOUT_SYMBOL;
|
44
43
|
|
45
44
|
static void ov_http_request_mark(void* vptr) {
|
46
45
|
ov_http_request_object* ptr;
|
@@ -56,7 +55,6 @@ static void ov_http_request_mark(void* vptr) {
|
|
56
55
|
rb_gc_mark(ptr->kerberos);
|
57
56
|
rb_gc_mark(ptr->body);
|
58
57
|
rb_gc_mark(ptr->timeout);
|
59
|
-
rb_gc_mark(ptr->connect_timeout);
|
60
58
|
}
|
61
59
|
|
62
60
|
static void ov_http_request_free(void* vptr) {
|
@@ -85,17 +83,16 @@ static VALUE ov_http_request_alloc(VALUE klass) {
|
|
85
83
|
ov_http_request_object* ptr;
|
86
84
|
|
87
85
|
ptr = ALLOC(ov_http_request_object);
|
88
|
-
ptr->method
|
89
|
-
ptr->url
|
90
|
-
ptr->query
|
91
|
-
ptr->headers
|
92
|
-
ptr->username
|
93
|
-
ptr->password
|
94
|
-
ptr->token
|
95
|
-
ptr->kerberos
|
96
|
-
ptr->body
|
97
|
-
ptr->timeout
|
98
|
-
ptr->connect_timeout = Qnil;
|
86
|
+
ptr->method = Qnil;
|
87
|
+
ptr->url = Qnil;
|
88
|
+
ptr->query = Qnil;
|
89
|
+
ptr->headers = Qnil;
|
90
|
+
ptr->username = Qnil;
|
91
|
+
ptr->password = Qnil;
|
92
|
+
ptr->token = Qnil;
|
93
|
+
ptr->kerberos = Qnil;
|
94
|
+
ptr->body = Qnil;
|
95
|
+
ptr->timeout = Qnil;
|
99
96
|
return TypedData_Wrap_Struct(klass, &ov_http_request_type, ptr);
|
100
97
|
}
|
101
98
|
|
@@ -282,36 +279,6 @@ static VALUE ov_http_request_set_timeout(VALUE self, VALUE value) {
|
|
282
279
|
return Qnil;
|
283
280
|
}
|
284
281
|
|
285
|
-
static VALUE ov_http_request_get_connect_timeout(VALUE self) {
|
286
|
-
ov_http_request_object* ptr;
|
287
|
-
|
288
|
-
ov_http_request_ptr(self, ptr);
|
289
|
-
return ptr->connect_timeout;
|
290
|
-
}
|
291
|
-
|
292
|
-
static VALUE ov_http_request_set_connect_timeout(VALUE self, VALUE value) {
|
293
|
-
ov_http_request_object* ptr;
|
294
|
-
|
295
|
-
ov_http_request_ptr(self, ptr);
|
296
|
-
if (!NIL_P(value)) {
|
297
|
-
Check_Type(value, T_FIXNUM);
|
298
|
-
}
|
299
|
-
ptr->connect_timeout = value;
|
300
|
-
return Qnil;
|
301
|
-
}
|
302
|
-
|
303
|
-
static VALUE ov_http_request_inspect(VALUE self) {
|
304
|
-
ov_http_request_object* ptr;
|
305
|
-
|
306
|
-
ov_http_request_ptr(self, ptr);
|
307
|
-
return rb_sprintf(
|
308
|
-
"#<%"PRIsVALUE":%"PRIsVALUE" %"PRIsVALUE">",
|
309
|
-
ov_http_request_class,
|
310
|
-
ptr->method,
|
311
|
-
ptr->url
|
312
|
-
);
|
313
|
-
}
|
314
|
-
|
315
282
|
static VALUE ov_http_request_initialize(int argc, VALUE* argv, VALUE self) {
|
316
283
|
VALUE opts;
|
317
284
|
|
@@ -337,7 +304,6 @@ static VALUE ov_http_request_initialize(int argc, VALUE* argv, VALUE self) {
|
|
337
304
|
ov_http_request_set_token(self, rb_hash_aref(opts, TOKEN_SYMBOL));
|
338
305
|
ov_http_request_set_body(self, rb_hash_aref(opts, BODY_SYMBOL));
|
339
306
|
ov_http_request_set_timeout(self, rb_hash_aref(opts, TIMEOUT_SYMBOL));
|
340
|
-
ov_http_request_set_connect_timeout(self, rb_hash_aref(opts, CONNECT_TIMEOUT_SYMBOL));
|
341
307
|
|
342
308
|
return self;
|
343
309
|
}
|
@@ -351,43 +317,38 @@ void ov_http_request_define(void) {
|
|
351
317
|
rb_define_method(ov_http_request_class, "initialize", ov_http_request_initialize, -1);
|
352
318
|
|
353
319
|
/* Define the methods: */
|
354
|
-
rb_define_method(ov_http_request_class, "method",
|
355
|
-
rb_define_method(ov_http_request_class, "method=",
|
356
|
-
rb_define_method(ov_http_request_class, "url",
|
357
|
-
rb_define_method(ov_http_request_class, "url=",
|
358
|
-
rb_define_method(ov_http_request_class, "query",
|
359
|
-
rb_define_method(ov_http_request_class, "query=",
|
360
|
-
rb_define_method(ov_http_request_class, "headers",
|
361
|
-
rb_define_method(ov_http_request_class, "headers=",
|
362
|
-
rb_define_method(ov_http_request_class, "username",
|
363
|
-
rb_define_method(ov_http_request_class, "username=",
|
364
|
-
rb_define_method(ov_http_request_class, "password",
|
365
|
-
rb_define_method(ov_http_request_class, "password=",
|
366
|
-
rb_define_method(ov_http_request_class, "token",
|
367
|
-
rb_define_method(ov_http_request_class, "token=",
|
368
|
-
rb_define_method(ov_http_request_class, "kerberos",
|
369
|
-
rb_define_method(ov_http_request_class, "kerberos=",
|
370
|
-
rb_define_method(ov_http_request_class, "body",
|
371
|
-
rb_define_method(ov_http_request_class, "body=",
|
372
|
-
rb_define_method(ov_http_request_class, "timeout",
|
373
|
-
rb_define_method(ov_http_request_class, "timeout=",
|
374
|
-
rb_define_method(ov_http_request_class, "connect_timeout", ov_http_request_get_connect_timeout, 0);
|
375
|
-
rb_define_method(ov_http_request_class, "connect_timeout=", ov_http_request_set_connect_timeout, 1);
|
376
|
-
rb_define_method(ov_http_request_class, "inspect", ov_http_request_inspect, 0);
|
377
|
-
rb_define_method(ov_http_request_class, "to_s", ov_http_request_inspect, 0);
|
320
|
+
rb_define_method(ov_http_request_class, "method", ov_http_request_get_method, 0);
|
321
|
+
rb_define_method(ov_http_request_class, "method=", ov_http_request_set_method, 1);
|
322
|
+
rb_define_method(ov_http_request_class, "url", ov_http_request_get_url, 0);
|
323
|
+
rb_define_method(ov_http_request_class, "url=", ov_http_request_set_url, 1);
|
324
|
+
rb_define_method(ov_http_request_class, "query", ov_http_request_get_query, 0);
|
325
|
+
rb_define_method(ov_http_request_class, "query=", ov_http_request_set_query, 1);
|
326
|
+
rb_define_method(ov_http_request_class, "headers", ov_http_request_get_headers, 0);
|
327
|
+
rb_define_method(ov_http_request_class, "headers=", ov_http_request_set_headers, 1);
|
328
|
+
rb_define_method(ov_http_request_class, "username", ov_http_request_get_username, 0);
|
329
|
+
rb_define_method(ov_http_request_class, "username=", ov_http_request_set_username, 1);
|
330
|
+
rb_define_method(ov_http_request_class, "password", ov_http_request_get_password, 0);
|
331
|
+
rb_define_method(ov_http_request_class, "password=", ov_http_request_set_password, 1);
|
332
|
+
rb_define_method(ov_http_request_class, "token", ov_http_request_get_token, 0);
|
333
|
+
rb_define_method(ov_http_request_class, "token=", ov_http_request_set_token, 1);
|
334
|
+
rb_define_method(ov_http_request_class, "kerberos", ov_http_request_get_kerberos, 0);
|
335
|
+
rb_define_method(ov_http_request_class, "kerberos=", ov_http_request_set_kerberos, 1);
|
336
|
+
rb_define_method(ov_http_request_class, "body", ov_http_request_get_body, 0);
|
337
|
+
rb_define_method(ov_http_request_class, "body=", ov_http_request_set_body, 1);
|
338
|
+
rb_define_method(ov_http_request_class, "timeout", ov_http_request_get_timeout, 0);
|
339
|
+
rb_define_method(ov_http_request_class, "timeout=", ov_http_request_set_timeout, 1);
|
378
340
|
|
379
341
|
/* Define the symbols for the attributes: */
|
380
|
-
URL_SYMBOL
|
381
|
-
METHOD_SYMBOL
|
382
|
-
QUERY_SYMBOL
|
383
|
-
HEADERS_SYMBOL
|
384
|
-
USERNAME_SYMBOL
|
385
|
-
PASSWORD_SYMBOL
|
386
|
-
TOKEN_SYMBOL
|
387
|
-
KERBEROS_SYMBOL
|
388
|
-
BODY_SYMBOL
|
389
|
-
TIMEOUT_SYMBOL
|
390
|
-
CONNECT_TIMEOUT_SYMBOL = ID2SYM(rb_intern("connect_timeout"));
|
342
|
+
URL_SYMBOL = ID2SYM(rb_intern("url"));
|
343
|
+
METHOD_SYMBOL = ID2SYM(rb_intern("method"));
|
344
|
+
QUERY_SYMBOL = ID2SYM(rb_intern("query"));
|
345
|
+
HEADERS_SYMBOL = ID2SYM(rb_intern("headers"));
|
346
|
+
USERNAME_SYMBOL = ID2SYM(rb_intern("username"));
|
347
|
+
PASSWORD_SYMBOL = ID2SYM(rb_intern("password"));
|
348
|
+
TOKEN_SYMBOL = ID2SYM(rb_intern("token"));
|
349
|
+
KERBEROS_SYMBOL = ID2SYM(rb_intern("kerberos"));
|
350
|
+
BODY_SYMBOL = ID2SYM(rb_intern("body"));
|
351
|
+
TIMEOUT_SYMBOL = ID2SYM(rb_intern("timeout"));
|
391
352
|
|
392
353
|
/* Define the symbols for the HTTP methods: */
|
393
354
|
GET_SYMBOL = ID2SYM(rb_intern("GET"));
|
@@ -31,17 +31,16 @@ extern VALUE DELETE_SYMBOL;
|
|
31
31
|
|
32
32
|
/* Content: */
|
33
33
|
typedef struct {
|
34
|
-
VALUE method;
|
35
|
-
VALUE url;
|
36
|
-
VALUE query;
|
37
|
-
VALUE headers;
|
38
|
-
VALUE username;
|
39
|
-
VALUE password;
|
40
|
-
VALUE token;
|
41
|
-
VALUE kerberos;
|
42
|
-
VALUE body;
|
43
|
-
VALUE timeout;
|
44
|
-
VALUE connect_timeout; /* Integer */
|
34
|
+
VALUE method; /* Symbol */
|
35
|
+
VALUE url; /* String */
|
36
|
+
VALUE query; /* Hash<String, String> */
|
37
|
+
VALUE headers; /* Hash<String, String> */
|
38
|
+
VALUE username; /* String */
|
39
|
+
VALUE password; /* String */
|
40
|
+
VALUE token; /* String */
|
41
|
+
VALUE kerberos; /* Boolean */
|
42
|
+
VALUE body; /* String */
|
43
|
+
VALUE timeout; /* Integer */
|
45
44
|
} ov_http_request_object;
|
46
45
|
|
47
46
|
/* Macro to get the pointer: */
|
@@ -146,18 +146,6 @@ static VALUE ov_http_response_set_message(VALUE self, VALUE value) {
|
|
146
146
|
return Qnil;
|
147
147
|
}
|
148
148
|
|
149
|
-
static VALUE ov_http_response_inspect(VALUE self) {
|
150
|
-
ov_http_response_object* ptr;
|
151
|
-
|
152
|
-
ov_http_response_ptr(self, ptr);
|
153
|
-
return rb_sprintf(
|
154
|
-
"#<%"PRIsVALUE":%"PRIsVALUE" %"PRIsVALUE">",
|
155
|
-
ov_http_response_class,
|
156
|
-
ptr->code,
|
157
|
-
ptr->message
|
158
|
-
);
|
159
|
-
}
|
160
|
-
|
161
149
|
static VALUE ov_http_response_initialize(int argc, VALUE* argv, VALUE self) {
|
162
150
|
VALUE opts;
|
163
151
|
|
@@ -199,8 +187,6 @@ void ov_http_response_define(void) {
|
|
199
187
|
rb_define_method(ov_http_response_class, "headers=", ov_http_response_set_headers, 1);
|
200
188
|
rb_define_method(ov_http_response_class, "message", ov_http_response_get_message, 0);
|
201
189
|
rb_define_method(ov_http_response_class, "message=", ov_http_response_set_message, 1);
|
202
|
-
rb_define_method(ov_http_response_class, "inspect", ov_http_response_inspect, 0);
|
203
|
-
rb_define_method(ov_http_response_class, "to_s", ov_http_response_inspect, 0);
|
204
190
|
|
205
191
|
/* Define the symbols: */
|
206
192
|
BODY_SYMBOL = ID2SYM(rb_intern("body"));
|
@@ -71,21 +71,10 @@ static VALUE ov_http_transfer_alloc(VALUE klass) {
|
|
71
71
|
return TypedData_Wrap_Struct(klass, &ov_http_transfer_type, ptr);
|
72
72
|
}
|
73
73
|
|
74
|
-
static VALUE ov_http_transfer_inspect(VALUE self) {
|
75
|
-
ov_http_transfer_object* ptr;
|
76
|
-
|
77
|
-
ov_http_transfer_ptr(self, ptr);
|
78
|
-
return rb_sprintf("#<%"PRIsVALUE":%p>", ov_http_transfer_class, ptr);
|
79
|
-
}
|
80
|
-
|
81
74
|
void ov_http_transfer_define(void) {
|
82
75
|
/* Define the class: */
|
83
76
|
ov_http_transfer_class = rb_define_class_under(ov_module, "HttpTransfer", rb_cData);
|
84
77
|
|
85
78
|
/* Define the constructor: */
|
86
79
|
rb_define_alloc_func(ov_http_transfer_class, ov_http_transfer_alloc);
|
87
|
-
|
88
|
-
/* Define the methods: */
|
89
|
-
rb_define_method(ov_http_transfer_class, "inspect", ov_http_transfer_inspect, 0);
|
90
|
-
rb_define_method(ov_http_transfer_class, "to_s", ov_http_transfer_inspect, 0);
|
91
80
|
}
|
data/ext/ovirtsdk4c/ov_module.h
CHANGED
@@ -17,10 +17,10 @@ limitations under the License.
|
|
17
17
|
#ifndef __OV_MODULE_H__
|
18
18
|
#define __OV_MODULE_H__
|
19
19
|
|
20
|
-
|
20
|
+
// Module:
|
21
21
|
extern VALUE ov_module;
|
22
22
|
|
23
|
-
|
23
|
+
// Initialization function:
|
24
24
|
extern void ov_module_define(void);
|
25
25
|
|
26
26
|
#endif
|
data/lib/ovirtsdk4/connection.rb
CHANGED
@@ -16,7 +16,6 @@
|
|
16
16
|
|
17
17
|
require 'json'
|
18
18
|
require 'tempfile'
|
19
|
-
require 'thread'
|
20
19
|
require 'uri'
|
21
20
|
|
22
21
|
module OvirtSDK4
|
@@ -75,11 +74,8 @@ module OvirtSDK4
|
|
75
74
|
# instead of user name and password to obtain the OAuth token.
|
76
75
|
#
|
77
76
|
# @option opts [Integer] :timeout (0) The maximun total time to wait for the response, in seconds. A value of zero
|
78
|
-
# (the default) means wait for ever. If the timeout expires before the response is received
|
79
|
-
#
|
80
|
-
#
|
81
|
-
# @option opts [Integer] :connect_timeout (300) The maximun time to wait for connection establishment, in seconds.
|
82
|
-
# If the timeout expires before the connection is established a `TimeoutError` exception will be raised.
|
77
|
+
# (the default) means wait for ever. If the timeout expires before the response is received an exception will be
|
78
|
+
# raised.
|
83
79
|
#
|
84
80
|
# @option opts [Boolean] :compress (true) A boolean flag indicating if the SDK should ask the server to send
|
85
81
|
# compressed responses. Note that this is a hint for the server, and that it may return uncompressed data even
|
@@ -120,7 +116,6 @@ module OvirtSDK4
|
|
120
116
|
@log = opts[:log]
|
121
117
|
@kerberos = opts[:kerberos] || false
|
122
118
|
@timeout = opts[:timeout] || 0
|
123
|
-
@connect_timeout = opts[:connect_timeout] || 0
|
124
119
|
@compress = opts[:compress] || true
|
125
120
|
@proxy_url = opts[:proxy_url]
|
126
121
|
@proxy_username = opts[:proxy_username]
|
@@ -150,9 +145,6 @@ module OvirtSDK4
|
|
150
145
|
@ca_store.close
|
151
146
|
end
|
152
147
|
|
153
|
-
# Create the mutex that will be used to prevents simultaneous access to the same HTTP client by multiple threads:
|
154
|
-
@mutex = Mutex.new
|
155
|
-
|
156
148
|
# Create the HTTP client:
|
157
149
|
@client = HttpClient.new(
|
158
150
|
insecure: @insecure,
|
@@ -160,7 +152,6 @@ module OvirtSDK4
|
|
160
152
|
debug: @debug,
|
161
153
|
log: @log,
|
162
154
|
timeout: @timeout,
|
163
|
-
connect_timeout: @connect_timeout,
|
164
155
|
compress: @compress,
|
165
156
|
proxy_url: @proxy_url,
|
166
157
|
proxy_username: @proxy_username,
|
@@ -193,24 +184,65 @@ module OvirtSDK4
|
|
193
184
|
end
|
194
185
|
|
195
186
|
#
|
196
|
-
# Sends an HTTP request
|
187
|
+
# Sends an HTTP request.
|
197
188
|
#
|
198
189
|
# @param request [HttpRequest] The request object containing the details of the HTTP request to send.
|
199
190
|
#
|
200
191
|
# @api private
|
201
192
|
#
|
202
193
|
def send(request)
|
203
|
-
|
194
|
+
# Add the base URL to the request:
|
195
|
+
request.url = request.url.nil? ? request.url = @url : "#{@url}#{request.url}"
|
196
|
+
|
197
|
+
# Set the headers common to all requests:
|
198
|
+
request.headers.merge!(
|
199
|
+
'User-Agent' => "RubySDK/#{VERSION}",
|
200
|
+
'Version' => '4',
|
201
|
+
'Content-Type' => 'application/xml',
|
202
|
+
'Accept' => 'application/xml'
|
203
|
+
)
|
204
|
+
|
205
|
+
# Older versions of the engine (before 4.1) required the 'all_content' as an HTTP header instead of a query
|
206
|
+
# parameter. In order to better support those older versions of the engine we need to check if this parameter is
|
207
|
+
# included in the request, and add the corresponding header.
|
208
|
+
unless request.query.nil?
|
209
|
+
all_content = request.query['all_content']
|
210
|
+
request.headers['All-Content'] = all_content unless all_content.nil?
|
211
|
+
end
|
212
|
+
|
213
|
+
# Add the global headers, but without replacing the values that may already exist:
|
214
|
+
request.headers.merge!(@headers) { |_name, local, _global| local } if @headers
|
215
|
+
|
216
|
+
# Set the authentication token:
|
217
|
+
@token ||= create_access_token
|
218
|
+
request.token = @token
|
219
|
+
|
220
|
+
# Send the request:
|
221
|
+
@client.send(request)
|
204
222
|
end
|
205
223
|
|
206
224
|
#
|
207
|
-
# Waits for the response to the given request
|
225
|
+
# Waits for the response to the given request.
|
208
226
|
#
|
209
227
|
# @param request [HttpRequest] The request object whose corresponding response you want to wait for.
|
210
|
-
# @return [
|
228
|
+
# @return [Response] A request object containing the details of the HTTP response received.
|
211
229
|
#
|
212
230
|
def wait(request)
|
213
|
-
|
231
|
+
# Wait for the response:
|
232
|
+
response = @client.wait(request)
|
233
|
+
raise response if response.is_a?(Exception)
|
234
|
+
|
235
|
+
# If the request failed because of authentication, and it wasn't a request to the SSO service, then the
|
236
|
+
# most likely cause is an expired SSO token. In this case we need to request a new token, and try the original
|
237
|
+
# request again, but only once. It if fails again, we just return the failed response.
|
238
|
+
if response.code == 401 && request.token
|
239
|
+
@token = create_access_token
|
240
|
+
request.token = @token
|
241
|
+
@client.send(request)
|
242
|
+
response = @client.wait(request)
|
243
|
+
end
|
244
|
+
|
245
|
+
response
|
214
246
|
end
|
215
247
|
|
216
248
|
#
|
@@ -434,10 +466,17 @@ module OvirtSDK4
|
|
434
466
|
end
|
435
467
|
|
436
468
|
#
|
437
|
-
# Releases the resources used by this connection
|
469
|
+
# Releases the resources used by this connection.
|
438
470
|
#
|
439
471
|
def close
|
440
|
-
|
472
|
+
# Revoke the SSO access token:
|
473
|
+
revoke_access_token if @token
|
474
|
+
|
475
|
+
# Close the HTTP client:
|
476
|
+
@client.close if @client
|
477
|
+
|
478
|
+
# Remove the temporary file that contains the trusted CA certificates:
|
479
|
+
@ca_store.unlink if @ca_store
|
441
480
|
end
|
442
481
|
|
443
482
|
#
|
@@ -514,30 +553,6 @@ module OvirtSDK4
|
|
514
553
|
raise error
|
515
554
|
end
|
516
555
|
|
517
|
-
#
|
518
|
-
# Returns a string representation of the connection.
|
519
|
-
#
|
520
|
-
# @return [String] The string representation.
|
521
|
-
#
|
522
|
-
def inspect
|
523
|
-
"#<#{self.class.name}:#{@url}>"
|
524
|
-
end
|
525
|
-
|
526
|
-
#
|
527
|
-
# Returns a string representation of the connection.
|
528
|
-
#
|
529
|
-
# @return [String] The string representation.
|
530
|
-
#
|
531
|
-
def to_s
|
532
|
-
inspect
|
533
|
-
end
|
534
|
-
|
535
|
-
#
|
536
|
-
# Returns a string representation of the connection.
|
537
|
-
#
|
538
|
-
# @return [String] The string representation.
|
539
|
-
#
|
540
|
-
|
541
556
|
private
|
542
557
|
|
543
558
|
#
|
@@ -581,85 +596,5 @@ module OvirtSDK4
|
|
581
596
|
end
|
582
597
|
raise_error(response, detail)
|
583
598
|
end
|
584
|
-
|
585
|
-
#
|
586
|
-
# Sends an HTTP request.
|
587
|
-
#
|
588
|
-
# @param request [HttpRequest] The request object containing the details of the HTTP request to send.
|
589
|
-
#
|
590
|
-
# @api private
|
591
|
-
#
|
592
|
-
def internal_send(request)
|
593
|
-
# Add the base URL to the request:
|
594
|
-
request.url = request.url.nil? ? request.url = @url : "#{@url}/#{request.url}"
|
595
|
-
|
596
|
-
# Set the headers common to all requests:
|
597
|
-
request.headers.merge!(
|
598
|
-
'User-Agent' => "RubySDK/#{VERSION}",
|
599
|
-
'Version' => '4',
|
600
|
-
'Content-Type' => 'application/xml',
|
601
|
-
'Accept' => 'application/xml'
|
602
|
-
)
|
603
|
-
|
604
|
-
# Older versions of the engine (before 4.1) required the 'all_content' as an HTTP header instead of a query
|
605
|
-
# parameter. In order to better support those older versions of the engine we need to check if this parameter is
|
606
|
-
# included in the request, and add the corresponding header.
|
607
|
-
unless request.query.nil?
|
608
|
-
all_content = request.query['all_content']
|
609
|
-
request.headers['All-Content'] = all_content unless all_content.nil?
|
610
|
-
end
|
611
|
-
|
612
|
-
# Add the global headers, but without replacing the values that may already exist:
|
613
|
-
request.headers.merge!(@headers) { |_name, local, _global| local } if @headers
|
614
|
-
|
615
|
-
# Set the authentication token:
|
616
|
-
@token ||= create_access_token
|
617
|
-
request.token = @token
|
618
|
-
|
619
|
-
# Send the request:
|
620
|
-
@client.send(request)
|
621
|
-
end
|
622
|
-
|
623
|
-
#
|
624
|
-
# Waits for the response to the given request.
|
625
|
-
#
|
626
|
-
# @param request [HttpRequest] The request object whose corresponding response you want to wait for.
|
627
|
-
# @return [Response] A request object containing the details of the HTTP response received.
|
628
|
-
#
|
629
|
-
# @api private
|
630
|
-
#
|
631
|
-
def internal_wait(request)
|
632
|
-
# Wait for the response:
|
633
|
-
response = @client.wait(request)
|
634
|
-
raise response if response.is_a?(Exception)
|
635
|
-
|
636
|
-
# If the request failed because of authentication, and it wasn't a request to the SSO service, then the
|
637
|
-
# most likely cause is an expired SSO token. In this case we need to request a new token, and try the original
|
638
|
-
# request again, but only once. It if fails again, we just return the failed response.
|
639
|
-
if response.code == 401 && request.token
|
640
|
-
@token = create_access_token
|
641
|
-
request.token = @token
|
642
|
-
@client.send(request)
|
643
|
-
response = @client.wait(request)
|
644
|
-
end
|
645
|
-
|
646
|
-
response
|
647
|
-
end
|
648
|
-
|
649
|
-
#
|
650
|
-
# Releases the resources used by this connection.
|
651
|
-
#
|
652
|
-
# @api private
|
653
|
-
#
|
654
|
-
def internal_close
|
655
|
-
# Revoke the SSO access token:
|
656
|
-
revoke_access_token if @token
|
657
|
-
|
658
|
-
# Close the HTTP client:
|
659
|
-
@client.close if @client
|
660
|
-
|
661
|
-
# Remove the temporary file that contains the trusted CA certificates:
|
662
|
-
@ca_store.unlink if @ca_store
|
663
|
-
end
|
664
599
|
end
|
665
600
|
end
|