rbovirt 0.0.35 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abcc1f63781e5ac6ab29e40b1f497e5ae0fc35a7
4
- data.tar.gz: fb5b226fe6dcd08f3ed0c7aad7449ed19805127c
3
+ metadata.gz: 24d9c850c785261ddcce09c73bece4e49287674f
4
+ data.tar.gz: 01d0e257a952c22855e2a039caefbd1e930808e7
5
5
  SHA512:
6
- metadata.gz: 4a0bdc00d5b70be58f5daca0a9e67eb9b646f34b127c5514d4a84468a51aa44cff3417f8d89890d44dff3154c4f472ee98895e7a7478dedc1334707a92dda813
7
- data.tar.gz: af49d5221bf07f53d22569ea6db69c8370113321c1bb308aa4bd252c7509d7cf37cc5fbf1d00a3f9975db1dbb80132e8c180c5367b658ad632517cded9a82ad5
6
+ metadata.gz: ef5da7148b56d0a56a76757317829643dde5601742a5a16665c343ec0f24f0af64025187f206cfb743bc207727e452fae313f994ecffab931bf1f1c1cc56a49d
7
+ data.tar.gz: d144a471b8008dca6aa0700343e07815f7d838077653acb2dc54d5dc57a9350bed4a3120854678c92a64235d81f46139c8e49bfef02c270b34cda63fd53aff9e
@@ -0,0 +1,20 @@
1
+ module OVIRT
2
+ class Client
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
11
+
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
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module OVIRT
2
+ class Client
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
9
+ end
10
+ end
data/lib/client/vm_api.rb CHANGED
@@ -6,7 +6,11 @@ module OVIRT
6
6
  end
7
7
 
8
8
  def vms(opts={})
9
- headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
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
10
14
  path = "/vms"
11
15
  path += search_url(opts) unless filtered_api
12
16
  http_get(path, headers).xpath('/vms/vm').collect do |vm|
@@ -0,0 +1,73 @@
1
+ module OVIRT
2
+ # Instance types are added to oVirt 3.5 and have been updated in oVirt 3.6
3
+ class InstanceType < BaseObject
4
+ # Common attributes to all oVirt version supported at this time
5
+ attr_reader :name, :description, :memory, :cores, :os, :creation_time
6
+ attr_reader :ha, :ha_priority, :display, :usb, :migration_downtime
7
+
8
+ # oVirt 3.5 attributes
9
+ attr_reader :type, :status, :cpu_shares, :boot_menu, :origin, :stateless
10
+ attr_reader :delete_protected, :sso, :timezone
11
+
12
+ # oVirt 3.6 attributes
13
+ attr_reader :migration, :io_threads, :memory_guaranteed
14
+
15
+ def initialize(client, xml)
16
+ super(client, xml[:id], xml[:href], (xml/'name').first.text)
17
+ parse_xml_attributes!(xml)
18
+ self
19
+ end
20
+
21
+ private
22
+ def parse_xml_attributes!(xml)
23
+ # Common attributes
24
+ @description = ((xml/'description').first.text rescue '')
25
+ @memory = (xml/'memory').first.text
26
+ @cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
27
+ @os = {
28
+ :type => (xml/'os').first[:type],
29
+ :boot => (xml/'os/boot').collect {|boot| boot[:dev] }
30
+ }
31
+ @creation_time = (xml/'creation_time').text
32
+ @ha = parse_bool((xml/'high_availability/enabled').first.text)
33
+ @ha_priority = ((xml/'high_availability/priority').first.text rescue nil)
34
+ @display = {
35
+ :type => (xml/'display/type').first.text,
36
+ :monitors => (xml/'display/monitors').first.text,
37
+ :single_qxl_pci => parse_bool((xml/'display/single_qxl_pci').first.text),
38
+ :smartcard_enabled => parse_bool((xml/'display/smartcard_enabled').first.text),
39
+
40
+ }
41
+ @usb = parse_bool((xml/'usb/enabled').first.text)
42
+ @migration_downtime = ((xml/'migration_downtime').first.text)
43
+
44
+ # oVirt 3.5 attributes
45
+ @type = ((xml/'type').first.text rescue nil)
46
+ @status = ((xml/'status').first.text rescue nil)
47
+ @cpu_shares = (((xml/'cpu_shares').first.text) rescue nil)
48
+ potential_bool = ((xml/'bios/boot_menu/enabled').first.text rescue nil)
49
+ @boot_menu = potential_bool.nil? ? nil : parse_bool(potential_bool)
50
+ @origin = ((xml/'origin').text rescue nil)
51
+ potential_bool = ((xml/'stateless').first.text rescue nil)
52
+ @stateless = potential_bool.nil? ? nil : parse_bool(potential_bool)
53
+ potential_bool = ((xml/'delete_protected').first.text rescue nil)
54
+ @delete_protected = potential_bool.nil? ? nil : parse_bool(potential_bool)
55
+ #@sso = ((xml/'sso/methods').first.text rescue nil)
56
+ @timezone = ((xml/'timezone').first.text rescue nil)
57
+ potential_bool = ((xml/'display/allow_override').first.text rescue nil)
58
+ @display[:allow_override] = potential_bool.nil? ? nil : parse_bool(potential_bool)
59
+ potential_bool = ((xml/'display/file_transfer_enabled').first.text rescue nil)
60
+ @display[:file_transfer_enabled] = potential_bool.nil? ? nil : parse_bool(potential_bool)
61
+ potential_bool = ((xml/'display/copy_paste_enabled').first.text rescue nil)
62
+ @display[:copy_paste_enabled] = potential_bool.nil? ? nil : parse_bool(potential_bool)
63
+
64
+ # oVirt 3.6 attributes
65
+ @migration = {
66
+ :auto_converge => ((xml/'migration/auto_converge').first.text rescue nil),
67
+ :compressed => ((xml/'migration/compressed').first.text rescue nil)
68
+ }
69
+ @io_threads = ((xml/'io/threads').first.text rescue nil)
70
+ @memory_guaranteed = ((xml/'memory_policy/guaranteed').first.text rescue nil)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,11 @@
1
+ module OVIRT
2
+ class OperatingSystem < BaseObject
3
+ attr_reader :description
4
+
5
+ def initialize(client, xml)
6
+ super(client, xml[:id], xml[:href], (xml/'name').text)
7
+ @description = (xml/'description').text
8
+ self
9
+ end
10
+ end
11
+ end
@@ -36,8 +36,8 @@ module OVIRT
36
36
  @profile = (xml/'type').first.text
37
37
  @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
38
38
  @display = {
39
- :type => (xml/'display/type').first.text,
40
- :monitors => (xml/'display/monitors').first.text
39
+ :type => ((xml/'display/type').first.text rescue ''),
40
+ :monitors => ((xml/'display/monitors').first.text rescue 0)
41
41
  }
42
42
  @cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
43
43
  @storage = ((xml/'disks/disk/size').first.text rescue nil)
data/lib/ovirt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OVIRT
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.36"
3
3
  end
data/lib/ovirt/vm.rb CHANGED
@@ -76,18 +76,23 @@ module OVIRT
76
76
  end
77
77
  # os element must not be sent when template is present (RHBZ 1104235)
78
78
  if opts[:template].nil? || opts[:template].empty?
79
- os({:type => opts[:os_type] || 'unassigned' }){
80
- if(opts[:first_boot_dev] && opts[:first_boot_dev] == 'network')
81
- boot(:dev=> opts[:boot_dev1] || 'network')
82
- boot(:dev=> opts[:boot_dev2] || 'hd')
83
- else
84
- boot(:dev=> opts[:boot_dev2] || 'hd')
85
- boot(:dev=> opts[:boot_dev1] || 'network')
79
+ os_opts = opts[:os] ? opts[:os].dup : {}
80
+ os_opts[:type] ||= opts[:os_type] || 'unassigned'
81
+ os_opts[:boot] ||= [opts.fetch(:boot_dev1, 'network'), opts.fetch(:boot_dev2, 'hd')]
82
+ os_opts[:kernel] ||= opts[:os_kernel]
83
+ os_opts[:initrd] ||= opts[:os_initrd]
84
+ os_opts[:cmdline] ||= opts[:os_cmdline]
85
+ if opts[:first_boot_dev]
86
+ os_opts[:boot] = os_opts[:boot].sort_by.with_index do |device, index|
87
+ device == opts[:first_boot_dev] ? -1 : index
86
88
  end
87
- kernel (opts[:os_kernel])
88
- initrd (opts[:os_initrd])
89
- cmdline (opts[:os_cmdline])
90
- }
89
+ end
90
+ os(:type => os_opts[:type]) do
91
+ os_opts[:boot].each { |device| boot(:dev => device) }
92
+ kernel os_opts[:kernel]
93
+ initrd os_opts[:initrd]
94
+ cmdline os_opts[:cmdline]
95
+ end
91
96
  end
92
97
  display_{
93
98
  type_(opts[:display][:type])
@@ -237,12 +242,12 @@ module OVIRT
237
242
  @host = Link::new(@client, (xml/'host').first[:id], (xml/'host').first[:href]) rescue nil
238
243
  @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
239
244
  @display = {
240
- :type => (xml/'display/type').first.text,
245
+ :type => ((xml/'display/type').first.text rescue ''),
241
246
  :address => ((xml/'display/address').first.text rescue nil),
242
247
  :port => ((xml/'display/port').first.text rescue nil),
243
248
  :secure_port => ((xml/'display/secure_port').first.text rescue nil),
244
249
  :subject => ((xml/'display/certificate/subject').first.text rescue nil),
245
- :monitors => (xml/'display/monitors').first.text
250
+ :monitors => ((xml/'display/monitors').first.text rescue 0)
246
251
  }
247
252
  @cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
248
253
  @storage = ((xml/'disks/disk/size').first.text rescue nil)
data/lib/rbovirt.rb CHANGED
@@ -11,7 +11,9 @@ require "ovirt/interface"
11
11
  require "ovirt/network"
12
12
  require "ovirt/quota"
13
13
  require "ovirt/affinity_group"
14
+ require "ovirt/instance_type"
14
15
  require "ovirt/version"
16
+ require "ovirt/operating_system"
15
17
 
16
18
  require "client/vm_api"
17
19
  require "client/template_api"
@@ -22,6 +24,8 @@ require "client/storage_domain_api"
22
24
  require "client/quota_api"
23
25
  require "client/disk_api"
24
26
  require "client/affinity_group_api"
27
+ require "client/instance_type_api"
28
+ require "client/operating_system_api"
25
29
 
26
30
  require "nokogiri"
27
31
  require "rest_client"
@@ -44,7 +48,7 @@ module OVIRT
44
48
 
45
49
  class Client
46
50
 
47
- attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify
51
+ attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify, :persistent_auth, :jsessionid
48
52
 
49
53
  # Construct a new ovirt client class.
50
54
  # mandatory parameters
@@ -66,14 +70,16 @@ module OVIRT
66
70
  :cluster_id => backward_compatibility_cluster,
67
71
  :filtered_api => backward_compatibility_filtered}
68
72
  end
69
- @api_entrypoint = api_entrypoint
70
- @credentials = { :username => username, :password => password }
71
- @datacenter_id = options[:datacenter_id]
72
- @cluster_id = options[:cluster_id]
73
- @filtered_api = options[:filtered_api]
74
- @ca_cert_file = options[:ca_cert_file]
75
- @ca_cert_store = options[:ca_cert_store]
76
- @ca_no_verify = options[:ca_no_verify]
73
+ @api_entrypoint = api_entrypoint
74
+ @credentials = { :username => username, :password => password }
75
+ @datacenter_id = options[:datacenter_id]
76
+ @cluster_id = options[:cluster_id]
77
+ @filtered_api = options[:filtered_api]
78
+ @ca_cert_file = options[:ca_cert_file]
79
+ @ca_cert_store = options[:ca_cert_store]
80
+ @ca_no_verify = options[:ca_no_verify]
81
+ @persistent_auth = options[:persistent_auth]
82
+ @jsessionid = options[:jsessionid]
77
83
  end
78
84
 
79
85
  def api_version
@@ -92,9 +98,13 @@ module OVIRT
92
98
  end
93
99
 
94
100
  private
101
+
95
102
  def search_url opts
96
- search = opts[:search] || ("datacenter=%s" % current_datacenter.name)
97
- "?search=%s" % CGI.escape(search)
103
+ search = opts[:search] || ''
104
+ search += " datacenter=\"%s\"" % current_datacenter.name
105
+ search += " page #{opts[:page]}" if opts[:page]
106
+ max = opts[:max] ? ";max=#{opts[:max]}" : ''
107
+ "#{max}?search=#{CGI.escape(search)}"
98
108
  end
99
109
 
100
110
  def current_datacenter
@@ -107,9 +117,7 @@ module OVIRT
107
117
 
108
118
  def http_get(suburl, headers={})
109
119
  begin
110
- res = rest_client(suburl).get(http_headers(headers))
111
- puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
112
- Nokogiri::XML(res)
120
+ handle_success(rest_client(suburl).get(http_headers(headers)))
113
121
  rescue
114
122
  handle_fault $!
115
123
  end
@@ -117,9 +125,7 @@ module OVIRT
117
125
 
118
126
  def http_post(suburl, body, headers={})
119
127
  begin
120
- res = rest_client(suburl).post(body, http_headers(headers))
121
- puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
122
- Nokogiri::XML(res)
128
+ handle_success(rest_client(suburl).post(body, http_headers(headers)))
123
129
  rescue
124
130
  handle_fault $!
125
131
  end
@@ -127,9 +133,7 @@ module OVIRT
127
133
 
128
134
  def http_put(suburl, body, headers={})
129
135
  begin
130
- res = rest_client(suburl).put(body, http_headers(headers))
131
- puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
132
- Nokogiri::XML(res)
136
+ handle_success(rest_client(suburl).put(body, http_headers(headers)))
133
137
  rescue
134
138
  handle_fault $!
135
139
  end
@@ -139,9 +143,7 @@ module OVIRT
139
143
  begin
140
144
  headers = body ? http_headers(headers) :
141
145
  {:accept => 'application/xml'}.merge(auth_header).merge(filter_header)
142
- res = rest_client(suburl).delete_with_payload(body, headers)
143
- puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
144
- Nokogiri::XML(res)
146
+ handle_success(rest_client(suburl).delete_with_payload(body, headers))
145
147
  rescue
146
148
  handle_fault $!
147
149
  end
@@ -150,7 +152,12 @@ module OVIRT
150
152
  def auth_header
151
153
  # This is the method for strict_encode64:
152
154
  encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
153
- { :authorization => "Basic " + encoded_credentials }
155
+ headers = { :authorization => "Basic " + encoded_credentials }
156
+ if persistent_auth
157
+ headers[:prefer] = 'persistent-auth'
158
+ headers[:cookie] = "JSESSIONID=#{jsessionid}" if jsessionid
159
+ end
160
+ headers
154
161
  end
155
162
 
156
163
  def rest_client(suburl)
@@ -188,6 +195,12 @@ module OVIRT
188
195
  }).merge(headers)
189
196
  end
190
197
 
198
+ def handle_success(response)
199
+ puts "#{response}\n" if ENV['RBOVIRT_LOG_RESPONSE']
200
+ @jsessionid ||= response.cookies['JSESSIONID']
201
+ Nokogiri::XML(response)
202
+ end
203
+
191
204
  def handle_fault(f)
192
205
  if f.is_a?(RestClient::BadRequest) || f.is_a?(RestClient::Conflict)
193
206
  fault = (Nokogiri::XML(f.http_body)/'//fault/detail')
@@ -58,6 +58,28 @@ describe OVIRT, "Https authentication" do
58
58
  end
59
59
  end
60
60
 
61
+ describe OVIRT, "Persistent authentication" do
62
+ context 'use persistent authentication' do
63
+
64
+ it "test_request_with_persistent_authentication" do
65
+ user, password, url, datacenter = endpoint
66
+ cert = ca_cert(url)
67
+ store = OpenSSL::X509::Store.new().add_cert(
68
+ OpenSSL::X509::Certificate.new(cert))
69
+
70
+ client = ::OVIRT::Client.new(user, password, url, {:ca_cert_store => store, :persistent_auth => true})
71
+ client.api_version.class.should eql(String)
72
+ client.persistent_auth.should eql(true)
73
+ client.jsessionid.should_not be_nil
74
+
75
+ # When performing a new request the jsessionid should remain the same
76
+ orig_jsession_id = client.jsessionid
77
+ client.datacenters.class.should eql(Array)
78
+ client.jsessionid.should eql(orig_jsession_id)
79
+ end
80
+ end
81
+ end
82
+
61
83
  describe OVIRT, "Admin API" do
62
84
 
63
85
  before(:all) do
@@ -0,0 +1,16 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe "Basic Instance type life cycle" do
4
+ before(:all) do
5
+ setup_client
6
+ end
7
+
8
+ it "test_should_return_instance_types" do
9
+ @client.instance_types
10
+ end
11
+
12
+ it "test_should_return_an_instance_type" do
13
+ @instance_type = @client.instance_types.first
14
+ @client.instance_type(@instance_type.id).id.should eql(@instance_type.id)
15
+ end
16
+ end
@@ -42,6 +42,8 @@ shared_examples_for "Basic VM Life cycle" do
42
42
  end
43
43
 
44
44
  it "test_should_start_with_cloudinit" do
45
+ while @client.vm(@vm.id).status.strip != 'down' do
46
+ end
45
47
  hostname = "host-"+Time.now.to_i.to_s
46
48
  user_data={ :hostname => hostname }
47
49
  @client.vm_start_with_cloudinit(@vm.id, user_data)
@@ -51,6 +53,8 @@ shared_examples_for "Basic VM Life cycle" do
51
53
  end
52
54
 
53
55
  it "test_should_set_vm_ticket" do
56
+ while @client.vm(@vm.id).status.strip != 'down' do
57
+ end
54
58
  @client.vm_action(@vm.id, :start)
55
59
  while !@client.vm(@vm.id).running? do
56
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbovirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Benari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -80,8 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: |2
84
- A Ruby client for oVirt REST API
83
+ description: " A Ruby client for oVirt REST API\n"
85
84
  email:
86
85
  - abenari@redhat.com
87
86
  executables: []
@@ -102,6 +101,8 @@ files:
102
101
  - lib/client/datacenter_api.rb
103
102
  - lib/client/disk_api.rb
104
103
  - lib/client/host_api.rb
104
+ - lib/client/instance_type_api.rb
105
+ - lib/client/operating_system_api.rb
105
106
  - lib/client/quota_api.rb
106
107
  - lib/client/storage_domain_api.rb
107
108
  - lib/client/template_api.rb
@@ -111,8 +112,10 @@ files:
111
112
  - lib/ovirt/cluster.rb
112
113
  - lib/ovirt/datacenter.rb
113
114
  - lib/ovirt/host.rb
115
+ - lib/ovirt/instance_type.rb
114
116
  - lib/ovirt/interface.rb
115
117
  - lib/ovirt/network.rb
118
+ - lib/ovirt/operating_system.rb
116
119
  - lib/ovirt/quota.rb
117
120
  - lib/ovirt/storage_domain.rb
118
121
  - lib/ovirt/template.rb
@@ -126,6 +129,7 @@ files:
126
129
  - rbovirt.gemspec
127
130
  - spec/endpoint.yml.example
128
131
  - spec/integration/api_spec.rb
132
+ - spec/integration/instance_type_spec.rb
129
133
  - spec/integration/vm_crud_spec.rb
130
134
  - spec/spec_helper.rb
131
135
  - spec/unit/client_spec.rb
@@ -156,14 +160,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
160
  version: '0'
157
161
  requirements: []
158
162
  rubyforge_project:
159
- rubygems_version: 2.2.2
163
+ rubygems_version: 2.0.14
160
164
  signing_key:
161
165
  specification_version: 4
162
166
  summary: A Ruby client for oVirt REST API
163
167
  test_files:
164
168
  - spec/endpoint.yml.example
165
169
  - spec/integration/api_spec.rb
170
+ - spec/integration/instance_type_spec.rb
166
171
  - spec/integration/vm_crud_spec.rb
167
172
  - spec/spec_helper.rb
168
173
  - spec/unit/client_spec.rb
169
174
  - spec/unit/vm_spec.rb
175
+ has_rdoc: