lib/rbovirt.rb in rbovirt-0.0.28 vs lib/rbovirt.rb in rbovirt-0.0.29
- old
+ new
@@ -37,11 +37,11 @@
end
end
class Client
- attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store
+ attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify
# Construct a new ovirt client class.
# mandatory parameters
# username, password, api_entrypoint - for example 'me@internal', 'secret', 'https://example.com/api'
# optional parameters
@@ -66,10 +66,11 @@
@datacenter_id = options[:datacenter_id]
@cluster_id = options[:cluster_id]
@filtered_api = options[:filtered_api]
@ca_cert_file = options[:ca_cert_file]
@ca_cert_store = options[:ca_cert_store]
+ @ca_no_verify = options[:ca_no_verify]
end
def api_version
return @api_version unless @api_version.nil?
xml = http_get("/")/'/api/product_info/version'
@@ -99,36 +100,44 @@
@current_cluster ||= self.cluster_id ? cluster(self.cluster_id) : clusters.first
end
def http_get(suburl, headers={})
begin
- Nokogiri::XML(rest_client(suburl).get(http_headers(headers)))
+ res = rest_client(suburl).get(http_headers(headers))
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
+ Nokogiri::XML(res)
rescue
handle_fault $!
end
end
def http_post(suburl, body, headers={})
begin
- Nokogiri::XML(rest_client(suburl).post(body, http_headers(headers)))
+ res = rest_client(suburl).post(body, http_headers(headers))
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
+ Nokogiri::XML(res)
rescue
handle_fault $!
end
end
def http_put(suburl, body, headers={})
begin
- Nokogiri::XML(rest_client(suburl).put(body, http_headers(headers)))
+ res = rest_client(suburl).put(body, http_headers(headers))
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
+ Nokogiri::XML(res)
rescue
handle_fault $!
end
end
def http_delete(suburl)
begin
headers = {:accept => 'application/xml'}.merge(auth_header).merge(filter_header)
- Nokogiri::XML(rest_client(suburl).delete(headers))
+ res = rest_client(suburl).delete(headers)
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
+ Nokogiri::XML(res)
rescue
handle_fault $!
end
end
@@ -138,12 +147,13 @@
{ :authorization => "Basic " + encoded_credentials }
end
def rest_client(suburl)
if (URI.parse(@api_entrypoint)).scheme == 'https'
- verify_options = {:verify_ssl => OpenSSL::SSL::VERIFY_PEER}
+ verify_options = {}
+ verify_options[:verify_ssl] = ca_no_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
verify_options[:ssl_cert_store] = ca_cert_store if ca_cert_store
- verify_options[:ssl_ca_file] = ca_cert_file if ca_cert_file
+ verify_options[:ssl_ca_file] = ca_cert_file if ca_cert_file
end
RestClient::Resource.new(@api_entrypoint, verify_options)[suburl]
end
def filter_header