fog-libvirt 0.12.1 → 0.13.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -3
  3. data/fog-libvirt.gemspec +4 -5
  4. data/lib/fog/libvirt/compute.rb +9 -26
  5. data/lib/fog/libvirt/models/compute/network.rb +11 -0
  6. data/lib/fog/libvirt/models/compute/pool.rb +14 -0
  7. data/lib/fog/libvirt/models/compute/server.rb +45 -150
  8. data/lib/fog/libvirt/models/compute/util/util.rb +2 -10
  9. data/lib/fog/libvirt/models/compute/volume.rb +41 -2
  10. data/lib/fog/libvirt/requests/compute/clone_volume.rb +7 -5
  11. data/lib/fog/libvirt/requests/compute/create_domain.rb +6 -4
  12. data/lib/fog/libvirt/requests/compute/create_volume.rb +6 -3
  13. data/lib/fog/libvirt/requests/compute/define_domain.rb +6 -4
  14. data/lib/fog/libvirt/requests/compute/define_pool.rb +6 -3
  15. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +6 -4
  16. data/lib/fog/libvirt/requests/compute/destroy_network.rb +6 -4
  17. data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +4 -5
  18. data/lib/fog/libvirt/requests/compute/get_node_info.rb +6 -3
  19. data/lib/fog/libvirt/requests/compute/libversion.rb +6 -4
  20. data/lib/fog/libvirt/requests/compute/list_domains.rb +27 -31
  21. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +6 -14
  22. data/lib/fog/libvirt/requests/compute/list_networks.rb +6 -24
  23. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +6 -3
  24. data/lib/fog/libvirt/requests/compute/list_pools.rb +20 -42
  25. data/lib/fog/libvirt/requests/compute/list_volumes.rb +16 -36
  26. data/lib/fog/libvirt/requests/compute/pool_action.rb +6 -4
  27. data/lib/fog/libvirt/requests/compute/update_autostart.rb +6 -4
  28. data/lib/fog/libvirt/requests/compute/update_display.rb +6 -5
  29. data/lib/fog/libvirt/requests/compute/upload_volume.rb +6 -3
  30. data/lib/fog/libvirt/requests/compute/vm_action.rb +6 -4
  31. data/lib/fog/libvirt/requests/compute/volume_action.rb +6 -4
  32. data/lib/fog/libvirt/version.rb +1 -1
  33. data/minitests/test_helper.rb +1 -1
  34. data/tests/helper.rb +1 -1
  35. data/tests/helpers/formats_helper.rb +3 -2
  36. data/tests/helpers/formats_helper_tests.rb +8 -8
  37. data/tests/helpers/mock_helper.rb +1 -1
  38. data/tests/libvirt/models/compute/network_tests.rb +14 -2
  39. data/tests/libvirt/models/compute/nic_tests.rb +2 -1
  40. data/tests/libvirt/models/compute/pools_tests.rb +6 -6
  41. data/tests/libvirt/models/compute/server_tests.rb +53 -3
  42. data/tests/libvirt/models/compute/volume_tests.rb +21 -1
  43. data/tests/libvirt/models/compute/volumes_tests.rb +2 -0
  44. data/tests/libvirt/requests/compute/list_pools_tests.rb +1 -1
  45. metadata +38 -43
  46. data/lib/fog/libvirt/models/compute/templates/network.xml.erb +0 -6
  47. data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +0 -6
  48. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +0 -34
  49. data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +0 -40
  50. data/minitests/server/server_test.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12e7867890312a401d0733ed3bd058c7bfba0488d32748569d6de134e516a752
4
- data.tar.gz: 1e37605f3bd9fee08a79d18d4383bcb68f38d88675f12ead62b6366afc1c0a60
3
+ metadata.gz: 4f599806341a157d51f1d560bd4ae124da48172f9e6f3273892e4b219dd9ff22
4
+ data.tar.gz: 95035f1e61df4bd437502cf1489eddde02718d0f38f0061087a9068a1e334ce0
5
5
  SHA512:
6
- metadata.gz: 6c5a173e6974eaa247bad12a3d3cacd10a43a1679dba49a361eb179e6a2a5d58ed12dacdab08b25c24ea49d05024f26b6c9564a2fb8fbf95be3e0500af6447c5
7
- data.tar.gz: cb7536c410f12da3549d328e19dd6f997f0a3ae4795a90d6eea576bcca8e79a0c7a086ec8dc6b85c84e860d93ba70109d13cd3a0684769eec4991ff0c5311592
6
+ metadata.gz: 5fd5999bb19e032e6fd20fd89e6a8f690a1e9f1ead269b8517a6d7f4a8c6835d4ce17c930791dcecae17a376351c8357e707824ee2cb53a81a868add8071dd9c
7
+ data.tar.gz: b19806eb8d0f066c9456d77f09b394f36587c94ea5ab8507be1e6248a5c6e6008d101b7827907f72b4c016b73465ee2089d7df6a724335bf9f50dda668a08d66
data/Gemfile CHANGED
@@ -6,7 +6,4 @@ group :development, :test do
6
6
  gem "octokit", :require => false
7
7
  end
8
8
 
9
- # 0.8.3 breaks our tests
10
- gem "ruby-libvirt", ">= 0.7.0", "< 0.8.3"
11
-
12
9
  gemspec
data/fog-libvirt.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "fog/libvirt/version"
@@ -23,23 +22,23 @@ Gem::Specification.new do |s|
23
22
  s.rdoc_options = ["--charset=UTF-8"]
24
23
  s.extra_rdoc_files = %w[README.md]
25
24
 
26
- s.required_ruby_version = '>= 2.5.0'
25
+ s.required_ruby_version = '>= 2.7'
27
26
 
28
27
  s.add_dependency("fog-core", ">= 1.27.4")
29
28
  s.add_dependency("fog-json")
30
29
  s.add_dependency("fog-xml", "~> 0.1.1")
31
- s.add_dependency('ruby-libvirt','>= 0.7.0')
32
30
  s.add_dependency("json")
31
+ s.add_dependency('ruby-libvirt','>= 0.7.0')
33
32
 
34
- s.add_development_dependency("net-ssh")
35
33
  s.add_development_dependency("minitest", "~> 5.0")
34
+ s.add_development_dependency("mocha", ">= 1.15", "< 3")
35
+ s.add_development_dependency("net-ssh")
36
36
  s.add_development_dependency("pry")
37
37
  s.add_development_dependency("rake")
38
38
  s.add_development_dependency("rubocop")
39
39
  s.add_development_dependency("shindo", "~> 0.3.4")
40
40
  s.add_development_dependency("simplecov")
41
41
  s.add_development_dependency("yard")
42
- s.add_development_dependency("mocha", ">= 1.15", "< 3")
43
42
 
44
43
  # Let's not ship dot files and gemfiles
45
44
  git_files = `git ls-files`.split("\n")
@@ -6,7 +6,6 @@ module Fog
6
6
  class Compute < Fog::Service
7
7
  requires :libvirt_uri
8
8
  recognizes :libvirt_username, :libvirt_password
9
- recognizes :libvirt_ip_command
10
9
 
11
10
  model_path 'fog/libvirt/models/compute'
12
11
  model :server
@@ -50,37 +49,13 @@ module Fog
50
49
 
51
50
  module Shared
52
51
  include Fog::Libvirt::Util
53
- end
54
-
55
- class Mock
56
- include Shared
57
- def initialize(options={})
58
- # libvirt is part of the gem => ruby-libvirt
59
- require 'libvirt'
60
- end
61
-
62
- private
63
-
64
- def client
65
- return @client if defined?(@client)
66
- end
67
52
 
68
- #read mocks xml
69
- def read_xml(file_name)
70
- file_path = File.join(File.dirname(__FILE__),"requests","compute","mock_files",file_name)
71
- File.read(file_path)
72
- end
73
- end
74
-
75
- class Real
76
- include Shared
77
53
  attr_reader :client
78
54
  attr_reader :uri
79
- attr_reader :ip_command
80
55
 
81
56
  def initialize(options={})
57
+ super()
82
58
  @uri = ::Fog::Libvirt::Util::URI.new(enhance_uri(options[:libvirt_uri]))
83
- @ip_command = options[:libvirt_ip_command]
84
59
 
85
60
  # libvirt is part of the gem => ruby-libvirt
86
61
  begin
@@ -135,6 +110,14 @@ module Fog
135
110
  uri+append
136
111
  end
137
112
  end
113
+
114
+ class Real
115
+ include Shared
116
+ end
117
+
118
+ class Mock
119
+ include Shared
120
+ end
138
121
  end
139
122
  end
140
123
  end
@@ -27,6 +27,17 @@ module Fog
27
27
  def shutdown
28
28
  service.destroy_network(uuid)
29
29
  end
30
+
31
+ def to_xml
32
+ builder = Nokogiri::XML::Builder.new do |xml|
33
+ xml.network do
34
+ xml.name(name)
35
+ xml.bridge(:name => bridge_name, :stp => 'on', :delay => '0')
36
+ end
37
+ end
38
+
39
+ builder.to_xml
40
+ end
30
41
  end
31
42
  end
32
43
  end
@@ -78,6 +78,20 @@ module Fog
78
78
  def volumes
79
79
  service.list_pool_volumes uuid
80
80
  end
81
+
82
+ def to_xml
83
+ builder = Nokogiri::XML::Builder.new do |xml|
84
+ xml.pool(:type => 'dir') do
85
+ xml.name(name)
86
+
87
+ xml.target do
88
+ xml.path(path)
89
+ end
90
+ end
91
+ end
92
+
93
+ builder.to_xml
94
+ end
81
95
  end
82
96
  end
83
97
  end
@@ -13,6 +13,10 @@ module Fog
13
13
 
14
14
  attribute :cpus
15
15
  attribute :cputime
16
+ attribute :firmware
17
+ attribute :firmware_features
18
+ attribute :secure_boot
19
+ attribute :loader_attributes
16
20
  attribute :os_type
17
21
  attribute :memory_size
18
22
  attribute :max_memory_size
@@ -30,6 +34,7 @@ module Fog
30
34
  attribute :cpu
31
35
  attribute :hugepages
32
36
  attribute :guest_agent
37
+ attribute :video
33
38
  attribute :virtio_rng
34
39
 
35
40
  attribute :state
@@ -83,7 +88,7 @@ module Fog
83
88
  end
84
89
 
85
90
  def mac
86
- nics.first.mac if nics && nics.first
91
+ nics&.first&.mac
87
92
  end
88
93
 
89
94
  def disk_path
@@ -96,6 +101,10 @@ module Fog
96
101
  if flags.zero?
97
102
  service.vm_action(uuid, :undefine)
98
103
  else
104
+ # the test driver doesn't support UNDEFINE_NVRAM
105
+ if service.uri.driver == 'test'
106
+ flags ^= ::Libvirt::Domain::UNDEFINE_NVRAM
107
+ end
99
108
  service.vm_action(uuid, :undefine, flags)
100
109
  end
101
110
  volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
@@ -282,14 +291,31 @@ module Fog
282
291
  end
283
292
 
284
293
  xml.vcpu(cpus)
285
- xml.os do
294
+ os_tags = {}
295
+
296
+ os_tags[:firmware] = firmware if firmware == 'efi'
297
+
298
+ xml.os(**os_tags) do
286
299
  type = xml.type(os_type, :arch => arch)
287
300
  type[:machine] = "q35" if ["i686", "x86_64"].include?(arch)
288
301
 
289
302
  boot_order.each do |dev|
290
303
  xml.boot(:dev => dev)
291
304
  end
305
+
306
+ loader_attributes&.each do |key, value|
307
+ xml.loader(key => value)
308
+ end
309
+
310
+ if firmware == "efi" && firmware_features&.any?
311
+ xml.firmware do
312
+ firmware_features.each_pair do |key, value|
313
+ xml.feature(:name => key, :enabled => value)
314
+ end
315
+ end
316
+ end
292
317
  end
318
+
293
319
  xml.features do
294
320
  xml.acpi
295
321
  xml.apic
@@ -302,7 +328,7 @@ module Fog
302
328
  end
303
329
  else
304
330
  xml.cpu(
305
- :mode => cpu.dig(:model, :name) || "host-passthrough",
331
+ :mode => cpu.fetch(:mode, "host-passthrough"),
306
332
  :check => cpu.fetch(:check, "none"),
307
333
  :migratable => cpu.fetch(:migratable, "on")
308
334
  )
@@ -357,14 +383,15 @@ module Fog
357
383
  xml.disk(:type => "file", :device => "cdrom") do
358
384
  xml.driver(:name => "qemu", :type => "raw")
359
385
  xml.source(:file => "#{iso_dir}/#{iso_file}")
360
- xml.target(:dev => "hdc", :bus => "ide")
386
+ xml.target(:dev => "sda", :bus => "scsi")
361
387
  xml.readonly
362
- xml.address(:type => "drive", :controller => 0, :bus => 1, :unit => 0)
388
+ xml.address(:type => "drive", :controller => 0, :bus => 0, :unit => 0)
363
389
  end
364
390
  end
365
391
 
366
392
  nics.each do |nic|
367
393
  xml.interface(:type => nic.type) do
394
+ xml.mac(:address => nic.mac) if nic.mac
368
395
  if nic.type == "bridge"
369
396
  xml.source(:bridge => nic.bridge)
370
397
  else
@@ -409,10 +436,10 @@ module Fog
409
436
  graphics.autoport = "yes"
410
437
  end
411
438
  graphics.listen = display[:listen] unless display[:listen].empty?
412
- graphics.passwd = display[:password] unless display[:password].empty?
439
+ graphics.passwd = display[:password] if display[:password] && !display[:password].empty?
413
440
 
414
441
  xml.video do
415
- xml.model(:type => "cirrus", :vram => 9216, :heads => 1)
442
+ xml.model(video)
416
443
  end
417
444
  end
418
445
  end
@@ -441,160 +468,26 @@ module Fog
441
468
  args
442
469
  end
443
470
 
444
- # This tests the library version before redefining the address
445
- # method for this instance to use a method compatible with
446
- # earlier libvirt libraries, or uses the dhcp method from more
447
- # recent releases.
448
- def addresses(service_arg=service, options={})
449
- addresses_method = self.method(:addresses_dhcp)
450
- # check if ruby-libvirt was compiled against a new enough version
451
- # that can use dhcp_leases, as otherwise it will not provide the
452
- # method dhcp_leases on any of the network objects.
453
- has_dhcp_leases = true
454
- begin
455
- service.networks.first.dhcp_leases(self.mac)
456
- rescue NoMethodError
457
- has_dhcp_leases = false
458
- rescue
459
- # assume some other odd exception.
460
- end
461
-
462
- # if ruby-libvirt not compiled with support, or remote library is
463
- # too old (must be newer than 1.2.8), then use old fallback
464
- if not has_dhcp_leases or service.libversion() < 1002008
465
- addresses_method = self.method(:addresses_ip_command)
466
- end
467
-
468
- # replace current definition for this instance with correct one for
469
- # detected libvirt to perform check once for connection
470
- (class << self; self; end).class_eval do
471
- define_method(:addresses, addresses_method)
472
- end
473
- addresses(service_arg, options)
474
- end
475
-
476
- def ssh_ip_command(ip_command, uri)
477
- # Retrieve the parts we need from the service to setup our ssh options
478
- user=uri.user #could be nil
479
- host=uri.host
480
- keyfile=uri.keyfile
481
- port=uri.port
482
-
483
- # Setup the options
484
- ssh_options={}
485
- ssh_options[:keys]=[ keyfile ] unless keyfile.nil?
486
- ssh_options[:port]=port unless keyfile.nil?
487
- ssh_options[:paranoid]=true if uri.no_verify?
488
-
489
- begin
490
- result=Fog::SSH.new(host, user, ssh_options).run(ip_command)
491
- rescue Errno::ECONNREFUSED
492
- raise Fog::Errors::Error.new("Connection was refused to host #{host} to retrieve the ip_address for #{mac}")
493
- rescue Net::SSH::AuthenticationFailed
494
- raise Fog::Errors::Error.new("Error authenticating over ssh to host #{host} and user #{user}")
495
- end
496
-
497
- # Check for a clean exit code
498
- if result.first.status == 0
499
- return result.first.stdout.strip
500
- else
501
- # We got a failure executing the command
502
- raise Fog::Errors::Error.new("The command #{ip_command} failed to execute with a clean exit code")
503
- end
504
- end
505
-
506
- def local_ip_command(ip_command)
507
- # Execute the ip_command locally
508
- # Initialize empty ip_address string
509
- ip_address=""
510
-
511
- IO.popen("#{ip_command}") do |p|
512
- p.each_line do |l|
513
- ip_address+=l
514
- end
515
- status=Process.waitpid2(p.pid)[1].exitstatus
516
- if status!=0
517
- raise Fog::Errors::Error.new("The command #{ip_command} failed to execute with a clean exit code")
518
- end
519
- end
520
-
521
- #Strip any new lines from the string
522
- ip_address.chomp
523
- end
524
-
525
- # Locale-friendly removal of non-alpha nums
526
- DOMAIN_CLEANUP_REGEXP = Regexp.compile('[\W_-]')
527
-
528
- # This retrieves the ip address of the mac address using ip_command
529
- # It returns an array of public and private ip addresses
530
- # Currently only one ip address is returned, but in the future this could be multiple
531
- # if the server has multiple network interface
532
- def addresses_ip_command(service_arg=service, options={})
533
- mac=self.mac
534
-
535
- # Aug 24 17:34:41 juno arpwatch: new station 10.247.4.137 52:54:00:88:5a:0a eth0.4
536
- # Aug 24 17:37:19 juno arpwatch: changed ethernet address 10.247.4.137 52:54:00:27:33:00 (52:54:00:88:5a:0a) eth0.4
537
- # Check if another ip_command string was provided
538
- ip_command_global=service_arg.ip_command.nil? ? 'grep $mac /var/log/arpwatch.log|sed -e "s/new station//"|sed -e "s/changed ethernet address//g" |sed -e "s/reused old ethernet //" |tail -1 |cut -d ":" -f 4-| cut -d " " -f 3' : service_arg.ip_command
539
- ip_command_local=options[:ip_command].nil? ? ip_command_global : options[:ip_command]
540
-
541
- ip_command="mac=#{mac}; server_name=#{name.gsub(DOMAIN_CLEANUP_REGEXP, '_')}; "+ip_command_local
542
-
543
- ip_address=nil
544
-
545
- if service_arg.uri.ssh_enabled?
546
- ip_address=ssh_ip_command(ip_command, service_arg.uri)
547
- else
548
- # It's not ssh enabled, so we assume it is
549
- if service_arg.uri.transport=="tls"
550
- raise Fog::Errors::Error.new("TlS remote transport is not currently supported, only ssh")
551
- end
552
- ip_address=local_ip_command(ip_command)
553
- end
554
-
555
- # The Ip-address command has been run either local or remote now
556
-
557
- if ip_address==""
558
- #The grep didn't find an ip address result"
559
- ip_address=nil
560
- else
561
- # To be sure that the command didn't return another random string
562
- # We check if the result is an actual ip-address
563
- # otherwise we return nil
564
- unless ip_address=~/^(\d{1,3}\.){3}\d{1,3}$/
565
- raise Fog::Errors::Error.new(
566
- "The result of #{ip_command} does not have valid ip-address format\n"+
567
- "Result was: #{ip_address}\n"
568
- )
569
- end
570
- end
571
-
572
- return { :public => [ip_address], :private => [ip_address]}
573
- end
574
-
575
471
  # This retrieves the ip address of the mac address using dhcp_leases
576
472
  # It returns an array of public and private ip addresses
577
473
  # Currently only one ip address is returned, but in the future this could be multiple
578
474
  # if the server has multiple network interface
579
- def addresses_dhcp(service_arg=service, options={})
580
- mac=self.mac
581
-
475
+ def addresses(service_arg=service, options={})
582
476
  ip_address = nil
583
- nic = self.nics.find {|nic| nic.mac==mac}
584
- if !nic.nil?
477
+ if (nic = self.nics&.first)
585
478
  net = service.networks.all(:name => nic.network).first
586
- if !net.nil?
587
- leases = net.dhcp_leases(mac, 0)
588
- # Assume the lease expiring last is the current IP address
589
- ip_address = leases.sort_by { |lse| lse["expirytime"] }.last["ipaddr"] if !leases.empty?
590
- end
479
+ # Assume the lease expiring last is the current IP address
480
+ ip_address = net&.dhcp_leases(nic.mac)&.max_by { |lse| lse["expirytime"] }&.dig("ipaddr")
591
481
  end
592
482
 
593
483
  return { :public => [ip_address], :private => [ip_address] }
594
484
  end
595
485
 
486
+ # Locale-friendly removal of non-alpha nums
487
+ DOMAIN_CLEANUP_REGEXP = Regexp.compile('[\W_-]')
488
+
596
489
  def ip_address(key)
597
- addresses[key].nil? ? nil : addresses[key].first
490
+ addresses[key]&.first
598
491
  end
599
492
 
600
493
  def initialize_nics
@@ -665,7 +558,9 @@ module Fog
665
558
  :cpu => {},
666
559
  :hugepages => false,
667
560
  :guest_agent => true,
561
+ :video => {:type => "cirrus", :vram => 9216, :heads => 1},
668
562
  :virtio_rng => {},
563
+ :firmware_features => { "secure-boot" => "no" },
669
564
  }
670
565
  end
671
566
 
@@ -679,7 +574,7 @@ module Fog
679
574
  end
680
575
 
681
576
  def default_display
682
- {:port => '-1', :listen => '127.0.0.1', :type => 'vnc', :password => '' }
577
+ {:port => '-1', :listen => '127.0.0.1', :type => 'vnc' }
683
578
  end
684
579
  end
685
580
  end
@@ -12,16 +12,8 @@ module Fog
12
12
  end
13
13
 
14
14
  def xml_elements(xml, path, attribute=nil)
15
- xml = Nokogiri::XML(xml)
16
- attribute.nil? ? (xml/path).map : (xml/path).map{|element| element[attribute.to_sym]}
17
- end
18
-
19
- def to_xml template_name = nil
20
- # figure out our ERB template filename
21
- erb = template_name || self.class.to_s.split("::").last.downcase
22
- path = File.join(File.dirname(__FILE__), "..", "templates", "#{erb}.xml.erb")
23
- template = File.read(path)
24
- ERB.new(template, nil, '-').result(binding)
15
+ xml = Nokogiri::XML(xml)
16
+ attribute.nil? ? (xml/path).map : (xml/path).map{|element| element[attribute.to_sym]}
25
17
  end
26
18
 
27
19
  def randomized_name
@@ -39,7 +39,8 @@ module Fog
39
39
 
40
40
  raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key
41
41
  @xml ||= to_xml
42
- self.path = service.create_volume(pool_name, xml).path
42
+ self.id = service.create_volume(pool_name, xml).key
43
+ reload
43
44
  end
44
45
 
45
46
  # Destroy a volume
@@ -68,8 +69,8 @@ module Fog
68
69
  new_volume = self.dup
69
70
  new_volume.key = nil
70
71
  new_volume.name = new_name
71
- new_volume.path = service.clone_volume(pool_name, new_volume.to_xml, self.name).path
72
72
 
73
+ new_volume.id = service.clone_volume(pool_name, new_volume.to_xml, self.name).key
73
74
  new_volume.reload
74
75
  end
75
76
 
@@ -78,8 +79,46 @@ module Fog
78
79
  service.upload_volume(pool_name, name, file_path)
79
80
  end
80
81
 
82
+ def to_xml
83
+ builder = Nokogiri::XML::Builder.new do |xml|
84
+ xml.volume do
85
+ xml.name(name)
86
+
87
+ allocation_size, allocation_unit = split_size_unit(allocation)
88
+ xml.allocation(allocation_size, :unit => allocation_unit)
89
+
90
+ capacity_size, capacity_unit = split_size_unit(capacity)
91
+ xml.capacity(capacity_size, :unit => capacity_unit)
92
+
93
+ xml.target do
94
+ xml.format(:type => format_type)
95
+ xml_permissions(xml)
96
+ end
97
+
98
+ if backing_volume
99
+ xml.backingStore do
100
+ xml.path(backing_volume.path)
101
+ xml.format(:type => backing_volume.format_type)
102
+ xml_permissions(xml)
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ builder.to_xml
109
+ end
110
+
81
111
  private
82
112
 
113
+ def xml_permissions(xml)
114
+ xml.permissions do
115
+ xml.owner(owner) if owner
116
+ xml.group(group) if group
117
+ xml.mode('0744')
118
+ xml.label('virt_image_t')
119
+ end
120
+ end
121
+
83
122
  def image_suffix
84
123
  return "img" if format_type == "raw"
85
124
  format_type
@@ -1,17 +1,19 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
5
- def clone_volume (pool_name, xml, name)
4
+ module Shared
5
+ def clone_volume(pool_name, xml, name)
6
6
  vol = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(name)
7
7
  client.lookup_storage_pool_by_name(pool_name).create_vol_xml_from(xml, vol)
8
8
  end
9
9
  end
10
10
 
11
+ class Real
12
+ include Shared
13
+ end
14
+
11
15
  class Mock
12
- def clone_volume(pool_name, xml, name)
13
- Fog::Libvirt::Compute::Volume.new({:pool_name => pool_name, :xml => xml})
14
- end
16
+ include Shared
15
17
  end
16
18
  end
17
19
  end
@@ -1,16 +1,18 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def create_domain(xml)
6
6
  client.create_domain_xml(xml)
7
7
  end
8
8
  end
9
9
 
10
+ class Real
11
+ include Shared
12
+ end
13
+
10
14
  class Mock
11
- def create_domain(xml)
12
- ::Libvirt::Domain.new()
13
- end
15
+ include Shared
14
16
  end
15
17
  end
16
18
  end
@@ -1,15 +1,18 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def create_volume(pool_name, xml)
6
6
  client.lookup_storage_pool_by_name(pool_name).create_vol_xml(xml)
7
7
  end
8
8
  end
9
9
 
10
+ class Real
11
+ include Shared
12
+ end
13
+
10
14
  class Mock
11
- def create_volume(pool_name, xml)
12
- end
15
+ include Shared
13
16
  end
14
17
  end
15
18
  end
@@ -1,16 +1,18 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def define_domain(xml)
6
6
  client.define_domain_xml(xml)
7
7
  end
8
8
  end
9
9
 
10
+ class Real
11
+ include Shared
12
+ end
13
+
10
14
  class Mock
11
- def define_domain(xml)
12
- ::Libvirt::Domain.new()
13
- end
15
+ include Shared
14
16
  end
15
17
  end
16
18
  end
@@ -1,15 +1,18 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def define_pool(xml)
6
6
  client.define_storage_pool_xml(xml)
7
7
  end
8
8
  end
9
9
 
10
+ class Real
11
+ include Shared
12
+ end
13
+
10
14
  class Mock
11
- def define_pool(xml)
12
- end
15
+ include Shared
13
16
  end
14
17
  end
15
18
  end
@@ -1,17 +1,19 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  #shutdown the interface
6
6
  def destroy_interface(uuid)
7
7
  client.lookup_interface_by_uuid(uuid).destroy
8
8
  end
9
9
  end
10
10
 
11
+ class Real
12
+ include Shared
13
+ end
14
+
11
15
  class Mock
12
- def destroy_interface(uuid)
13
- true
14
- end
16
+ include Shared
15
17
  end
16
18
  end
17
19
  end