fog-libvirt 0.12.2 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/fog-libvirt.gemspec +4 -5
- data/lib/fog/libvirt/compute.rb +15 -26
- data/lib/fog/libvirt/models/compute/network.rb +11 -0
- data/lib/fog/libvirt/models/compute/pool.rb +14 -0
- data/lib/fog/libvirt/models/compute/server.rb +41 -150
- data/lib/fog/libvirt/models/compute/util/util.rb +2 -10
- data/lib/fog/libvirt/models/compute/volume.rb +41 -2
- data/lib/fog/libvirt/requests/compute/clone_volume.rb +7 -5
- data/lib/fog/libvirt/requests/compute/create_domain.rb +6 -4
- data/lib/fog/libvirt/requests/compute/create_volume.rb +6 -3
- data/lib/fog/libvirt/requests/compute/define_domain.rb +6 -4
- data/lib/fog/libvirt/requests/compute/define_pool.rb +6 -3
- data/lib/fog/libvirt/requests/compute/destroy_interface.rb +6 -4
- data/lib/fog/libvirt/requests/compute/destroy_network.rb +6 -4
- data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +4 -5
- data/lib/fog/libvirt/requests/compute/get_node_info.rb +6 -3
- data/lib/fog/libvirt/requests/compute/libversion.rb +6 -4
- data/lib/fog/libvirt/requests/compute/list_domains.rb +27 -31
- data/lib/fog/libvirt/requests/compute/list_interfaces.rb +6 -14
- data/lib/fog/libvirt/requests/compute/list_networks.rb +6 -24
- data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +6 -3
- data/lib/fog/libvirt/requests/compute/list_pools.rb +20 -42
- data/lib/fog/libvirt/requests/compute/list_volumes.rb +16 -36
- data/lib/fog/libvirt/requests/compute/pool_action.rb +6 -4
- data/lib/fog/libvirt/requests/compute/update_autostart.rb +6 -4
- data/lib/fog/libvirt/requests/compute/update_display.rb +6 -5
- data/lib/fog/libvirt/requests/compute/upload_volume.rb +6 -3
- data/lib/fog/libvirt/requests/compute/vm_action.rb +6 -4
- data/lib/fog/libvirt/requests/compute/volume_action.rb +6 -4
- data/lib/fog/libvirt/version.rb +1 -1
- data/minitests/test_helper.rb +1 -1
- data/tests/helper.rb +1 -1
- data/tests/helpers/formats_helper.rb +3 -2
- data/tests/helpers/formats_helper_tests.rb +8 -8
- data/tests/helpers/mock_helper.rb +1 -1
- data/tests/libvirt/models/compute/network_tests.rb +14 -2
- data/tests/libvirt/models/compute/nic_tests.rb +2 -1
- data/tests/libvirt/models/compute/pools_tests.rb +6 -6
- data/tests/libvirt/models/compute/server_tests.rb +53 -3
- data/tests/libvirt/models/compute/volume_tests.rb +21 -1
- data/tests/libvirt/models/compute/volumes_tests.rb +2 -0
- data/tests/libvirt/requests/compute/list_pools_tests.rb +1 -1
- metadata +38 -43
- data/lib/fog/libvirt/models/compute/templates/network.xml.erb +0 -6
- data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +0 -6
- data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +0 -34
- data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +0 -40
- data/minitests/server/server_test.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a669713a0c03e1bbfaa52fc3e9264f94c1e4966cc78d87cfc951e9e583c539a
|
4
|
+
data.tar.gz: 518134720023079b9e6ff39616cb6bd9355486c441be5fcefe651ecc98d282c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7fd1e7d922c785a27c9e6496dca419b9dc85ec342941354371ab7004495327229c82193ea99e88a27c6192b7169fb67f52f49795814559e77dbe40171ad2e74
|
7
|
+
data.tar.gz: 0e4ec2da6eb82210b16a445f3957bc1f1034ee6c7ccf63e303180a0d5fcc61a871f2f7c6c1896ccf2e893920324a31350f90a026ca1690556e76fbdaee301a05
|
data/Gemfile
CHANGED
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.
|
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")
|
data/lib/fog/libvirt/compute.rb
CHANGED
@@ -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
52
|
|
62
|
-
private
|
63
|
-
|
64
|
-
def client
|
65
|
-
return @client if defined?(@client)
|
66
|
-
end
|
67
|
-
|
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,20 @@ 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
|
+
|
121
|
+
def enhance_uri(uri)
|
122
|
+
uri = 'test:///default' unless ::URI.parse(uri).scheme == 'test'
|
123
|
+
|
124
|
+
super(uri)
|
125
|
+
end
|
126
|
+
end
|
138
127
|
end
|
139
128
|
end
|
140
129
|
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
|
91
|
+
nics&.first&.mac
|
87
92
|
end
|
88
93
|
|
89
94
|
def disk_path
|
@@ -286,14 +291,31 @@ module Fog
|
|
286
291
|
end
|
287
292
|
|
288
293
|
xml.vcpu(cpus)
|
289
|
-
|
294
|
+
os_tags = {}
|
295
|
+
|
296
|
+
os_tags[:firmware] = firmware if firmware == 'efi'
|
297
|
+
|
298
|
+
xml.os(**os_tags) do
|
290
299
|
type = xml.type(os_type, :arch => arch)
|
291
300
|
type[:machine] = "q35" if ["i686", "x86_64"].include?(arch)
|
292
301
|
|
293
302
|
boot_order.each do |dev|
|
294
303
|
xml.boot(:dev => dev)
|
295
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
|
296
317
|
end
|
318
|
+
|
297
319
|
xml.features do
|
298
320
|
xml.acpi
|
299
321
|
xml.apic
|
@@ -306,7 +328,7 @@ module Fog
|
|
306
328
|
end
|
307
329
|
else
|
308
330
|
xml.cpu(
|
309
|
-
:mode => cpu.
|
331
|
+
:mode => cpu.fetch(:mode, "host-passthrough"),
|
310
332
|
:check => cpu.fetch(:check, "none"),
|
311
333
|
:migratable => cpu.fetch(:migratable, "on")
|
312
334
|
)
|
@@ -361,14 +383,15 @@ module Fog
|
|
361
383
|
xml.disk(:type => "file", :device => "cdrom") do
|
362
384
|
xml.driver(:name => "qemu", :type => "raw")
|
363
385
|
xml.source(:file => "#{iso_dir}/#{iso_file}")
|
364
|
-
xml.target(:dev => "
|
386
|
+
xml.target(:dev => "sda", :bus => "scsi")
|
365
387
|
xml.readonly
|
366
|
-
xml.address(:type => "drive", :controller => 0, :bus =>
|
388
|
+
xml.address(:type => "drive", :controller => 0, :bus => 0, :unit => 0)
|
367
389
|
end
|
368
390
|
end
|
369
391
|
|
370
392
|
nics.each do |nic|
|
371
393
|
xml.interface(:type => nic.type) do
|
394
|
+
xml.mac(:address => nic.mac) if nic.mac
|
372
395
|
if nic.type == "bridge"
|
373
396
|
xml.source(:bridge => nic.bridge)
|
374
397
|
else
|
@@ -413,10 +436,10 @@ module Fog
|
|
413
436
|
graphics.autoport = "yes"
|
414
437
|
end
|
415
438
|
graphics.listen = display[:listen] unless display[:listen].empty?
|
416
|
-
graphics.passwd = display[:password]
|
439
|
+
graphics.passwd = display[:password] if display[:password] && !display[:password].empty?
|
417
440
|
|
418
441
|
xml.video do
|
419
|
-
xml.model(
|
442
|
+
xml.model(video)
|
420
443
|
end
|
421
444
|
end
|
422
445
|
end
|
@@ -445,160 +468,26 @@ module Fog
|
|
445
468
|
args
|
446
469
|
end
|
447
470
|
|
448
|
-
# This tests the library version before redefining the address
|
449
|
-
# method for this instance to use a method compatible with
|
450
|
-
# earlier libvirt libraries, or uses the dhcp method from more
|
451
|
-
# recent releases.
|
452
|
-
def addresses(service_arg=service, options={})
|
453
|
-
addresses_method = self.method(:addresses_dhcp)
|
454
|
-
# check if ruby-libvirt was compiled against a new enough version
|
455
|
-
# that can use dhcp_leases, as otherwise it will not provide the
|
456
|
-
# method dhcp_leases on any of the network objects.
|
457
|
-
has_dhcp_leases = true
|
458
|
-
begin
|
459
|
-
service.networks.first.dhcp_leases(self.mac)
|
460
|
-
rescue NoMethodError
|
461
|
-
has_dhcp_leases = false
|
462
|
-
rescue
|
463
|
-
# assume some other odd exception.
|
464
|
-
end
|
465
|
-
|
466
|
-
# if ruby-libvirt not compiled with support, or remote library is
|
467
|
-
# too old (must be newer than 1.2.8), then use old fallback
|
468
|
-
if not has_dhcp_leases or service.libversion() < 1002008
|
469
|
-
addresses_method = self.method(:addresses_ip_command)
|
470
|
-
end
|
471
|
-
|
472
|
-
# replace current definition for this instance with correct one for
|
473
|
-
# detected libvirt to perform check once for connection
|
474
|
-
(class << self; self; end).class_eval do
|
475
|
-
define_method(:addresses, addresses_method)
|
476
|
-
end
|
477
|
-
addresses(service_arg, options)
|
478
|
-
end
|
479
|
-
|
480
|
-
def ssh_ip_command(ip_command, uri)
|
481
|
-
# Retrieve the parts we need from the service to setup our ssh options
|
482
|
-
user=uri.user #could be nil
|
483
|
-
host=uri.host
|
484
|
-
keyfile=uri.keyfile
|
485
|
-
port=uri.port
|
486
|
-
|
487
|
-
# Setup the options
|
488
|
-
ssh_options={}
|
489
|
-
ssh_options[:keys]=[ keyfile ] unless keyfile.nil?
|
490
|
-
ssh_options[:port]=port unless keyfile.nil?
|
491
|
-
ssh_options[:paranoid]=true if uri.no_verify?
|
492
|
-
|
493
|
-
begin
|
494
|
-
result=Fog::SSH.new(host, user, ssh_options).run(ip_command)
|
495
|
-
rescue Errno::ECONNREFUSED
|
496
|
-
raise Fog::Errors::Error.new("Connection was refused to host #{host} to retrieve the ip_address for #{mac}")
|
497
|
-
rescue Net::SSH::AuthenticationFailed
|
498
|
-
raise Fog::Errors::Error.new("Error authenticating over ssh to host #{host} and user #{user}")
|
499
|
-
end
|
500
|
-
|
501
|
-
# Check for a clean exit code
|
502
|
-
if result.first.status == 0
|
503
|
-
return result.first.stdout.strip
|
504
|
-
else
|
505
|
-
# We got a failure executing the command
|
506
|
-
raise Fog::Errors::Error.new("The command #{ip_command} failed to execute with a clean exit code")
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
def local_ip_command(ip_command)
|
511
|
-
# Execute the ip_command locally
|
512
|
-
# Initialize empty ip_address string
|
513
|
-
ip_address=""
|
514
|
-
|
515
|
-
IO.popen("#{ip_command}") do |p|
|
516
|
-
p.each_line do |l|
|
517
|
-
ip_address+=l
|
518
|
-
end
|
519
|
-
status=Process.waitpid2(p.pid)[1].exitstatus
|
520
|
-
if status!=0
|
521
|
-
raise Fog::Errors::Error.new("The command #{ip_command} failed to execute with a clean exit code")
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
#Strip any new lines from the string
|
526
|
-
ip_address.chomp
|
527
|
-
end
|
528
|
-
|
529
|
-
# Locale-friendly removal of non-alpha nums
|
530
|
-
DOMAIN_CLEANUP_REGEXP = Regexp.compile('[\W_-]')
|
531
|
-
|
532
|
-
# This retrieves the ip address of the mac address using ip_command
|
533
|
-
# It returns an array of public and private ip addresses
|
534
|
-
# Currently only one ip address is returned, but in the future this could be multiple
|
535
|
-
# if the server has multiple network interface
|
536
|
-
def addresses_ip_command(service_arg=service, options={})
|
537
|
-
mac=self.mac
|
538
|
-
|
539
|
-
# Aug 24 17:34:41 juno arpwatch: new station 10.247.4.137 52:54:00:88:5a:0a eth0.4
|
540
|
-
# 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
|
541
|
-
# Check if another ip_command string was provided
|
542
|
-
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
|
543
|
-
ip_command_local=options[:ip_command].nil? ? ip_command_global : options[:ip_command]
|
544
|
-
|
545
|
-
ip_command="mac=#{mac}; server_name=#{name.gsub(DOMAIN_CLEANUP_REGEXP, '_')}; "+ip_command_local
|
546
|
-
|
547
|
-
ip_address=nil
|
548
|
-
|
549
|
-
if service_arg.uri.ssh_enabled?
|
550
|
-
ip_address=ssh_ip_command(ip_command, service_arg.uri)
|
551
|
-
else
|
552
|
-
# It's not ssh enabled, so we assume it is
|
553
|
-
if service_arg.uri.transport=="tls"
|
554
|
-
raise Fog::Errors::Error.new("TlS remote transport is not currently supported, only ssh")
|
555
|
-
end
|
556
|
-
ip_address=local_ip_command(ip_command)
|
557
|
-
end
|
558
|
-
|
559
|
-
# The Ip-address command has been run either local or remote now
|
560
|
-
|
561
|
-
if ip_address==""
|
562
|
-
#The grep didn't find an ip address result"
|
563
|
-
ip_address=nil
|
564
|
-
else
|
565
|
-
# To be sure that the command didn't return another random string
|
566
|
-
# We check if the result is an actual ip-address
|
567
|
-
# otherwise we return nil
|
568
|
-
unless ip_address=~/^(\d{1,3}\.){3}\d{1,3}$/
|
569
|
-
raise Fog::Errors::Error.new(
|
570
|
-
"The result of #{ip_command} does not have valid ip-address format\n"+
|
571
|
-
"Result was: #{ip_address}\n"
|
572
|
-
)
|
573
|
-
end
|
574
|
-
end
|
575
|
-
|
576
|
-
return { :public => [ip_address], :private => [ip_address]}
|
577
|
-
end
|
578
|
-
|
579
471
|
# This retrieves the ip address of the mac address using dhcp_leases
|
580
472
|
# It returns an array of public and private ip addresses
|
581
473
|
# Currently only one ip address is returned, but in the future this could be multiple
|
582
474
|
# if the server has multiple network interface
|
583
|
-
def
|
584
|
-
mac=self.mac
|
585
|
-
|
475
|
+
def addresses(service_arg=service, options={})
|
586
476
|
ip_address = nil
|
587
|
-
nic = self.nics
|
588
|
-
if !nic.nil?
|
477
|
+
if (nic = self.nics&.first)
|
589
478
|
net = service.networks.all(:name => nic.network).first
|
590
|
-
|
591
|
-
|
592
|
-
# Assume the lease expiring last is the current IP address
|
593
|
-
ip_address = leases.sort_by { |lse| lse["expirytime"] }.last["ipaddr"] if !leases.empty?
|
594
|
-
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")
|
595
481
|
end
|
596
482
|
|
597
483
|
return { :public => [ip_address], :private => [ip_address] }
|
598
484
|
end
|
599
485
|
|
486
|
+
# Locale-friendly removal of non-alpha nums
|
487
|
+
DOMAIN_CLEANUP_REGEXP = Regexp.compile('[\W_-]')
|
488
|
+
|
600
489
|
def ip_address(key)
|
601
|
-
addresses[key]
|
490
|
+
addresses[key]&.first
|
602
491
|
end
|
603
492
|
|
604
493
|
def initialize_nics
|
@@ -669,7 +558,9 @@ module Fog
|
|
669
558
|
:cpu => {},
|
670
559
|
:hugepages => false,
|
671
560
|
:guest_agent => true,
|
561
|
+
:video => {:type => "cirrus", :vram => 9216, :heads => 1},
|
672
562
|
:virtio_rng => {},
|
563
|
+
:firmware_features => { "secure-boot" => "no" },
|
673
564
|
}
|
674
565
|
end
|
675
566
|
|
@@ -683,7 +574,7 @@ module Fog
|
|
683
574
|
end
|
684
575
|
|
685
576
|
def default_display
|
686
|
-
{:port => '-1', :listen => '127.0.0.1', :type => 'vnc'
|
577
|
+
{:port => '-1', :listen => '127.0.0.1', :type => 'vnc' }
|
687
578
|
end
|
688
579
|
end
|
689
580
|
end
|
@@ -12,16 +12,8 @@ module Fog
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def xml_elements(xml, path, attribute=nil)
|
15
|
-
|
16
|
-
|
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.
|
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
|
-
|
5
|
-
def clone_volume
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
13
|
-
true
|
14
|
-
end
|
16
|
+
include Shared
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|