rbovirt 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2UzMTk4OTk2ZmFlNWJjMGVkYzYzMjBkY2Q3YmIxMzNiNjkxMGJmOQ==
5
- data.tar.gz: !binary |-
6
- NDEyYWE2ZjAyY2E3YjEwNjY0OGEzOGMxNDY5NTQwZGIwMWY2ZDY5NA==
2
+ SHA1:
3
+ metadata.gz: 0bc880c41ea4532df8b68011f5d9f68b8118b403
4
+ data.tar.gz: 58445a4c11abd89d373b40448b327167a6f95915
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDllNmM3OGZkZjBkNGY3Yjk1NjhjM2I0YWJjZDcyODI3ZGZlNTcxMjdlNzA2
10
- M2EzNDc4NWM4YzE1YWFkZjNjODU3NDZiYjI3ODg4YjM3NjcxZTkwNjVjOWUy
11
- NTAwZGVkY2QzYmQ4ZTQ1ZDQyY2QyZDI4ZmEyNDA3NzM2MDVjZDI=
12
- data.tar.gz: !binary |-
13
- ZjMwMGZhZjQxZDcxZGI3MzRkODYyYmJiMWYzYWQ2MjVkMmM0YTg5MGZlN2Nj
14
- YTYyMzI4MzNjZjc4YTQ0ZGUyZjU3NTFhZmY0NjMzNzE2MTZlNmE4NWUyYmUx
15
- NTNiNDI2YTBhYjhhMWVkODRiNjU3MGM4YjVhZTc3ZDhiY2UyYjk=
6
+ metadata.gz: 84fb76a2e15e4c715390fb51c8485099d2fda933e219cc687b4dc23948335a998cd9140b57c3faa8cd4d82629851457b83fdd6df5bbc2dab3ed4635c20ea263d
7
+ data.tar.gz: bbd004504dba3fd58ef03a51b310970ee1b3d069daa753e4085c46e02c96deb0863893caaf5e36a24cb35b4acf0ac6a937c8e7f4c55d12b4d7358a3ca54784f9
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ tags
1
2
  Gemfile.lock
2
3
  endpoint.yml
3
4
  spec/ca_cert.pem
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
-
data/README.rdoc CHANGED
@@ -13,10 +13,25 @@ A Ruby client for oVirt.
13
13
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
14
 
15
15
  == Running the tests
16
+
16
17
  * Copy the file spec/endpoint.yml.example to spec/endpoint.yml
17
18
  * Edit the endpoint properties (user, password and host name)
19
+ * `wget --no-check-certificate -O spec/ca_cert.pem https://host/ca.crt`
18
20
  * From command line run => rake spec
19
21
 
22
+ RHEV/oVirt can be installed with all-in-one setup, but host certificate must be self-signed otherwise one test will fail.
23
+
24
+ == Logging
25
+
26
+ If you want to see API requests and responses, use the following environment variables:
27
+
28
+ RESTCLIENT_LOG=stdout RBOVIRT_LOG_RESPONSE=1 rake spec
29
+
30
+ == TODO
31
+
32
+ * Auto download of ca.crt for all tests
33
+ * Pry integration
34
+
20
35
  == Copyright
21
36
 
22
37
  Copyright (c) 2012 Amos Benari. See LICENSE.txt for
data/lib/ovirt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OVIRT
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
  end
data/lib/ovirt/vm.rb CHANGED
@@ -74,18 +74,21 @@ module OVIRT
74
74
  topology( :cores => (opts[:cores] || '1'), :sockets => '1' )
75
75
  }
76
76
  end
77
- os({:type => opts[:os_type] || 'unassigned' }){
78
- if(opts[:first_boot_dev] && opts[:first_boot_dev] == 'network')
79
- boot(:dev=> opts[:boot_dev1] || 'network')
80
- boot(:dev=> opts[:boot_dev2] || 'hd')
81
- else
82
- boot(:dev=> opts[:boot_dev2] || 'hd')
83
- boot(:dev=> opts[:boot_dev1] || 'network')
84
- end
85
- kernel (opts[:os_kernel])
86
- initrd (opts[:os_initrd])
87
- cmdline (opts[:os_cmdline])
88
- }
77
+ # os element must not be sent when template is present (RHBZ 1104235)
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')
86
+ end
87
+ kernel (opts[:os_kernel])
88
+ initrd (opts[:os_initrd])
89
+ cmdline (opts[:os_cmdline])
90
+ }
91
+ end
89
92
  display_{
90
93
  type_(opts[:display][:type])
91
94
  } if opts[:display]
data/lib/rbovirt.rb CHANGED
@@ -39,7 +39,7 @@ module OVIRT
39
39
 
40
40
  class Client
41
41
 
42
- attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store
42
+ attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify
43
43
 
44
44
  # Construct a new ovirt client class.
45
45
  # mandatory parameters
@@ -68,6 +68,7 @@ module OVIRT
68
68
  @filtered_api = options[:filtered_api]
69
69
  @ca_cert_file = options[:ca_cert_file]
70
70
  @ca_cert_store = options[:ca_cert_store]
71
+ @ca_no_verify = options[:ca_no_verify]
71
72
  end
72
73
 
73
74
  def api_version
@@ -101,7 +102,9 @@ module OVIRT
101
102
 
102
103
  def http_get(suburl, headers={})
103
104
  begin
104
- Nokogiri::XML(rest_client(suburl).get(http_headers(headers)))
105
+ res = rest_client(suburl).get(http_headers(headers))
106
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
107
+ Nokogiri::XML(res)
105
108
  rescue
106
109
  handle_fault $!
107
110
  end
@@ -109,7 +112,9 @@ module OVIRT
109
112
 
110
113
  def http_post(suburl, body, headers={})
111
114
  begin
112
- Nokogiri::XML(rest_client(suburl).post(body, http_headers(headers)))
115
+ res = rest_client(suburl).post(body, http_headers(headers))
116
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
117
+ Nokogiri::XML(res)
113
118
  rescue
114
119
  handle_fault $!
115
120
  end
@@ -117,7 +122,9 @@ module OVIRT
117
122
 
118
123
  def http_put(suburl, body, headers={})
119
124
  begin
120
- Nokogiri::XML(rest_client(suburl).put(body, http_headers(headers)))
125
+ res = rest_client(suburl).put(body, http_headers(headers))
126
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
127
+ Nokogiri::XML(res)
121
128
  rescue
122
129
  handle_fault $!
123
130
  end
@@ -126,7 +133,9 @@ module OVIRT
126
133
  def http_delete(suburl)
127
134
  begin
128
135
  headers = {:accept => 'application/xml'}.merge(auth_header).merge(filter_header)
129
- Nokogiri::XML(rest_client(suburl).delete(headers))
136
+ res = rest_client(suburl).delete(headers)
137
+ puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
138
+ Nokogiri::XML(res)
130
139
  rescue
131
140
  handle_fault $!
132
141
  end
@@ -140,9 +149,10 @@ module OVIRT
140
149
 
141
150
  def rest_client(suburl)
142
151
  if (URI.parse(@api_entrypoint)).scheme == 'https'
143
- verify_options = {:verify_ssl => OpenSSL::SSL::VERIFY_PEER}
152
+ verify_options = {}
153
+ verify_options[:verify_ssl] = ca_no_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
144
154
  verify_options[:ssl_cert_store] = ca_cert_store if ca_cert_store
145
- verify_options[:ssl_ca_file] = ca_cert_file if ca_cert_file
155
+ verify_options[:ssl_ca_file] = ca_cert_file if ca_cert_file
146
156
  end
147
157
  RestClient::Resource.new(@api_entrypoint, verify_options)[suburl]
148
158
  end
@@ -1,5 +1,9 @@
1
+ # This is example configuration for integration tests and it should
2
+ # work out-of-box with all-in-one oVirt setup
1
3
 
4
+ url: "https://localhost/api"
2
5
  user: "admin@internal"
3
- password: "secret"
4
- url: "http://ovirt.example.com/api"
5
- network: 'ovirtmgmt'
6
+ password: "ovirt"
7
+ datacenter: "local_datacenter"
8
+ cluster: "local_cluster"
9
+ network: "ovirtmgmt"
@@ -43,12 +43,12 @@ describe OVIRT, "Https authentication" do
43
43
 
44
44
  it "test_should_get_ca_certificate" do
45
45
  user, password, url, datacenter = endpoint
46
- ::OVIRT::RSpec.ca_cert(url).class.should eql(String)
46
+ ca_cert(url).class.should eql(String)
47
47
  end
48
48
 
49
49
  it "should_authenticate_with_ca_certificate" do
50
50
  user, password, url, datacenter = endpoint
51
- cert = ::OVIRT::RSpec.ca_cert(url)
51
+ cert = ca_cert(url)
52
52
  store = OpenSSL::X509::Store.new().add_cert(
53
53
  OpenSSL::X509::Certificate.new(cert))
54
54
 
@@ -61,9 +61,7 @@ end
61
61
  describe OVIRT, "Admin API" do
62
62
 
63
63
  before(:all) do
64
- user, password, url, datacenter = endpoint
65
- opts = {:datacenter_id => datacenter, :ca_cert_file => "#{File.dirname(__FILE__)}/../ca_cert.pem"}
66
- @client = ::OVIRT::Client.new(user, password, url, opts )
64
+ setup_client
67
65
  end
68
66
 
69
67
  after(:all) do
@@ -82,9 +80,7 @@ end
82
80
  describe OVIRT, "User API" do
83
81
 
84
82
  before(:all) do
85
- user, password, url, datacenter = endpoint
86
- opts = {:datacenter_id => datacenter, :ca_cert_file => "#{File.dirname(__FILE__)}/../ca_cert.pem", :filtered_api => support_user_level_api}
87
- @client = ::OVIRT::Client.new(user, password, url, opts)
83
+ setup_client :filtered_api => support_user_level_api
88
84
  end
89
85
 
90
86
  after(:all) do
@@ -100,4 +96,4 @@ describe OVIRT, "User API" do
100
96
  end
101
97
  end
102
98
 
103
- end
99
+ end
@@ -3,9 +3,9 @@ require "#{File.dirname(__FILE__)}/../spec_helper"
3
3
  shared_examples_for "Basic VM Life cycle" do
4
4
 
5
5
  before(:all) do
6
- @cluster = @client.clusters.last.id
7
- @template_id = "00000000-0000-0000-0000-000000000000"
8
6
  name = 'vm-'+Time.now.to_i.to_s
7
+ @cluster = @client.clusters.select{|c| c.name == cluster_name}.first.id
8
+ @template_id = "00000000-0000-0000-0000-000000000000"
9
9
  @vm = @client.create_vm(:name => name, :template => @template_id, :cluster => @cluster)
10
10
  @client.add_volume(@vm.id)
11
11
  @client.add_interface(@vm.id, :network_name => network_name)
@@ -56,7 +56,7 @@ shared_examples_for "Basic VM Life cycle" do
56
56
  end
57
57
 
58
58
  it "test_should_update_vm" do
59
- name = 'u-'+Time.now.to_i.to_s
59
+ name = 'vmu-'+Time.now.to_i.to_s
60
60
  @client.update_vm(:id => @vm.id, :name=> name, :cluster => @cluster)
61
61
  end
62
62
 
@@ -68,12 +68,43 @@ shared_examples_for "Basic VM Life cycle" do
68
68
  end
69
69
  end
70
70
 
71
+ shared_examples_for "VM Life cycle without template" do
72
+
73
+ before(:all) do
74
+ name = 'vm-'+Time.now.to_i.to_s
75
+ @cluster = @client.clusters.select{|c| c.name == cluster_name}.first.id
76
+ @vm = @client.create_vm(:name => name, :cluster => @cluster)
77
+ @client.add_volume(@vm.id)
78
+ @client.add_interface(@vm.id, :network_name => network_name)
79
+ while !@client.vm(@vm.id).ready? do
80
+ end
81
+ end
82
+
83
+ after(:all) do
84
+ @client.destroy_vm(@vm.id)
85
+ end
86
+
87
+ it "test_should_return_a_vm" do
88
+ @client.vm(@vm.id).id.should eql(@vm.id)
89
+ end
90
+
91
+ it "test_should_update_vm" do
92
+ name = 'vmu-'+Time.now.to_i.to_s
93
+ @client.update_vm(:id => @vm.id, :name=> name, :cluster => @cluster)
94
+ end
95
+
96
+ it "test_should_start_and_stop_vm" do
97
+ @client.vm_action(@vm.id, :start)
98
+ while !@client.vm(@vm.id).running? do
99
+ end
100
+ @client.vm_action(@vm.id, :shutdown)
101
+ end
102
+ end
103
+
71
104
  describe "Admin API VM Life cycle" do
72
105
 
73
106
  before(:all) do
74
- user, password, url, datacenter = endpoint
75
- opts = {:datacenter_id => datacenter, :ca_cert_file => "#{File.dirname(__FILE__)}/../ca_cert.pem"}
76
- @client = ::OVIRT::Client.new(user, password, url, opts)
107
+ setup_client
77
108
  end
78
109
 
79
110
  context 'admin basic vm and templates operations' do
@@ -81,17 +112,24 @@ describe "Admin API VM Life cycle" do
81
112
  end
82
113
  end
83
114
 
115
+ describe "Admin API VM Life cycle without any template" do
116
+
117
+ before(:all) do
118
+ setup_client
119
+ end
120
+
121
+ context 'admin basic vm and templates operations' do
122
+ it_behaves_like "VM Life cycle without template"
123
+ end
124
+ end
125
+
84
126
  describe "User API VM Life cycle" do
85
127
 
86
128
  before(:all) do
87
- user, password, url, datacenter = endpoint
88
- opts = {:datacenter_id => datacenter,
89
- :ca_cert_file => "#{File.dirname(__FILE__)}/../ca_cert.pem",
90
- :filtered_api => support_user_level_api}
91
- @client = ::OVIRT::Client.new(user, password, url, opts)
129
+ setup_client :filtered_api => support_user_level_api
92
130
  end
93
131
 
94
132
  context 'user basic vm and templates operations' do
95
133
  it_behaves_like "Basic VM Life cycle"
96
134
  end
97
- end
135
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  require 'rspec/core'
2
2
  require 'rspec/mocks'
3
3
  require 'rbovirt'
4
+ require 'yaml'
4
5
 
5
6
  module OVIRT::RSpec
6
7
 
7
8
  # get ovirt ca certificate public key
8
9
  # * url - ovirt server url
9
- def self.ca_cert(url)
10
+ def ca_cert(url)
10
11
  ca_url = URI.parse(url)
11
12
  ca_url.path = "/ca.crt"
12
13
  http = Net::HTTP.new(ca_url.host, ca_url.port)
@@ -16,10 +17,40 @@ module OVIRT::RSpec
16
17
  http.request(request).body
17
18
  end
18
19
 
19
- end
20
+ def setup_client(options = {})
21
+ user, password, url, datacenter = endpoint
22
+ opts = {
23
+ :ca_cert_file => "#{File.dirname(__FILE__)}/ca_cert.pem"
24
+ }
25
+ @client = ::OVIRT::Client.new(user, password, url, opts)
26
+ datacenter_id = @client.datacenters.find{|x| x.name == datacenter}.id rescue raise("Cannot find datacenter #{datacenter}")
27
+ opts.merge!(:datacenter_id => datacenter_id)
28
+ opts.merge! options
29
+ @client = ::OVIRT::Client.new(user, password, url, opts)
30
+ end
31
+
32
+ def endpoint
33
+ return config['user'], config['password'], config['url'], config['datacenter']
34
+ end
20
35
 
21
- require "#{File.dirname(__FILE__)}/lib/endpoint"
36
+ def cluster_name
37
+ config['cluster'] || 'Default'
38
+ end
39
+
40
+ def network_name
41
+ config['network'] || 'ovirtmgmt'
42
+ end
43
+
44
+ def support_user_level_api
45
+ config['version'] && config['version'] > 3.1
46
+ end
47
+
48
+ def config
49
+ @config ||= YAML.load(File.read(File.expand_path("endpoint.yml", File.dirname(__FILE__))))
50
+ end
51
+
52
+ end
22
53
 
23
54
  RSpec.configure do |config|
24
- config.include OVIRT::RSpec::Endpoint
55
+ config.include OVIRT::RSpec
25
56
  end
metadata CHANGED
@@ -1,88 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbovirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Benari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: shoulda
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: ! ' A Ruby client for oVirt REST API
84
-
85
- '
83
+ description: |2
84
+ A Ruby client for oVirt REST API
86
85
  email:
87
86
  - abenari@redhat.com
88
87
  executables: []
@@ -90,8 +89,8 @@ extensions: []
90
89
  extra_rdoc_files:
91
90
  - README.rdoc
92
91
  files:
93
- - .document
94
- - .gitignore
92
+ - ".document"
93
+ - ".gitignore"
95
94
  - Gemfile
96
95
  - LICENSE.txt
97
96
  - README.rdoc
@@ -121,7 +120,6 @@ files:
121
120
  - spec/endpoint.yml.example
122
121
  - spec/integration/api_spec.rb
123
122
  - spec/integration/vm_crud_spec.rb
124
- - spec/lib/endpoint.rb
125
123
  - spec/spec_helper.rb
126
124
  - spec/unit/client_spec.rb
127
125
  - spec/unit/vm_spec.rb
@@ -130,22 +128,22 @@ licenses: []
130
128
  metadata: {}
131
129
  post_install_message:
132
130
  rdoc_options:
133
- - --title
131
+ - "--title"
134
132
  - rbovirt
135
- - --main
133
+ - "--main"
136
134
  - README.rdoc
137
- - --line-numbers
138
- - --inline-source
135
+ - "--line-numbers"
136
+ - "--inline-source"
139
137
  require_paths:
140
138
  - lib
141
139
  required_ruby_version: !ruby/object:Gem::Requirement
142
140
  requirements:
143
- - - ! '>='
141
+ - - ">="
144
142
  - !ruby/object:Gem::Version
145
143
  version: '0'
146
144
  required_rubygems_version: !ruby/object:Gem::Requirement
147
145
  requirements:
148
- - - ! '>='
146
+ - - ">="
149
147
  - !ruby/object:Gem::Version
150
148
  version: '0'
151
149
  requirements: []
@@ -158,7 +156,6 @@ test_files:
158
156
  - spec/endpoint.yml.example
159
157
  - spec/integration/api_spec.rb
160
158
  - spec/integration/vm_crud_spec.rb
161
- - spec/lib/endpoint.rb
162
159
  - spec/spec_helper.rb
163
160
  - spec/unit/client_spec.rb
164
161
  - spec/unit/vm_spec.rb
data/spec/lib/endpoint.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'yaml'
2
- module OVIRT::RSpec::Endpoint
3
-
4
- def endpoint
5
- return config['user'], config['password'], config['url'] , config['datacenter']
6
- end
7
-
8
- def network_name
9
- config['network'] || 'ovirtmgmt'
10
- end
11
-
12
- def support_user_level_api
13
- config['version'] && config['version'] > 3.1
14
- end
15
-
16
- def config
17
- @config ||= YAML.load(File.read(File.expand_path("../endpoint.yml", File.dirname(__FILE__))))
18
- end
19
-
20
- end