ovirt 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ovirt/inventory.rb +4 -0
- data/lib/ovirt/service.rb +47 -5
- data/lib/ovirt/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc172ac5a494fe8fadb4903ac66e950a17cd9e16
|
4
|
+
data.tar.gz: 917e3cd03ddacd7a64e5880e8e7fb063fae59010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94cba5c058a105783ad3950e5b66215df36b84aef7b1b2b0df5efa1e8c480eaa51a420f9c574f39e27d2f4bea319d2ca593359c4541f229d55d48c9d9edb727d
|
7
|
+
data.tar.gz: e436a90440f21749c935a23241c85f9d6d9d2856527830d5e02af1f6d7cc5fe29b273ef5e498cdecb3e4cc2b3665269456447c9a84047876201ec1524b76f9e4
|
data/lib/ovirt/inventory.rb
CHANGED
@@ -99,6 +99,10 @@ module Ovirt
|
|
99
99
|
collect_secondary_items(primary_items, methods[:secondary])
|
100
100
|
end
|
101
101
|
|
102
|
+
def api_path
|
103
|
+
@service.api_path
|
104
|
+
end
|
105
|
+
|
102
106
|
private
|
103
107
|
|
104
108
|
def standard_collection(uri_suffix, element_name = nil, paginate = false, sort_by = :name, direction = :asc)
|
data/lib/ovirt/service.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'openssl'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'uri'
|
2
5
|
|
3
6
|
module Ovirt
|
4
7
|
class Service
|
@@ -12,6 +15,12 @@ module Ovirt
|
|
12
15
|
DEFAULT_SCHEME = 'https'.freeze
|
13
16
|
SESSION_ID_KEY = 'JSESSIONID'.freeze
|
14
17
|
|
18
|
+
# The list of absolute URI paths where the API can be available:
|
19
|
+
CANDIDATE_API_PATHS = [
|
20
|
+
'/api',
|
21
|
+
'/ovirt-engine/api',
|
22
|
+
].freeze
|
23
|
+
|
15
24
|
attr_accessor :session_id
|
16
25
|
|
17
26
|
def self.name_to_class(name)
|
@@ -28,6 +37,7 @@ module Ovirt
|
|
28
37
|
REQUIRED_OPTIONS.each { |key| raise "No #{key} specified" unless @options.key?(key) }
|
29
38
|
@password = @options.delete(:password)
|
30
39
|
@session_id = @options[:session_id]
|
40
|
+
@api_path = @options[:path]
|
31
41
|
end
|
32
42
|
|
33
43
|
def inspect # just like the default inspect, but WITHOUT @password
|
@@ -145,8 +155,40 @@ module Ovirt
|
|
145
155
|
node.xpath('status/state').text
|
146
156
|
end
|
147
157
|
|
158
|
+
# Checks if the API is available in the given candidate path. It does so sending a request without
|
159
|
+
# authentication. If the API is available there it will respond with the "WWW-Autenticate" header
|
160
|
+
# and with the "RESTAPI" or "ENGINE" realm.
|
161
|
+
def probe_api_path(uri, path)
|
162
|
+
uri = URI.join(uri, path)
|
163
|
+
request = RestClient::Resource.new(uri.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE)
|
164
|
+
begin
|
165
|
+
request.get
|
166
|
+
rescue RestClient::Exception => exception
|
167
|
+
response = exception.response
|
168
|
+
if response.code == 401
|
169
|
+
www_authenticate = response.headers[:www_authenticate]
|
170
|
+
if www_authenticate =~ /^Basic realm="?(RESTAPI|ENGINE)"?$/
|
171
|
+
return true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
false
|
176
|
+
end
|
177
|
+
|
178
|
+
# Probes all the candidate paths of the API, and returns the first that success. If all probes
|
179
|
+
# fail, then the first candidate will be returned.
|
180
|
+
def find_api_path(uri)
|
181
|
+
CANDIDATE_API_PATHS.detect { |path| probe_api_path(uri, path) } || CANDIDATE_API_PATHS.first
|
182
|
+
end
|
183
|
+
|
184
|
+
# Returns the path of the API, probing it if needed.
|
185
|
+
def api_path
|
186
|
+
@api_path ||= find_api_path(base_uri)
|
187
|
+
end
|
188
|
+
|
148
189
|
def api_uri(path = nil)
|
149
|
-
|
190
|
+
# Calculate the complete URI:
|
191
|
+
uri = URI.join(base_uri, api_path).to_s
|
150
192
|
unless path.nil?
|
151
193
|
parts = path.to_s.split('/')
|
152
194
|
parts.shift if parts.first == '' # Remove leading slash
|
@@ -164,7 +206,6 @@ module Ovirt
|
|
164
206
|
end
|
165
207
|
|
166
208
|
def engine_ssh_public_key
|
167
|
-
require "rest-client"
|
168
209
|
RestClient::Resource.new("#{base_uri}/engine.ssh.key.txt", resource_options).get
|
169
210
|
end
|
170
211
|
|
@@ -206,7 +247,6 @@ module Ovirt
|
|
206
247
|
end
|
207
248
|
|
208
249
|
def create_resource(path = nil)
|
209
|
-
require "rest-client"
|
210
250
|
RestClient::Resource.new(api_uri(path), resource_options)
|
211
251
|
end
|
212
252
|
|
@@ -270,14 +310,16 @@ module Ovirt
|
|
270
310
|
end
|
271
311
|
|
272
312
|
def base_uri
|
273
|
-
require 'uri'
|
274
313
|
uri = URI::Generic.build(:scheme => scheme.to_s, :port => port)
|
275
314
|
uri.hostname = server
|
276
315
|
uri.to_s
|
277
316
|
end
|
278
317
|
|
279
318
|
def resource_options
|
280
|
-
headers = merge_headers(
|
319
|
+
headers = merge_headers(
|
320
|
+
'Version' => '3',
|
321
|
+
'Prefer' => 'persistent-auth',
|
322
|
+
)
|
281
323
|
options = {}
|
282
324
|
|
283
325
|
if session_id
|
data/lib/ovirt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ovirt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Frey
|
@@ -16,10 +16,11 @@ authors:
|
|
16
16
|
- Adam Grare
|
17
17
|
- Dávid Halász
|
18
18
|
- pkliczewski
|
19
|
+
- Juan Hernandez
|
19
20
|
autorequire:
|
20
21
|
bindir: bin
|
21
22
|
cert_chain: []
|
22
|
-
date: 2016-04-
|
23
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
23
24
|
dependencies:
|
24
25
|
- !ruby/object:Gem::Dependency
|
25
26
|
name: bundler
|
@@ -176,6 +177,7 @@ email:
|
|
176
177
|
- agrare@redhat.com
|
177
178
|
- dhalasz@redhat.com
|
178
179
|
- piotr.kliczewski@gmail.com
|
180
|
+
- juan.hernandez@redhat.com
|
179
181
|
executables: []
|
180
182
|
extensions: []
|
181
183
|
extra_rdoc_files: []
|