rbovirt 0.1.2 → 0.1.3

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: 176f8a221ec21197b316ac5b673573649353db2e
4
- data.tar.gz: b0d2e1cd49e4013cd1a22cd0f1dac7ad5ce599f1
3
+ metadata.gz: af1cb013363d659b947761e3e38126834c084042
4
+ data.tar.gz: c4ac3c8988f2951bd0eb99e38a5a4db7e219be60
5
5
  SHA512:
6
- metadata.gz: 6646f08fe9c3faba1af5234a7807f315198cc76fc32d5ed2355f7c27ee042a6a08a94f4f729d18fe7e4e70cefdb7e83667ebe2a6560810bb3d99e23544722ff0
7
- data.tar.gz: f91d2c1333728938ec6fdb47eab1c6c262cea1196bf60ba5c7165ebcc2f2ba1024226ce8aa1b4eac660308bff10292f2d8b8f60bab1948029834768b1964ae25
6
+ metadata.gz: 46c76b24ab5c95762920ddea7c1a44fee65df4fe951b1a4e1fbc9307d3993178e8f7cf87d63c8e87e9ccf8a7da318905a7b8d10ad80c72e0ca754b8d457fb6fd
7
+ data.tar.gz: 751efa86aebe75dda8afd43dca666ad23ba1d1958734ff7d9f7715a1c22685ea06387e4f262195d63f02b65ada7b246625099b80c2499656791ec76a4ce04b06
@@ -1,6 +1,6 @@
1
1
  module OVIRT
2
2
  class Network < BaseObject
3
- attr_reader :description, :datacenter, :cluster, :stp, :status
3
+ attr_reader :description, :datacenter, :cluster, :vlan_id, :mtu, :stp, :usages, :status
4
4
 
5
5
  def initialize(client, xml)
6
6
  super(client, xml[:id], xml[:href], (xml/'name').first.text)
@@ -13,6 +13,9 @@ module OVIRT
13
13
  def parse_xml_attributes!(xml)
14
14
  @description = ((xml/'description').first.text rescue nil)
15
15
  @stp = ((xml/'stp').first.text rescue false)
16
+ @mtu = ((xml/'mtu').first.text rescue nil)
17
+ @vlan_id = ((xml/'vlan').first[:id] rescue nil)
18
+ @usages = ((xml/'usages/usage').collect{ |usage| usage.text } rescue [])
16
19
  @datacenter = Link::new(@client, (xml/'data_center').first[:id], (xml/'data_center').first[:href]) unless (xml/'data_center').empty?
17
20
  @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href]) unless (xml/'cluster').empty?
18
21
  @status = ((xml/'status/state').first.text rescue nil)
@@ -1,3 +1,3 @@
1
1
  module OVIRT
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -4,7 +4,7 @@ module OVIRT
4
4
  FILEINJECT_PATH = "user-data.txt"
5
5
 
6
6
  class VM < BaseObject
7
- attr_reader :description, :status, :memory, :profile, :display, :host, :cluster, :template
7
+ attr_reader :description, :status, :memory, :profile, :display, :host, :cluster, :template, :instance_type
8
8
  attr_reader :storage, :cores, :creation_time, :os, :ha, :ha_priority, :ips, :vnc, :quota, :clone
9
9
  attr_accessor :comment, :interfaces, :volumes
10
10
 
@@ -61,6 +61,9 @@ module OVIRT
61
61
  else
62
62
  template_{name_('Blank')}
63
63
  end
64
+ if opts[:instance_type] && !opts[:instance_type].empty?
65
+ instance_type( :id => opts[:instance_type])
66
+ end
64
67
  if opts[:quota]
65
68
  quota_( :id => opts[:quota])
66
69
  end
@@ -260,15 +263,15 @@ module OVIRT
260
263
  }
261
264
  end
262
265
  dns {
263
- unless dns.nil?
264
- servers {
265
- dns.each do |dnsentry|
266
- host { address dnsentry }
267
- end
268
- }
266
+ if dns.is_a?(String)
267
+ servers { host { address dns }}
268
+ elsif dns.is_a?(Array) && dns.all? {|n| n.is_a?(String) }
269
+ servers { host { address dns.join(' ') }}
269
270
  end
270
- unless domain.nil?
271
+ if domain.is_a?(String)
271
272
  search_domains { host { address domain }}
273
+ elsif domain.is_a?(Array) && domain.all? {|n| n.is_a?(String) }
274
+ search_domains { host { address domain.join(' ')}}
272
275
  end
273
276
  }
274
277
  }
@@ -308,6 +311,7 @@ module OVIRT
308
311
  @memory = (xml/'memory').first.text
309
312
  @profile = (xml/'type').first.text
310
313
  @template = Link::new(@client, (xml/'template').first[:id], (xml/'template').first[:href])
314
+ @instance_type = Link::new(@client, (xml/'instance_type').first[:id], (xml/'instance_type').first[:href]) rescue nil
311
315
  @host = Link::new(@client, (xml/'host').first[:id], (xml/'host').first[:href]) rescue nil
312
316
  @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
313
317
  @display = {
@@ -119,6 +119,30 @@ shared_examples_for "VM Life cycle without template" do
119
119
  end
120
120
  end
121
121
 
122
+ describe "Basic VM creation with instance type" do
123
+ before(:all) do
124
+ setup_client
125
+ @name = 'vm-'+Time.now.to_i.to_s
126
+ @cluster = @client.clusters.select{|c| c.name == cluster_name}.first.id
127
+ if @config['instance_type']
128
+ @instance_type = @client.instance_type(@config['instance_type'])
129
+ else
130
+ @instance_type = @client.instance_types.first
131
+ end
132
+ end
133
+
134
+ it "test_should_create_vm_with_instance_type" do
135
+ if @instance_type
136
+ @vm = @client.create_vm(:name => @name, :instance_type => @instance_type.id, :cluster => @cluster)
137
+ @vm.should_not be_nil
138
+ while !@client.vm(@vm.id).ready? do
139
+ end
140
+ @client.destroy_vm(@vm.id) if @vm
141
+ else
142
+ skip "No instance type found, skip VM creation based on instance type"
143
+ end
144
+ end
145
+ end
122
146
 
123
147
  describe "Admin API VM Life cycle" do
124
148
 
@@ -107,6 +107,68 @@ describe OVIRT::VM do
107
107
  </vm>
108
108
  END_HEREDOC
109
109
 
110
+ @min_instance_type_xml = <<END_HEREDOC
111
+ <vm id="76d29095-bc27-4cd0-8178-07e942aea549" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549">
112
+ <name>c-1326980484</name>
113
+ <actions>
114
+ <link rel="shutdown" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/shutdown"/>
115
+ <link rel="start" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/start"/>
116
+ <link rel="stop" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/stop"/>
117
+ <link rel="suspend" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/suspend"/>
118
+ <link rel="detach" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/detach"/>
119
+ <link rel="export" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/export"/>
120
+ <link rel="move" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/move"/>
121
+ <link rel="ticket" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/ticket"/>
122
+ <link rel="migrate" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/migrate"/>
123
+ <link rel="cancelmigration" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/cancelmigration"/>
124
+ </actions>
125
+ <link rel="disks" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/disks"/>
126
+ <link rel="nics" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/nics"/>
127
+ <link rel="cdroms" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/cdroms"/>
128
+ <link rel="snapshots" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/snapshots"/>
129
+ <link rel="tags" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/tags"/>
130
+ <link rel="permissions" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/permissions"/>
131
+ <link rel="statistics" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/statistics"/>
132
+ <type>server</type>
133
+ <status>
134
+ <state>up</state>
135
+ </status>
136
+ <memory>536870912</memory>
137
+ <cpu>
138
+ <topology cores="1" sockets="1"/>
139
+ </cpu>
140
+ <os type="unassigned">
141
+ <boot dev="network"/>
142
+ <boot dev="hd"/>
143
+ </os>
144
+ <high_availability>
145
+ <enabled>false</enabled>
146
+ <priority>0</priority>
147
+ </high_availability>
148
+ <display>
149
+ <type>vnc</type>
150
+ <monitors>1</monitors>
151
+ </display>
152
+ <cluster id="b68980dc-3ab8-11e1-bcbf-5254005f0f6f" href="/api/clusters/b68980dc-3ab8-11e1-bcbf-5254005f0f6f"/>
153
+ <template id="00000000-0000-0000-0000-000000000000" href="/api/templates/00000000-0000-0000-0000-000000000000"/>
154
+ <instance_type id="00000000-0000-0000-0000-000000000001" href="/api/instancetypes/00000000-0000-0000-0000-000000000001"/>
155
+ <start_time>2012-01-19T14:41:58.428Z</start_time>
156
+ <creation_time>2012-01-19T13:41:24.405Z</creation_time>
157
+ <origin>rhev</origin>
158
+ <stateless>false</stateless>
159
+ <placement_policy>
160
+ <affinity>migratable</affinity>
161
+ </placement_policy>
162
+ <memory_policy>
163
+ <guaranteed>536870912</guaranteed>
164
+ </memory_policy>
165
+ <usb>
166
+ <enabled>true</enabled>
167
+ </usb>
168
+ </vm>
169
+ END_HEREDOC
170
+
171
+
110
172
  @min_xml = <<END_HEREDOC
111
173
  <vm id="76d29095-bc27-4cd0-8178-07e942aea549" href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549">
112
174
  <name>c-1326980484</name>
@@ -276,6 +338,24 @@ END_HEREDOC
276
338
  Nokogiri::XML(xml).xpath("//disks/disk/storage_domains/storage_domain[contains(@id,'#{storagedomain}')]").length.should eql(1)
277
339
  end
278
340
 
341
+ it "create vm xml without instance_type" do
342
+ opts = {:cluster_name=>'cluster'}
343
+ xml = OVIRT::VM.to_xml(opts)
344
+ xml.nil?.should eql(false)
345
+ Nokogiri::XML(xml).xpath("//instance_type").length.should eql(0)
346
+ end
347
+
348
+ it "create vm xml with instance_type" do
349
+ instance_type = "00000000-0000-0000-0000-000000000001"
350
+ opts = {:cluster_name => 'cluster', :instance_type => instance_type}
351
+ xml = OVIRT::VM.to_xml(opts)
352
+ puts xml
353
+ xml.nil?.should eql(false)
354
+ Nokogiri::XML(xml).xpath("//instance_type").length.should eql(1)
355
+ Nokogiri::XML(xml).xpath("//instance_type[contains(@id,'#{instance_type}')]").length.should eql(1)
356
+ end
357
+
358
+
279
359
  it "should be running" do
280
360
  vm = OVIRT::VM.new(nil, Nokogiri::XML(@xml).xpath('/').first)
281
361
  vm.running?.should eql(true)
@@ -303,6 +383,11 @@ END_HEREDOC
303
383
  disk.interface.should eql('virtio')
304
384
  end
305
385
 
386
+ it "should have instance_type" do
387
+ vm = OVIRT::VM.new(nil, Nokogiri::XML(@min_instance_type_xml).xpath('/').first)
388
+ vm.instance_type.id.should eql('00000000-0000-0000-0000-000000000001')
389
+ end
390
+
306
391
  it "should still fallback to the client" do
307
392
  vm = OVIRT::VM.new(@mock_client, Nokogiri::XML(@min_xml).xpath('/').first)
308
393
  vm.volumes.length.should eql(1)
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Benari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-18 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri