class OVIRT::Client

Attributes

api_entrypoint[R]
ca_cert_file[R]
ca_cert_store[R]
ca_no_verify[R]
cluster_id[R]
credentials[R]
datacenter_id[R]
filtered_api[R]
jsessionid[R]
persistent_auth[R]

Public Class Methods

new(username, password, api_entrypoint, options={}, backward_compatibility_cluster=nil, backward_compatibility_filtered=nil ) click to toggle source

Construct a new ovirt client class. mandatory parameters

username, password, api_entrypoint  - for example 'me@internal', 'secret', 'https://example.com/api'

optional parameters

datacenter_id, cluster_id and filtered_api can be sent in this order for backward
compatibility, or as a hash in the 4th parameter.
datacenter_id - setting the datacenter at initialization will add a default scope to any subsequent call
                to the client to the specified datacenter.
cluster_id    - setting the cluster at initialization will add a default scope to any subsequent call
                to the client to the specified cluster.
filtered_api  - when set to false (default) will use ovirt administrator api, else it will use the user
                api mode.
   # File lib/rbovirt.rb
67 def initialize(username, password, api_entrypoint, options={}, backward_compatibility_cluster=nil, backward_compatibility_filtered=nil )
68   if !options.is_a?(Hash)
69     # backward compatibility optional parameters
70     options = {:datacenter_id => options,
71                :cluster_id => backward_compatibility_cluster,
72                :filtered_api => backward_compatibility_filtered}
73   end
74   @api_entrypoint  = api_entrypoint
75   @credentials     = { :username => username, :password => password }
76   @datacenter_id   = options[:datacenter_id]
77   @cluster_id      = options[:cluster_id]
78   @filtered_api    = options[:filtered_api]
79   @ca_cert_file    = options[:ca_cert_file]
80   @ca_cert_store   = options[:ca_cert_store]
81   @ca_no_verify    = options[:ca_no_verify]
82   @persistent_auth = options[:persistent_auth]
83   @jsessionid      = options[:jsessionid]
84 end

Private Class Methods

parse_response(response) click to toggle source
    # File lib/rbovirt.rb
188 def self.parse_response(response)
189   Nokogiri::XML(response)
190 end

Public Instance Methods

activate_volume(vm_id, vol_id) click to toggle source
    # File lib/client/vm_api.rb
123 def activate_volume(vm_id, vol_id)
124   http_post("/vms/%s/disks/%s/activate" % [vm_id, vol_id], '<action/>') unless volume_active?(vm_id, vol_id)
125 end
add_interface(vm_id, opts={}) click to toggle source
   # File lib/client/vm_api.rb
76 def add_interface(vm_id, opts={})
77   http_post("/vms/%s/nics" % vm_id, OVIRT::Interface.to_xml( opts))
78 end
add_vm_to_affinity_group(affinity_group_id, vm_id, opts={}) click to toggle source
   # File lib/client/affinity_group_api.rb
33 def add_vm_to_affinity_group(affinity_group_id, vm_id, opts={})
34   cluster_id = opts[:cluster_id] || current_cluster.id
35   http_post("/clusters/%s/affinitygroups/%s/vms" % [cluster_id, affinity_group_id], "<vm id='%s'/>" % vm_id)
36 end
add_volume(vm_id, opts={}) click to toggle source
    # File lib/client/vm_api.rb
 97 def add_volume(vm_id, opts={})
 98   search = opts[:search] || ("datacenter=%s" % current_datacenter.name)
 99   opts[:storage_domain_id] = opts[:storage_domain] || storagedomains(:role => 'data', :search => search).first.id
100   # If no size is given, default to a volume size of 8GB
101   opts[:size] = 8 * 1024 * 1024 * 1024 unless opts[:size]
102   opts[:type] = 'data' unless opts[:type]
103   opts[:bootable] = 'true' unless opts[:bootable]
104   opts[:interface] = 'virtio' unless opts[:interface]
105   opts[:format] = 'cow' unless opts[:format]
106   opts[:sparse] = 'true' unless opts[:sparse]
107   http_post("/vms/%s/disks" % vm_id, OVIRT::Volume.to_xml(opts))
108 end
affinity_group(affinity_group_id, opts={}) click to toggle source
  # File lib/client/affinity_group_api.rb
3 def affinity_group(affinity_group_id, opts={})
4   cluster_id = opts[:cluster_id] || current_cluster.id
5   ag_xml = http_get("/clusters/%s/affinitygroups/%s" % [cluster_id, affinity_group_id], http_headers)
6   OVIRT::AffinityGroup.new(self, ag_xml.root)
7 end
affinity_group_vms(affinity_group_id, opts={}) click to toggle source
   # File lib/client/affinity_group_api.rb
16 def affinity_group_vms(affinity_group_id, opts={})
17   cluster_id = opts[:cluster_id] || current_cluster.id
18   http_get("/clusters/%s/affinitygroups/%s/vms" % [cluster_id, affinity_group_id], http_headers).xpath('/vms/vm').collect do |vm_ref|
19     OVIRT::VM.new(self, http_get("/vms/%s" % vm_ref.attribute('id').value, http_headers).root)
20   end
21 end
affinity_groups(opts={}) click to toggle source
   # File lib/client/affinity_group_api.rb
 9 def affinity_groups(opts={})
10   cluster_id = opts[:cluster_id] || current_cluster.id
11   http_get("/clusters/%s/affinitygroups" % cluster_id, http_headers).xpath('/affinity_groups/affinity_group').collect do |ag|
12     OVIRT::AffinityGroup.new(self, ag)
13   end
14 end
api_version() click to toggle source
   # File lib/rbovirt.rb
86 def api_version
87   return @api_version unless @api_version.nil?
88   xml = http_get("/")/'/api/product_info/version'
89   major = (xml/'version').first[:major]
90   minor = (xml/'version').first[:minor]
91   build = (xml/'version').first[:build]
92   revision = (xml/'version').first[:revision]
93   @api_version = "#{major}.#{minor}.#{build}.#{revision}"
94 end
api_version?(major, minor=nil) click to toggle source
   # File lib/rbovirt.rb
96 def api_version?(major, minor=nil)
97   (api_version.split('.')[0] == major) && (minor.nil? ? true : api_version.split('.')[1] == minor)
98 end
approve_host(host_id, opts={}) click to toggle source
   # File lib/client/host_api.rb
16 def approve_host(host_id, opts={})
17     http_post("/hosts/%s/approve" % host_id, "<action></action>")
18 end
attach_volume(vm_id, vol_id, activate=true) click to toggle source
    # File lib/client/vm_api.rb
131 def attach_volume(vm_id, vol_id, activate=true)
132   http_post("/vms/%s/disks" % vm_id, "<disk id='%s'/>" % vol_id)
133   activate_volume(vm_id, vol_id) if activate
134 end
cluster(cluster_id) click to toggle source
   # File lib/client/cluster_api.rb
24 def cluster(cluster_id)
25   headers = {:accept => "application/xml; detail=datacenters"}
26   cluster_xml = http_get("/clusters/%s" % cluster_id, headers)
27   OVIRT::Cluster.new(self, cluster_xml.root)
28 end
cluster_version(cluster_id) click to toggle source
  # File lib/client/cluster_api.rb
3 def cluster_version(cluster_id)
4   c = cluster(cluster_id)
5   return c.version.split('.')[0].to_i, c.version.split('.')[1].to_i
6 end
cluster_version?(cluster_id, major) click to toggle source
   # File lib/client/cluster_api.rb
 8 def cluster_version?(cluster_id, major)
 9   c = cluster(cluster_id)
10   c.version.split('.')[0] == major
11 end
clusters(opts={}) click to toggle source
   # File lib/client/cluster_api.rb
13 def clusters(opts={})
14   headers = {:accept => "application/xml; detail=datacenters"}
15   path = "/clusters"
16   path += search_url(opts) unless filtered_api
17   http_get(path, headers).xpath('/clusters/cluster').collect do |cl|
18     cluster = OVIRT::Cluster.new(self, cl)
19     #the following line is needed as a work-around a bug in RHEV 3.0 rest-api
20     cluster if filtered_api || (cluster.datacenter.id == current_datacenter.id)
21   end.compact
22 end
create_affinity_group(opts={}) click to toggle source
   # File lib/client/affinity_group_api.rb
23 def create_affinity_group(opts={})
24   cluster_id = opts[:cluster_id] || current_cluster.id
25   OVIRT::AffinityGroup.new(self, http_post("/clusters/%s/affinitygroups" % cluster_id, OVIRT::AffinityGroup.to_xml(opts)).root)
26 end
create_template(opts) click to toggle source
   # File lib/client/template_api.rb
17 def create_template(opts)
18   template = http_post("/templates", Template.to_xml(opts))
19   OVIRT::Template::new(self, template.root)
20 end
create_vm(opts) click to toggle source
   # File lib/client/vm_api.rb
36 def create_vm(opts)
37   cluster_major_ver, cluster_minor_ver = cluster_version(self.cluster_id)
38 
39   if opts[:user_data] and not opts[:user_data].empty?
40     if api_version?('3') and cluster_major_ver >= 3
41       if cluster_minor_ver >= 3
42         opts[:user_data_method] = :payload_v3_3
43       elsif cluster_minor_ver >= 1
44         opts[:user_data_method] = :payload
45       elsif floppy_hook?
46         opts[:user_data_method] = :custom_property
47       else
48         raise "Required VDSM hook 'floppyinject' not supported by RHEV-M"
49       end
50     else
51       raise BackendVersionUnsupportedException.new
52     end
53   end
54 
55   process_vm_opts(opts)
56 
57   opts[:cluster_name] ||= clusters.first.name unless opts[:cluster]
58   OVIRT::VM::new(self, http_post("/vms",OVIRT::VM.to_xml(opts)).root)
59 end
datacenter(datacenter_id) click to toggle source
   # File lib/client/datacenter_api.rb
 3 def datacenter(datacenter_id)
 4     begin
 5       datacenter = http_get("/datacenters/%s" % datacenter_id)
 6       OVIRT::DataCenter::new(self, datacenter.root)
 7     rescue
 8       handle_fault $!
 9     end
10   end
datacenters(opts={}) click to toggle source
   # File lib/client/datacenter_api.rb
12 def datacenters(opts={})
13   search = opts[:search] ||""
14   datacenters = http_get("/datacenters?search=%s" % CGI.escape(search))
15   datacenters.xpath('/data_centers/data_center').collect do |dc|
16     OVIRT::DataCenter::new(self, dc)
17   end
18 end
deactivate_volume(vm_id, vol_id) click to toggle source
    # File lib/client/vm_api.rb
127 def deactivate_volume(vm_id, vol_id)
128   http_post("/vms/%s/disks/%s/deactivate" % [vm_id, vol_id], '<action/>') if volume_active?(vm_id, vol_id)
129 end
delete_vm_from_affinity_group(affinity_group_id, vm_id, opts={}) click to toggle source
   # File lib/client/affinity_group_api.rb
38 def delete_vm_from_affinity_group(affinity_group_id, vm_id, opts={})
39   cluster_id = opts[:cluster_id] || current_cluster.id
40   http_delete("/clusters/%s/affinitygroups/%s/vms/%s" % [cluster_id, affinity_group_id, vm_id])
41 end
destroy_affinity_group(affinity_group_id, opts={}) click to toggle source
   # File lib/client/affinity_group_api.rb
28 def destroy_affinity_group(affinity_group_id, opts={})
29   cluster_id = opts[:cluster_id] || current_cluster.id
30   http_delete("/clusters/%s/affinitygroups/%s" % [cluster_id, affinity_group_id])
31 end
destroy_interface(vm_id, interface_id) click to toggle source
   # File lib/client/vm_api.rb
72 def destroy_interface(vm_id, interface_id)
73   http_delete("/vms/%s/nics/%s" % [vm_id, interface_id])
74 end
destroy_template(id) click to toggle source
   # File lib/client/template_api.rb
22 def destroy_template(id)
23   http_delete("/templates/%s" % id)
24 end
destroy_vm(id) click to toggle source
    # File lib/client/vm_api.rb
158 def destroy_vm(id)
159   http_delete("/vms/%s" % id)
160 end
destroy_volume(vm_id, vol_id) click to toggle source
    # File lib/client/vm_api.rb
110 def destroy_volume(vm_id, vol_id)
111   http_delete("/vms/%s/disks/%s" % [vm_id, vol_id])
112 end
detach_volume(vm_id, vol_id) click to toggle source
    # File lib/client/vm_api.rb
136 def detach_volume(vm_id, vol_id)
137   deactivate_volume(vm_id, vol_id)
138   http_delete("/vms/%s/disks/%s" % [vm_id, vol_id], '<action><detach>true</detach></action>')
139 end
disk(disk_id) click to toggle source
   # File lib/client/disk_api.rb
10 def disk(disk_id)
11   disk_xml = http_get("/disks/%s" % disk_id)
12   OVIRT::Volume.new(self, disk_xml.root)
13 end
diskprofile(dp_id) click to toggle source
  # File lib/client/disk_profile_api.rb
3 def diskprofile(dp_id)
4   dp = http_get("/diskprofiles/%s" % dp_id)
5   OVIRT::DiskProfile::new(self, dp.root)
6 end
diskprofiles(opts={}) click to toggle source
   # File lib/client/disk_profile_api.rb
 8 def diskprofiles(opts={})
 9   path = "/diskprofiles"
10   path += search_url(opts) unless filtered_api
11   http_get(path).xpath('/disk_profiles/disk_profile').collect do |dp|
12     OVIRT::DiskProfile::new(self,dp)
13   end.compact
14 end
disks(opts={}) click to toggle source
  # File lib/client/disk_api.rb
3 def disks(opts={})
4   path = "/disks" + search_url(opts)
5   http_get(path).xpath('/disks/disk').collect do |d|
6     OVIRT::Volume.new(self, d)
7   end
8 end
floppy_hook?() click to toggle source
    # File lib/rbovirt.rb
100 def floppy_hook?
101   xml = http_get("/capabilities")
102   !(xml/"version/custom_properties/custom_property[@name='floppyinject']").empty?
103 end
host(host_id, opts={}) click to toggle source
  # File lib/client/host_api.rb
3 def host(host_id, opts={})
4   xml_response = http_get("/hosts/%s" % host_id)
5   OVIRT::Host::new(self, xml_response.root)
6 end
hosts(opts={}) click to toggle source
   # File lib/client/host_api.rb
 8 def hosts(opts={})
 9   path = "/hosts"
10   path += search_url(opts) unless filtered_api
11   http_get(path).xpath('/hosts/host').collect do |h|
12     OVIRT::Host::new(self, h)
13   end
14 end
instance_type(instance_type_id) click to toggle source
   # File lib/client/instance_type_api.rb
 3 def instance_type(instance_type_id)
 4     begin
 5       instance_type = http_get("/instancetypes/%s" % instance_type_id)
 6       OVIRT::InstanceType::new(self, instance_type.root)
 7     rescue
 8       handle_fault $!
 9     end
10   end
instance_types(opts={}) click to toggle source
   # File lib/client/instance_type_api.rb
12 def instance_types(opts={})
13   search = opts[:search] ||""
14   instance_types = http_get("/instancetypes?search=%s" % CGI.escape(search))
15   instance_types.xpath('/instance_types/instance_type').collect do |it|
16     OVIRT::InstanceType::new(self, it)
17   end
18 end
networks(opts) click to toggle source
   # File lib/client/cluster_api.rb
30 def networks(opts)
31   cluster_id = opts[:cluster_id] || current_cluster.id
32   http_get("/clusters/%s/networks" % cluster_id, http_headers).xpath('/networks/network').collect do |cl|
33     OVIRT::Network.new(self, cl)
34   end
35 end
operating_systems() click to toggle source
  # File lib/client/operating_system_api.rb
3 def operating_systems
4   operating_systems = http_get('/operatingsystems')
5   operating_systems.xpath('/operating_systems/operating_system').collect do |os|
6     OVIRT::OperatingSystem::new(self, os)
7   end
8 end
process_vm_opts(opts) click to toggle source
   # File lib/client/vm_api.rb
21 def process_vm_opts(opts)
22   if (opts[:template] or opts[:template_name]) and (opts[:storagedomain] or opts[:storagedomain_name])
23     template_id = opts[:template] || templates.select{|t| t.name == opts[:template_name]}.first.id
24     template_disks = template_volumes(template_id)
25     storagedomain_id = opts[:storagedomain] || storagedomains.select{|s| s.name == opts[:storagedomain_name]}.first.id
26 
27     # Make sure the 'clone' option is set if any of the disks defined by
28     # the template is stored on a different storage domain than requested
29     opts[:clone] = true unless opts[:clone] == true || template_disks.empty? || template_disks.all? { |d| d.storage_domain == storagedomain_id }
30 
31     # Create disks map
32     opts[:disks] = template_disks.collect { |d| {:id => d.id, :storagedomain => storagedomain_id} }
33   end
34 end
quota(quota_id, opts={}) click to toggle source
  # File lib/client/quota_api.rb
3 def quota(quota_id, opts={})
4   q = http_get("/datacenters/%s/quotas/%s" % [current_datacenter.id, quota_id])
5   OVIRT::Quota::new(self, q.root)
6 end
quotas(opts={}) click to toggle source
   # File lib/client/quota_api.rb
 8 def quotas(opts={})
 9   http_get("/datacenters/%s/quotas" % CGI.escape(current_datacenter.id)).xpath('/quotas/quota').collect do |q|
10     OVIRT::Quota::new(self, q)
11   end.compact
12 end
reinstall_host(host_id, override_iptables=false, opts={}) click to toggle source
   # File lib/client/host_api.rb
20 def reinstall_host(host_id, override_iptables=false, opts={})
21     http_post("/hosts/%s/install" % host_id,
22               "<action>
23                 <ssh>
24                  <authentication_method>PublicKey</authentication_method>
25                 </ssh>
26                 <host>
27                  <override_iptables>" + override_iptables.to_s + "</override_iptables>
28                 </host>
29                </action>"
30              )
31 end
set_ticket(vm_id, options={}) click to toggle source
    # File lib/client/vm_api.rb
162 def set_ticket(vm_id, options={})
163   ticket = OVIRT::VM.ticket(options)
164   xml_response = http_post("/vms/%s/ticket" % vm_id, ticket)
165   (xml_response/'action/ticket/value').first.text
166 end
storagedomain(sd_id) click to toggle source
  # File lib/client/storage_domain_api.rb
3 def storagedomain(sd_id)
4   sd = http_get("/storagedomains/%s" % sd_id)
5   OVIRT::StorageDomain::new(self, sd.root)
6 end
storagedomains(opts={}) click to toggle source
   # File lib/client/storage_domain_api.rb
 8 def storagedomains(opts={})
 9   path = "/storagedomains"
10   path += search_url(opts) unless filtered_api
11   http_get(path).xpath('/storage_domains/storage_domain').collect do |sd|
12     storage_domain = OVIRT::StorageDomain::new(self, sd)
13     #filter by role is not supported by the search language. The work around is to list all, then filter.
14     (opts[:role].nil? || storage_domain.role == opts[:role]) ? storage_domain : nil
15   end.compact
16 end
template(template_id, opts={}) click to toggle source
   # File lib/client/template_api.rb
11 def template(template_id, opts={})
12   results = http_get("/templates/%s" % template_id)
13   template = OVIRT::Template::new(self, results.root)
14   template
15 end
template_interfaces(template_id) click to toggle source
   # File lib/client/template_api.rb
26 def template_interfaces template_id
27   http_get("/templates/%s/nics" % template_id, http_headers).xpath('/nics/nic').collect do |nic|
28     OVIRT::Interface::new(self, nic)
29   end
30 end
template_volumes(template_id) click to toggle source
   # File lib/client/template_api.rb
32 def template_volumes template_id
33   http_get("/templates/%s/disks" % template_id, http_headers).xpath('/disks/disk').collect do |disk|
34     OVIRT::Volume::new(self, disk)
35   end
36 end
templates(opts={}) click to toggle source
  # File lib/client/template_api.rb
3 def templates(opts={})
4   path = "/templates"
5   path += search_url(opts) unless filtered_api
6   http_get(path).xpath('/templates/template').collect do |t|
7     OVIRT::Template::new(self, t)
8   end.compact
9 end
update_interface(vm_id, interface_id, opts={}) click to toggle source
   # File lib/client/vm_api.rb
80 def update_interface(vm_id, interface_id, opts={})
81   http_put("/vms/%s/nics/%s" % [vm_id, interface_id], OVIRT::Interface.to_xml( opts))
82 end
update_vm(opts) click to toggle source
    # File lib/client/vm_api.rb
168 def update_vm(opts)
169   opts[:cluster_name] ||= clusters.first.name
170   result_xml = http_put("/vms/%s" % opts[:id], OVIRT::VM.to_xml(opts))
171   OVIRT::VM::new(self, result_xml.root)
172 end
update_volume(vm_id, vol_id, opts={}) click to toggle source
    # File lib/client/vm_api.rb
114 def update_volume(vm_id, vol_id, opts={})
115   http_put("/vms/%s/disks/%s" % [vm_id, vol_id], OVIRT::Volume.to_xml(opts))
116 end
vm(vm_id, opts={}) click to toggle source
  # File lib/client/vm_api.rb
3 def vm(vm_id, opts={})
4   headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
5   OVIRT::VM::new(self,  http_get("/vms/%s" % vm_id, headers).root)
6 end
vm_action(id, action, opts={}) click to toggle source
    # File lib/client/vm_api.rb
141 def vm_action(id, action, opts={})
142   xml_response = http_post("/vms/%s/%s" % [id, action],'<action/>', opts)
143   return (xml_response/'action/status').first.text.strip.upcase=="COMPLETE"
144 end
vm_interfaces(vm_id) click to toggle source
   # File lib/client/vm_api.rb
61 def vm_interfaces vm_id
62   begin
63     http_get("/vms/%s/nics" % vm_id, http_headers).xpath('/nics/nic').collect do |nic|
64       OVIRT::Interface::new(self, nic)
65     end
66   rescue => e # Catch case were vm_id is destroyed.
67     raise e unless e.message =~ /Entity not found/
68     []
69   end
70 end
vm_start_with_cloudinit(id, opts={}) click to toggle source
    # File lib/client/vm_api.rb
146 def vm_start_with_cloudinit(id, opts={})
147   # Get the api and cluster version on which the VM is provisioned.
148   # This is required for VM::cloudinit.
149   opts.merge!(
150     :cluster_version => cluster_version(vm(id).cluster.id),
151     :api_version => api_version.split('.').map(&:to_i)
152   )
153   xml = OVIRT::VM.cloudinit(opts)
154   xml_response = http_post("/vms/%s/%s" % [id, 'start'], xml, {} )
155   return (xml_response/'action/status').first.text.strip.upcase=="COMPLETE"
156 end
vm_volumes(vm_id) click to toggle source
   # File lib/client/vm_api.rb
84 def vm_volumes vm_id
85   begin
86     volumes = http_get("/vms/%s/disks" % vm_id, http_headers).xpath('/disks/disk').collect do |disk|
87       OVIRT::Volume::new(self, disk)
88     end
89   rescue => e # Catch case were vm_id is destroyed.
90     raise e unless e.message =~ /Entity not found/
91     volumes = []
92   end
93   #this is a workaround to a bug that the list is not sorted by default.
94   volumes.sort{ |l, r| l.name <=> r.name }
95 end
vms(opts={}) click to toggle source
   # File lib/client/vm_api.rb
 8 def vms(opts={})
 9   if opts[:without_details]
10     headers = {:accept => "application/xml"}
11   else
12     headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
13   end
14   path = "/vms"
15   path += search_url(opts) unless filtered_api
16   http_get(path, headers).xpath('/vms/vm').collect do |vm|
17     OVIRT::VM::new(self, vm)
18   end
19 end
volume_active?(vm_id, vol_id) click to toggle source
    # File lib/client/vm_api.rb
118 def volume_active?(vm_id, vol_id)
119   http_response = http_get("/vms/%s/disks/%s" % [vm_id, vol_id, http_headers])
120   http_response.xpath("/disk/active").first.text.upcase == "TRUE"
121 end

Private Instance Methods

auth_header() click to toggle source
    # File lib/rbovirt.rb
157 def auth_header
158   # This is the method for strict_encode64:
159   encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
160   headers = { :authorization => "Basic " + encoded_credentials }
161   if persistent_auth
162     headers[:prefer] = 'persistent-auth'
163     headers[:cookie] = "JSESSIONID=#{jsessionid}" if jsessionid
164   end
165   headers
166 end
base_url() click to toggle source
    # File lib/rbovirt.rb
183 def base_url
184   url = URI.parse(@api_entrypoint)
185   "#{url.scheme}://#{url.host}:#{url.port}"
186 end
current_cluster() click to toggle source
    # File lib/rbovirt.rb
119 def current_cluster
120   @current_cluster ||= self.cluster_id ? cluster(self.cluster_id) : clusters.first
121 end
current_datacenter() click to toggle source
    # File lib/rbovirt.rb
115 def current_datacenter
116   @current_datacenter ||= self.datacenter_id ? datacenter(self.datacenter_id) : datacenters.first
117 end
filter_header() click to toggle source
    # File lib/rbovirt.rb
179 def filter_header
180   filtered_api ? { :filter => "true" } : {}
181 end
handle_fault(f) click to toggle source
    # File lib/rbovirt.rb
210 def handle_fault(f)
211   if f.is_a?(RestClient::BadRequest) || f.is_a?(RestClient::Conflict)
212     fault = (Nokogiri::XML(f.http_body)/'//fault/detail')
213     fault = fault.text.gsub(/\[|\]/, '') if fault
214   end
215   fault ||= f.message
216   raise OvirtException::new(fault)
217 end
handle_success(response) click to toggle source
    # File lib/rbovirt.rb
204 def handle_success(response)
205   puts "#{response}\n" if ENV['RBOVIRT_LOG_RESPONSE']
206   @jsessionid ||= response.cookies['JSESSIONID']
207   Nokogiri::XML(response)
208 end
has_datacenter?(vm) click to toggle source
    # File lib/rbovirt.rb
192 def has_datacenter?(vm)
193   (vm/'data_center').any?
194 end
http_delete(suburl, body=nil, headers={}) click to toggle source
    # File lib/rbovirt.rb
147 def http_delete(suburl, body=nil, headers={})
148   begin
149     headers = body ? http_headers(headers) :
150       {:accept => 'application/xml', :version => '3'}.merge(auth_header).merge(filter_header)
151     handle_success(rest_client(suburl).delete_with_payload(body, headers))
152   rescue
153     handle_fault $!
154   end
155 end
http_get(suburl, headers={}) click to toggle source
    # File lib/rbovirt.rb
123 def http_get(suburl, headers={})
124   begin
125     handle_success(rest_client(suburl).get(http_headers(headers)))
126   rescue
127     handle_fault $!
128   end
129 end
http_headers(headers ={}) click to toggle source
    # File lib/rbovirt.rb
196 def http_headers(headers ={})
197   filter_header.merge(auth_header).merge({
198     :content_type => 'application/xml',
199     :accept => 'application/xml',
200     :version => '3',
201   }).merge(headers)
202 end
http_post(suburl, body, headers={}) click to toggle source
    # File lib/rbovirt.rb
131 def http_post(suburl, body, headers={})
132   begin
133     handle_success(rest_client(suburl).post(body, http_headers(headers)))
134   rescue
135     handle_fault $!
136   end
137 end
http_put(suburl, body, headers={}) click to toggle source
    # File lib/rbovirt.rb
139 def http_put(suburl, body, headers={})
140   begin
141     handle_success(rest_client(suburl).put(body, http_headers(headers)))
142   rescue
143     handle_fault $!
144   end
145 end
rest_client(suburl) click to toggle source
    # File lib/rbovirt.rb
168 def rest_client(suburl)
169   if (URI.parse(@api_entrypoint)).scheme == 'https'
170     options = {}
171     options[:verify_ssl] = ca_no_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
172     options[:ssl_cert_store] = ca_cert_store if ca_cert_store
173     options[:ssl_ca_file] = ca_cert_file if ca_cert_file
174   end
175   options[:timeout] = ENV['RBOVIRT_REST_TIMEOUT'].to_i if ENV['RBOVIRT_REST_TIMEOUT']
176   RestClient::Resource.new(@api_entrypoint, options)[suburl]
177 end
search_url(opts) click to toggle source
    # File lib/rbovirt.rb
107 def search_url opts
108   search = opts[:search] || ''
109   search += " datacenter=\"%s\"" % current_datacenter.name
110   search += " page #{opts[:page]}" if opts[:page]
111   max = opts[:max] ? ";max=#{opts[:max]}" : ''
112   "#{max}?search=#{CGI.escape(search)}"
113 end