lib/rbovirt.rb in rbovirt-0.0.38 vs lib/rbovirt.rb in rbovirt-0.1.0
- old
+ new
@@ -1,37 +1,34 @@
require "ovirt/base_object"
require "ovirt/cluster"
require "ovirt/datacenter"
require "ovirt/host"
require "ovirt/storage_domain"
+require "ovirt/disk_profile"
require "ovirt/template"
require "ovirt/template_version"
require "ovirt/vm"
require "ovirt/volume"
require "ovirt/interface"
require "ovirt/network"
require "ovirt/quota"
require "ovirt/affinity_group"
-require "ovirt/instance_type"
require "ovirt/version"
-require "ovirt/operating_system"
require "client/vm_api"
require "client/template_api"
require "client/cluster_api"
require "client/host_api"
require "client/datacenter_api"
require "client/storage_domain_api"
require "client/quota_api"
require "client/disk_api"
require "client/affinity_group_api"
-require "client/instance_type_api"
-require "client/operating_system_api"
+require "client/disk_profile_api"
require "nokogiri"
require "rest_client"
-require "restclient_ext/request"
require "restclient_ext/resource"
module OVIRT
class OvirtVersionUnsupportedException < StandardError; end
@@ -46,11 +43,11 @@
end
end
class Client
- attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify, :persistent_auth, :jsessionid
+ 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
@@ -68,20 +65,18 @@
# backward compatibility optional parameters
options = {:datacenter_id => options,
:cluster_id => backward_compatibility_cluster,
:filtered_api => backward_compatibility_filtered}
end
- @api_entrypoint = api_entrypoint
- @credentials = { :username => username, :password => password }
- @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]
- @persistent_auth = options[:persistent_auth]
- @jsessionid = options[:jsessionid]
+ @api_entrypoint = api_entrypoint
+ @credentials = { :username => username, :password => password }
+ @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'
@@ -96,17 +91,13 @@
xml = http_get("/capabilities")
!(xml/"version/custom_properties/custom_property[@name='floppyinject']").empty?
end
private
-
def search_url opts
- search = opts[:search] || ''
- search += " datacenter=\"%s\"" % current_datacenter.name
- search += " page #{opts[:page]}" if opts[:page]
- max = opts[:max] ? ";max=#{opts[:max]}" : ''
- "#{max}?search=#{CGI.escape(search)}"
+ search = opts[:search] || ("datacenter=%s" % current_datacenter.name)
+ "?search=%s" % CGI.escape(search)
end
def current_datacenter
@current_datacenter ||= self.datacenter_id ? datacenter(self.datacenter_id) : datacenters.first
end
@@ -115,51 +106,54 @@
@current_cluster ||= self.cluster_id ? cluster(self.cluster_id) : clusters.first
end
def http_get(suburl, headers={})
begin
- handle_success(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
- handle_success(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
- handle_success(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, body=nil, headers={})
begin
headers = body ? http_headers(headers) :
- {:accept => 'application/xml', :version => '3'}.merge(auth_header).merge(filter_header)
- handle_success(rest_client(suburl).delete_with_payload(body, headers))
+ {:accept => 'application/xml'}.merge(auth_header).merge(filter_header)
+ res = rest_client(suburl).delete_with_payload(body, headers)
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
+ Nokogiri::XML(res)
rescue
handle_fault $!
end
end
def auth_header
# This is the method for strict_encode64:
encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
- headers = { :authorization => "Basic " + encoded_credentials }
- if persistent_auth
- headers[:prefer] = 'persistent-auth'
- headers[:cookie] = "JSESSIONID=#{jsessionid}" if jsessionid
- end
- headers
+ { :authorization => "Basic " + encoded_credentials }
end
def rest_client(suburl)
if (URI.parse(@api_entrypoint)).scheme == 'https'
options = {}
@@ -190,17 +184,10 @@
def http_headers(headers ={})
filter_header.merge(auth_header).merge({
:content_type => 'application/xml',
:accept => 'application/xml',
- :version => '3',
}).merge(headers)
- end
-
- def handle_success(response)
- puts "#{response}\n" if ENV['RBOVIRT_LOG_RESPONSE']
- @jsessionid ||= response.cookies['JSESSIONID']
- Nokogiri::XML(response)
end
def handle_fault(f)
if f.is_a?(RestClient::BadRequest) || f.is_a?(RestClient::Conflict)
fault = (Nokogiri::XML(f.http_body)/'//fault/detail')