rbovirt 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9848bea2f871ad9d719fe767623cb5a90693e1a6
4
- data.tar.gz: bb231cd4f28257c2bae9d76cc721be3d39e5c705
3
+ metadata.gz: b97753a15261f2aefe05f131f10919c4e4462b86
4
+ data.tar.gz: e11ea2283df23bc959a966d4c3f0b5a48a60a25b
5
5
  SHA512:
6
- metadata.gz: 0c08516ba05303b32daeee352a0ca5230447b820bbf4e781248af4bfbc01b8dfd3cf6d9c0385fee0cfa7ad2e0a3359a377be5793ca87ab82c1d505cd457ca15a
7
- data.tar.gz: 00b59b5b92ebdb2f889b0dc7b6e0b0745ba0dc143cfabd7ea986e4f59c747981975a316048ab88664d14d9210e4ed2578f9f83f35a91bf1aa879381917e3e0c7
6
+ metadata.gz: 254c0845f58a8c0c81cdfd092d83138bb9347aeee338606e283e8d91d9f8791533e9bda06804b487d57e38dc722c982872a6982bfbbb73c064a725364454676e
7
+ data.tar.gz: 98637488a24997cc47b4ab67384b7b5994841fb953e1ca72bf9154dc129973e5418d07662445b12ba106e23df6510be4dca7d8f6b1b77bacb18db98c22a79d72
data/.gitignore CHANGED
@@ -54,3 +54,6 @@ pkg
54
54
 
55
55
  # For rubinius:
56
56
  #*.rbc
57
+
58
+ # Ignore generated .gem files:
59
+ *.gem
@@ -6,6 +6,13 @@ _rbovirt_ project.
6
6
  Note that this list of changes was added with the 0.0.30 release,
7
7
  previous releases aren't described here.
8
8
 
9
+ == 0.0.31 / 2014-12-11
10
+
11
+ New features:
12
+
13
+ * Added support for starting virtual machines with _cloud-init_, using
14
+ the new +vm_start_with_cloud_init+ method of the client class.
15
+
9
16
  == 0.0.30 / 2014-11-25
10
17
 
11
18
  New features:
@@ -97,6 +97,12 @@ module OVIRT
97
97
  return (xml_response/'action/status').first.text.strip.upcase=="COMPLETE"
98
98
  end
99
99
 
100
+ def vm_start_with_cloudinit(id, opts={})
101
+ xml = OVIRT::VM.cloudinit(opts)
102
+ xml_response = http_post("/vms/%s/%s" % [id, 'start'], xml, {} )
103
+ return (xml_response/'action/status').first.text.strip.upcase=="COMPLETE"
104
+ end
105
+
100
106
  def destroy_vm(id)
101
107
  http_delete("/vms/%s" % id)
102
108
  end
@@ -1,3 +1,3 @@
1
1
  module OVIRT
2
- VERSION = "0.0.30"
2
+ VERSION = "0.0.31"
3
3
  end
@@ -108,6 +108,124 @@ module OVIRT
108
108
  Nokogiri::XML(builder.to_xml).root.to_s
109
109
  end
110
110
 
111
+ def self.cloudinit(opts={})
112
+ hostname = opts[:hostname]
113
+ ip = opts[:ip]
114
+ netmask = opts[:netmask]
115
+ dns = opts[:dns]
116
+ gateway = opts[:gateway]
117
+ domain = opts[:domain]
118
+ nicname = opts[:nicname]
119
+ password = opts[:password]
120
+ ssh_authorized_keys = opts[:ssh_authorized_keys]
121
+ fileslist = opts[:files]
122
+ runcmd = opts[:runcmd]
123
+ unless opts[:phone_home].nil?
124
+ phone_home = \
125
+ "phone_home\n" \
126
+ " url: #{opts[:phone_home]['url']}\n" \
127
+ " post: #{opts[:phone_home]['post']}\n"
128
+ end
129
+ cmdlist = 'runcmd:'
130
+ unless runcmd.nil?
131
+ runcmd.each do |cmd|
132
+ cmdlist = \
133
+ "#{cmdlist}\n" \
134
+ "- #{cmd}\n"
135
+ end
136
+ end
137
+ builder = Nokogiri::XML::Builder.new do
138
+ action {
139
+ vm {
140
+ initialization {
141
+ unless runcmd.nil?
142
+ custom_script cmdlist
143
+ end
144
+ unless phone_home.nil?
145
+ custom_script phone_home
146
+ end
147
+ cloud_init {
148
+ unless hostname.nil?
149
+ host { address hostname }
150
+ end
151
+ unless password.nil?
152
+ users {
153
+ user {
154
+ user_name 'root'
155
+ password password
156
+ }
157
+ }
158
+ end
159
+ unless ssh_authorized_keys.nil?
160
+ authorized_keys {
161
+ authorized_key {
162
+ user { user_name 'root' }
163
+ ssh_authorized_keys.each do |sshkey|
164
+ key sshkey
165
+ end
166
+ }
167
+ }
168
+ end
169
+ network_configuration {
170
+ unless nicname.nil?
171
+ nics {
172
+ nic {
173
+ name_ nicname
174
+ unless ip.nil? || netmask.nil? || gateway.nil?
175
+ network { ip(:'address'=> ip , :'netmask'=> netmask, :'gateway'=> gateway ) }
176
+ boot_protocol 'STATIC'
177
+ on_boot 'true'
178
+ end
179
+ }
180
+ }
181
+ end
182
+ dns {
183
+ unless dns.nil?
184
+ servers {
185
+ dns.each do |dnsentry|
186
+ host { address dnsentry }
187
+ end
188
+ }
189
+ end
190
+ unless domain.nil?
191
+ search_domains { host { address domain }}
192
+ end
193
+ }
194
+ }
195
+ regenerate_ssh_keys 'true'
196
+ files {
197
+ unless runcmd.nil?
198
+ file {
199
+ name_ 'ignored'
200
+ content cmdlist
201
+ type 'PLAINTEXT'
202
+ }
203
+ end
204
+ unless phone_home.nil?
205
+ file {
206
+ name_ 'ignored'
207
+ content phone_home
208
+ type 'PLAINTEXT'
209
+ }
210
+ end
211
+ unless fileslist.nil?
212
+ fileslist.each do |fileentry|
213
+ file {
214
+ name_ fileentry['path']
215
+ content fileentry['content']
216
+ type 'PLAINTEXT'
217
+ }
218
+ end
219
+ end
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ end
226
+ Nokogiri::XML(builder.to_xml).root.to_xml
227
+ end
228
+
111
229
  private
112
230
 
113
231
  def parse_xml_attributes!(xml)
@@ -149,3 +267,4 @@ module OVIRT
149
267
 
150
268
  end
151
269
  end
270
+
@@ -149,12 +149,13 @@ module OVIRT
149
149
 
150
150
  def rest_client(suburl)
151
151
  if (URI.parse(@api_entrypoint)).scheme == 'https'
152
- verify_options = {}
153
- verify_options[:verify_ssl] = ca_no_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
154
- verify_options[:ssl_cert_store] = ca_cert_store if ca_cert_store
155
- verify_options[:ssl_ca_file] = ca_cert_file if ca_cert_file
152
+ options = {}
153
+ options[:verify_ssl] = ca_no_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
154
+ options[:ssl_cert_store] = ca_cert_store if ca_cert_store
155
+ options[:ssl_ca_file] = ca_cert_file if ca_cert_file
156
156
  end
157
- RestClient::Resource.new(@api_entrypoint, verify_options)[suburl]
157
+ options[:timeout] = ENV['RBOVIRT_REST_TIMEOUT'] if ENV['RBOVIRT_REST_TIMEOUT']
158
+ RestClient::Resource.new(@api_entrypoint, options)[suburl]
158
159
  end
159
160
 
160
161
  def filter_header
@@ -6,6 +6,7 @@ require 'ovirt/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "rbovirt"
8
8
  gem.version = OVIRT::VERSION
9
+ gem.license = "MIT"
9
10
  gem.authors = ['Amos Benari']
10
11
  gem.email = ['abenari@redhat.com']
11
12
  gem.homepage = "http://github.com/abenari/rbovirt"
@@ -41,6 +41,15 @@ shared_examples_for "Basic VM Life cycle" do
41
41
  @client.vm_action(@vm.id, :shutdown)
42
42
  end
43
43
 
44
+ it "test_should_start_with_cloudinit" do
45
+ hostname = "host-"+Time.now.to_i.to_s
46
+ user_data={ :hostname => hostname }
47
+ @client.vm_start_with_cloudinit(@vm.id, user_data)
48
+ while !@client.vm(@vm.id).running? do
49
+ end
50
+ @client.vm_action(@vm.id, :shutdown)
51
+ end
52
+
44
53
  it "test_should_set_vm_ticket" do
45
54
  @client.vm_action(@vm.id, :start)
46
55
  while !@client.vm(@vm.id).running? do
@@ -1,6 +1,9 @@
1
+ require 'openssl'
2
+ require 'rbovirt'
1
3
  require 'rspec/core'
2
4
  require 'rspec/mocks'
3
- require 'rbovirt'
5
+ require 'socket'
6
+ require 'uri'
4
7
  require 'yaml'
5
8
 
6
9
  module OVIRT::RSpec
@@ -8,13 +11,20 @@ module OVIRT::RSpec
8
11
  # get ovirt ca certificate public key
9
12
  # * url - ovirt server url
10
13
  def ca_cert(url)
11
- ca_url = URI.parse(url)
12
- ca_url.path = "/ca.crt"
13
- http = Net::HTTP.new(ca_url.host, ca_url.port)
14
- http.use_ssl = (ca_url.scheme == 'https')
15
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
- request = Net::HTTP::Get.new(ca_url.path)
17
- http.request(request).body
14
+ parsed_url = URI.parse url
15
+ begin
16
+ tcp_socket = TCPSocket.open parsed_url.host, parsed_url.port
17
+ ssl_socket = OpenSSL::SSL::SSLSocket.new tcp_socket
18
+ ssl_socket.connect
19
+ ssl_socket.peer_cert_chain.last.to_pem
20
+ ensure
21
+ unless ssl_socket.nil?
22
+ ssl_socket.close
23
+ end
24
+ unless tcp_socket.nil?
25
+ tcp_socket.close
26
+ end
27
+ end
18
28
  end
19
29
 
20
30
  def setup_client(options = {})
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.30
4
+ version: 0.0.31
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-11-25 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -126,7 +126,8 @@ files:
126
126
  - spec/unit/client_spec.rb
127
127
  - spec/unit/vm_spec.rb
128
128
  homepage: http://github.com/abenari/rbovirt
129
- licenses: []
129
+ licenses:
130
+ - MIT
130
131
  metadata: {}
131
132
  post_install_message:
132
133
  rdoc_options: