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