vagrant-libvirt 0.0.40 → 0.0.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +13 -103
- data/.coveralls.yml +0 -1
- data/.github/issue_template.md +0 -37
- data/.gitignore +0 -21
- data/.travis.yml +0 -28
- data/CHANGELOG.md +0 -99
- data/Gemfile +0 -27
- data/LICENSE +0 -22
- data/README.md +0 -1311
- data/Rakefile +0 -8
- data/example_box/README.md +0 -29
- data/example_box/Vagrantfile +0 -60
- data/example_box/metadata.json +0 -5
- data/lib/vagrant-libvirt.rb +0 -29
- data/lib/vagrant-libvirt/action.rb +0 -362
- data/lib/vagrant-libvirt/action/create_domain.rb +0 -313
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +0 -87
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +0 -294
- data/lib/vagrant-libvirt/action/create_networks.rb +0 -353
- data/lib/vagrant-libvirt/action/destroy_domain.rb +0 -83
- data/lib/vagrant-libvirt/action/destroy_networks.rb +0 -95
- data/lib/vagrant-libvirt/action/forward_ports.rb +0 -221
- data/lib/vagrant-libvirt/action/halt_domain.rb +0 -35
- data/lib/vagrant-libvirt/action/handle_box_image.rb +0 -156
- data/lib/vagrant-libvirt/action/handle_storage_pool.rb +0 -57
- data/lib/vagrant-libvirt/action/is_created.rb +0 -18
- data/lib/vagrant-libvirt/action/is_running.rb +0 -21
- data/lib/vagrant-libvirt/action/is_suspended.rb +0 -42
- data/lib/vagrant-libvirt/action/message_already_created.rb +0 -16
- data/lib/vagrant-libvirt/action/message_not_created.rb +0 -16
- data/lib/vagrant-libvirt/action/message_not_running.rb +0 -16
- data/lib/vagrant-libvirt/action/message_not_suspended.rb +0 -16
- data/lib/vagrant-libvirt/action/package_domain.rb +0 -105
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +0 -94
- data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +0 -17
- data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +0 -27
- data/lib/vagrant-libvirt/action/read_mac_addresses.rb +0 -40
- data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +0 -20
- data/lib/vagrant-libvirt/action/remove_stale_volume.rb +0 -50
- data/lib/vagrant-libvirt/action/resume_domain.rb +0 -34
- data/lib/vagrant-libvirt/action/set_boot_order.rb +0 -109
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +0 -64
- data/lib/vagrant-libvirt/action/share_folders.rb +0 -71
- data/lib/vagrant-libvirt/action/start_domain.rb +0 -303
- data/lib/vagrant-libvirt/action/suspend_domain.rb +0 -40
- data/lib/vagrant-libvirt/action/wait_till_up.rb +0 -102
- data/lib/vagrant-libvirt/cap/mount_p9.rb +0 -42
- data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +0 -17
- data/lib/vagrant-libvirt/cap/synced_folder.rb +0 -113
- data/lib/vagrant-libvirt/config.rb +0 -698
- data/lib/vagrant-libvirt/driver.rb +0 -118
- data/lib/vagrant-libvirt/errors.rb +0 -149
- data/lib/vagrant-libvirt/plugin.rb +0 -92
- data/lib/vagrant-libvirt/provider.rb +0 -130
- data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +0 -13
- data/lib/vagrant-libvirt/templates/domain.xml.erb +0 -229
- data/lib/vagrant-libvirt/templates/private_network.xml.erb +0 -34
- data/lib/vagrant-libvirt/templates/public_interface.xml.erb +0 -23
- data/lib/vagrant-libvirt/util.rb +0 -11
- data/lib/vagrant-libvirt/util/collection.rb +0 -19
- data/lib/vagrant-libvirt/util/erb_template.rb +0 -22
- data/lib/vagrant-libvirt/util/error_codes.rb +0 -100
- data/lib/vagrant-libvirt/util/network_util.rb +0 -138
- data/lib/vagrant-libvirt/util/timer.rb +0 -17
- data/lib/vagrant-libvirt/version.rb +0 -5
- data/locales/en.yml +0 -159
- data/spec/spec_helper.rb +0 -9
- data/spec/support/environment_helper.rb +0 -46
- data/spec/support/libvirt_context.rb +0 -30
- data/spec/support/sharedcontext.rb +0 -34
- data/spec/unit/action/destroy_domain_spec.rb +0 -97
- data/spec/unit/action/set_name_of_domain_spec.rb +0 -21
- data/spec/unit/action/wait_till_up_spec.rb +0 -127
- data/spec/unit/config_spec.rb +0 -106
- data/spec/unit/templates/domain_all_settings.xml +0 -133
- data/spec/unit/templates/domain_defaults.xml +0 -46
- data/spec/unit/templates/domain_spec.rb +0 -75
- data/tools/create_box.sh +0 -130
- data/tools/prepare_redhat_for_box.sh +0 -119
- data/vagrant-libvirt.gemspec +0 -28
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
# require 'log4r/yamlconfigurator'
|
3
|
-
|
4
|
-
module VagrantPlugins
|
5
|
-
module ProviderLibvirt
|
6
|
-
module Action
|
7
|
-
class RemoveStaleVolume
|
8
|
-
def initialize(app, _env)
|
9
|
-
# log4r_config= YAML.load_file(File.join(File.dirname(__FILE__),"log4r.yaml"))
|
10
|
-
# log_cfg = Log4r::YamlConfigurator
|
11
|
-
# log_cfg.decode_yaml( log4r_config['log4r_config'] )
|
12
|
-
|
13
|
-
@logger = Log4r::Logger.new('vagrant_libvirt::action::remove_stale_volume')
|
14
|
-
@app = app
|
15
|
-
end
|
16
|
-
|
17
|
-
def call(env)
|
18
|
-
# Remove stale server volume
|
19
|
-
env[:ui].info(I18n.t('vagrant_libvirt.remove_stale_volume'))
|
20
|
-
|
21
|
-
config = env[:machine].provider_config
|
22
|
-
# Check for storage pool, where box image should be created
|
23
|
-
fog_pool = ProviderLibvirt::Util::Collection.find_matching(
|
24
|
-
env[:machine].provider.driver.connection.pools.all, config.storage_pool_name
|
25
|
-
)
|
26
|
-
@logger.debug("**** Pool #{fog_pool.name}")
|
27
|
-
|
28
|
-
# This is name of newly created image for vm.
|
29
|
-
name = "#{env[:domain_name]}.img"
|
30
|
-
@logger.debug("**** Volume name #{name}")
|
31
|
-
|
32
|
-
# remove root storage
|
33
|
-
box_volume = ProviderLibvirt::Util::Collection.find_matching(
|
34
|
-
env[:machine].provider.driver.connection.volumes.all, name
|
35
|
-
)
|
36
|
-
if box_volume && box_volume.pool_name == fog_pool.name
|
37
|
-
@logger.info("Deleting volume #{box_volume.key}")
|
38
|
-
box_volume.destroy
|
39
|
-
env[:result] = box_volume
|
40
|
-
else
|
41
|
-
env[:result] = nil
|
42
|
-
end
|
43
|
-
|
44
|
-
# Continue the middleware chain.
|
45
|
-
@app.call(env)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module ProviderLibvirt
|
5
|
-
module Action
|
6
|
-
# Resume suspended domain.
|
7
|
-
class ResumeDomain
|
8
|
-
def initialize(app, _env)
|
9
|
-
@logger = Log4r::Logger.new('vagrant_libvirt::action::resume_domain')
|
10
|
-
@app = app
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
env[:ui].info(I18n.t('vagrant_libvirt.resuming_domain'))
|
15
|
-
|
16
|
-
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
17
|
-
raise Errors::NoDomainError if domain.nil?
|
18
|
-
|
19
|
-
libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
|
20
|
-
config = env[:machine].provider_config
|
21
|
-
if config.suspend_mode == 'managedsave'
|
22
|
-
domain.start
|
23
|
-
else
|
24
|
-
domain.resume
|
25
|
-
end
|
26
|
-
|
27
|
-
@logger.info("Machine #{env[:machine].id} is resumed.")
|
28
|
-
|
29
|
-
@app.call(env)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
module VagrantPlugins
|
5
|
-
module ProviderLibvirt
|
6
|
-
module Action
|
7
|
-
# boot order useful for pxe in discovery workflow
|
8
|
-
class SetBootOrder
|
9
|
-
def initialize(app, env)
|
10
|
-
@app = app
|
11
|
-
@logger = Log4r::Logger.new('vagrant_libvirt::action::set_boot_order')
|
12
|
-
config = env[:machine].provider_config
|
13
|
-
@boot_order = config.boot_order
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
# Get domain first
|
18
|
-
begin
|
19
|
-
domain = env[:machine].provider
|
20
|
-
.driver
|
21
|
-
.connection
|
22
|
-
.client
|
23
|
-
.lookup_domain_by_uuid(
|
24
|
-
env[:machine].id.to_s
|
25
|
-
)
|
26
|
-
rescue => e
|
27
|
-
raise Errors::NoDomainError,
|
28
|
-
error_message: e.message
|
29
|
-
end
|
30
|
-
|
31
|
-
# Only execute specific boot ordering if this is defined
|
32
|
-
# in the Vagrant file
|
33
|
-
if @boot_order.count >= 1
|
34
|
-
|
35
|
-
# If a domain is initially defined with no box or disk or
|
36
|
-
# with an explicit boot order, libvirt adds <boot dev="foo">
|
37
|
-
# This conflicts with an explicit boot_order configuration,
|
38
|
-
# so we need to remove it from the domain xml and feed it back.
|
39
|
-
# Also see https://bugzilla.redhat.com/show_bug.cgi?id=1248514
|
40
|
-
# as to why we have to do this after all devices have been defined.
|
41
|
-
xml = Nokogiri::XML(domain.xml_desc)
|
42
|
-
xml.search('/domain/os/boot').each(&:remove)
|
43
|
-
|
44
|
-
# Parse the XML and find each defined drive and network interfacee
|
45
|
-
hd = xml.search("/domain/devices/disk[@device='disk']")
|
46
|
-
cdrom = xml.search("/domain/devices/disk[@device='cdrom']")
|
47
|
-
# implemented only for 1 network
|
48
|
-
nets = @boot_order.flat_map do |x|
|
49
|
-
x.class == Hash ? x : nil
|
50
|
-
end.compact
|
51
|
-
raise 'Defined only for 1 network for boot' if nets.size > 1
|
52
|
-
network = search_network(nets, xml)
|
53
|
-
|
54
|
-
# Generate an array per device group and a flattened
|
55
|
-
# array from all of those
|
56
|
-
devices = { 'hd' => hd,
|
57
|
-
'cdrom' => cdrom,
|
58
|
-
'network' => network }
|
59
|
-
|
60
|
-
final_boot_order = final_boot_order(@boot_order, devices)
|
61
|
-
# Loop over the entire defined boot order array and
|
62
|
-
# create boot order entries in the domain XML
|
63
|
-
final_boot_order.each_with_index do |node, index|
|
64
|
-
boot = "<boot order='#{index + 1}'/>"
|
65
|
-
node.add_child(boot)
|
66
|
-
logger_msg(node, index)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Finally redefine the domain XML through libvirt
|
70
|
-
# to apply the boot ordering
|
71
|
-
env[:machine].provider
|
72
|
-
.driver
|
73
|
-
.connection
|
74
|
-
.client
|
75
|
-
.define_domain_xml(xml.to_s)
|
76
|
-
end
|
77
|
-
|
78
|
-
@app.call(env)
|
79
|
-
end
|
80
|
-
|
81
|
-
def final_boot_order(boot_order, devices)
|
82
|
-
boot_order.flat_map do |category|
|
83
|
-
devices[category.class == Hash ? category.keys.first : category]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def search_network(nets, xml)
|
88
|
-
str = '/domain/devices/interface'
|
89
|
-
str += "[(@type='network' or @type='udp' or @type='bridge')"
|
90
|
-
unless nets.empty?
|
91
|
-
str += " and source[@network='#{nets.first['network']}']"
|
92
|
-
end
|
93
|
-
str += ']'
|
94
|
-
@logger.debug(str)
|
95
|
-
xml.search(str)
|
96
|
-
end
|
97
|
-
|
98
|
-
def logger_msg(node, index)
|
99
|
-
name = if node.name == 'disk'
|
100
|
-
node['device']
|
101
|
-
elsif node.name == 'interface'
|
102
|
-
node.name
|
103
|
-
end
|
104
|
-
@logger.debug "Setting #{name} to boot index #{index + 1}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
module VagrantPlugins
|
3
|
-
module ProviderLibvirt
|
4
|
-
module Action
|
5
|
-
# Setup name for domain and domain volumes.
|
6
|
-
class SetNameOfDomain
|
7
|
-
def initialize(app, _env)
|
8
|
-
@logger = Log4r::Logger.new('vagrant_libvirt::action::set_name_of_domain')
|
9
|
-
@app = app
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(env)
|
13
|
-
env[:domain_name] = build_domain_name(env)
|
14
|
-
|
15
|
-
begin
|
16
|
-
@logger.info("Looking for domain #{env[:domain_name]} through list " \
|
17
|
-
"#{env[:machine].provider.driver.connection.servers.all}")
|
18
|
-
# Check if the domain name is not already taken
|
19
|
-
|
20
|
-
domain = ProviderLibvirt::Util::Collection.find_matching(
|
21
|
-
env[:machine].provider.driver.connection.servers.all, env[:domain_name]
|
22
|
-
)
|
23
|
-
rescue Fog::Errors::Error => e
|
24
|
-
@logger.info(e.to_s)
|
25
|
-
domain = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
@logger.info("Looking for domain #{env[:domain_name]}")
|
29
|
-
|
30
|
-
unless domain.nil?
|
31
|
-
raise ProviderLibvirt::Errors::DomainNameExists,
|
32
|
-
domain_name: env[:domain_name]
|
33
|
-
end
|
34
|
-
|
35
|
-
@app.call(env)
|
36
|
-
end
|
37
|
-
|
38
|
-
# build domain name
|
39
|
-
# random_hostname option avoids
|
40
|
-
# `domain about to create is already taken`
|
41
|
-
# parsable and sortable by epoch time
|
42
|
-
# @example
|
43
|
-
# development-centos-6-chef-11_1404488971_3b7a569e2fd7c554b852
|
44
|
-
# @return [String] libvirt domain name
|
45
|
-
def build_domain_name(env)
|
46
|
-
config = env[:machine].provider_config
|
47
|
-
domain_name =
|
48
|
-
if config.default_prefix.nil?
|
49
|
-
env[:root_path].basename.to_s.dup.concat('_')
|
50
|
-
elsif config.default_prefix.empty?
|
51
|
-
# don't have any prefix, not even "_"
|
52
|
-
''
|
53
|
-
else
|
54
|
-
config.default_prefix.to_s.dup.concat('_')
|
55
|
-
end
|
56
|
-
domain_name << env[:machine].name.to_s
|
57
|
-
domain_name.gsub!(/[^-a-z0-9_\.]/i, '')
|
58
|
-
domain_name << "_#{Time.now.utc.to_i}_#{SecureRandom.hex(10)}" if config.random_hostname
|
59
|
-
domain_name
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
require 'log4r'
|
4
|
-
|
5
|
-
module VagrantPlugins
|
6
|
-
module ProviderLibvirt
|
7
|
-
module Action
|
8
|
-
class ShareFolders
|
9
|
-
def initialize(app, _env)
|
10
|
-
@logger = Log4r::Logger.new('vagrant::action::vm::share_folders')
|
11
|
-
@app = app
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
@env = env
|
16
|
-
|
17
|
-
prepare_folders
|
18
|
-
create_metadata
|
19
|
-
|
20
|
-
@app.call(env)
|
21
|
-
end
|
22
|
-
|
23
|
-
# This method returns an actual list of shared
|
24
|
-
# folders to create and their proper path.
|
25
|
-
def shared_folders
|
26
|
-
{}.tap do |result|
|
27
|
-
@env[:machine].config.vm.synced_folders.each do |id, data|
|
28
|
-
# Ignore NFS shared folders
|
29
|
-
next if !data[:type] == :nfs
|
30
|
-
|
31
|
-
# This to prevent overwriting the actual shared folders data
|
32
|
-
result[id] = data.dup
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Prepares the shared folders by verifying they exist and creating them
|
38
|
-
# if they don't.
|
39
|
-
def prepare_folders
|
40
|
-
shared_folders.each do |_id, options|
|
41
|
-
hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])
|
42
|
-
|
43
|
-
next unless !hostpath.directory? && options[:create]
|
44
|
-
# Host path doesn't exist, so let's create it.
|
45
|
-
@logger.debug("Host path doesn't exist, creating: #{hostpath}")
|
46
|
-
|
47
|
-
begin
|
48
|
-
hostpath.mkpath
|
49
|
-
rescue Errno::EACCES
|
50
|
-
raise Vagrant::Errors::SharedFolderCreateFailed,
|
51
|
-
path: hostpath.to_s
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def create_metadata
|
57
|
-
@env[:ui].info I18n.t('vagrant.actions.vm.share_folders.creating')
|
58
|
-
|
59
|
-
folders = []
|
60
|
-
shared_folders.each do |id, data|
|
61
|
-
folders << {
|
62
|
-
name: id,
|
63
|
-
hostpath: File.expand_path(data[:hostpath], @env[:root_path]),
|
64
|
-
transient: data[:transient]
|
65
|
-
}
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,303 +0,0 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
require 'rexml/document'
|
3
|
-
|
4
|
-
module VagrantPlugins
|
5
|
-
module ProviderLibvirt
|
6
|
-
module Action
|
7
|
-
# Just start the domain.
|
8
|
-
class StartDomain
|
9
|
-
def initialize(app, _env)
|
10
|
-
@logger = Log4r::Logger.new('vagrant_libvirt::action::start_domain')
|
11
|
-
@app = app
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:ui].info(I18n.t('vagrant_libvirt.starting_domain'))
|
16
|
-
|
17
|
-
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
18
|
-
raise Errors::NoDomainError if domain.nil?
|
19
|
-
config = env[:machine].provider_config
|
20
|
-
|
21
|
-
begin
|
22
|
-
# update domain settings on change.
|
23
|
-
|
24
|
-
libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
|
25
|
-
|
26
|
-
if config.memory.to_i * 1024 != libvirt_domain.max_memory
|
27
|
-
libvirt_domain.max_memory = config.memory.to_i * 1024
|
28
|
-
libvirt_domain.memory = libvirt_domain.max_memory
|
29
|
-
end
|
30
|
-
begin
|
31
|
-
# XML definition manipulation
|
32
|
-
descr = libvirt_domain.xml_desc(1)
|
33
|
-
xml_descr = REXML::Document.new descr
|
34
|
-
descr_changed = false
|
35
|
-
|
36
|
-
# additional disk bus
|
37
|
-
config.disks.each do |disk|
|
38
|
-
device = disk[:device]
|
39
|
-
bus = disk[:bus]
|
40
|
-
REXML::XPath.each(xml_descr, '/domain/devices/disk[@device="disk"]/target[@dev="' + device + '"]') do |disk_target|
|
41
|
-
next unless disk_target.attributes['bus'] != bus
|
42
|
-
descr_changed = true
|
43
|
-
disk_target.attributes['bus'] = bus
|
44
|
-
disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# disk_bus
|
49
|
-
REXML::XPath.each(xml_descr, '/domain/devices/disk[@device="disk"]/target[@dev="vda"]') do |disk_target|
|
50
|
-
next unless disk_target.attributes['bus'] != config.disk_bus
|
51
|
-
descr_changed = true
|
52
|
-
disk_target.attributes['bus'] = config.disk_bus
|
53
|
-
disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
|
54
|
-
end
|
55
|
-
|
56
|
-
# Iterface type
|
57
|
-
unless config.nic_model_type.nil?
|
58
|
-
REXML::XPath.each(xml_descr, '/domain/devices/interface/model') do |iface_model|
|
59
|
-
if iface_model.attributes['type'] != config.nic_model_type
|
60
|
-
descr_changed = true
|
61
|
-
iface_model.attributes['type'] = config.nic_model_type
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# vCpu count
|
67
|
-
if config.cpus.to_i != libvirt_domain.vcpus.length
|
68
|
-
descr_changed = true
|
69
|
-
REXML::XPath.first(xml_descr, '/domain/vcpu').text = config.cpus
|
70
|
-
end
|
71
|
-
|
72
|
-
# cpu_mode
|
73
|
-
cpu = REXML::XPath.first(xml_descr, '/domain/cpu')
|
74
|
-
if cpu.nil?
|
75
|
-
descr_changed = true
|
76
|
-
cpu = REXML::Element.new('cpu', REXML::XPath.first(xml_descr, '/domain'))
|
77
|
-
cpu.attributes['mode'] = config.cpu_mode
|
78
|
-
else
|
79
|
-
if cpu.attributes['mode'] != config.cpu_mode
|
80
|
-
descr_changed = true
|
81
|
-
cpu.attributes['mode'] = config.cpu_mode
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
if config.cpu_mode != 'host-passthrough'
|
86
|
-
cpu_model = REXML::XPath.first(xml_descr, '/domain/cpu/model')
|
87
|
-
if cpu_model.nil?
|
88
|
-
descr_changed = true
|
89
|
-
cpu_model = REXML::Element.new('model', REXML::XPath.first(xml_descr, '/domain/cpu'))
|
90
|
-
cpu_model.attributes['fallback'] = 'allow'
|
91
|
-
cpu_model.text = config.cpu_model
|
92
|
-
else
|
93
|
-
if cpu_model.text != config.cpu_model
|
94
|
-
descr_changed = true
|
95
|
-
cpu_model.text = config.cpu_model
|
96
|
-
end
|
97
|
-
if cpu_model.attributes['fallback'] != config.cpu_fallback
|
98
|
-
descr_changed = true
|
99
|
-
cpu_model.attributes['fallback'] = config.cpu_fallback
|
100
|
-
end
|
101
|
-
end
|
102
|
-
vmx_feature = REXML::XPath.first(xml_descr, '/domain/cpu/feature[@name="vmx"]')
|
103
|
-
svm_feature = REXML::XPath.first(xml_descr, '/domain/cpu/feature[@name="svm"]')
|
104
|
-
if config.nested
|
105
|
-
if vmx_feature.nil?
|
106
|
-
descr_changed = true
|
107
|
-
vmx_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr, '/domain/cpu'))
|
108
|
-
vmx_feature.attributes['policy'] = 'optional'
|
109
|
-
vmx_feature.attributes['name'] = 'vmx'
|
110
|
-
end
|
111
|
-
if svm_feature.nil?
|
112
|
-
descr_changed = true
|
113
|
-
svm_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr, '/domain/cpu'))
|
114
|
-
svm_feature.attributes['policy'] = 'optional'
|
115
|
-
svm_feature.attributes['name'] = 'svm'
|
116
|
-
end
|
117
|
-
else
|
118
|
-
unless vmx_feature.nil?
|
119
|
-
descr_changed = true
|
120
|
-
cpu.delete_element(vmx_feature)
|
121
|
-
end
|
122
|
-
unless svm_feature.nil?
|
123
|
-
descr_changed = true
|
124
|
-
cpu.delete_element(svm_feature)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
else
|
128
|
-
unless cpu.elements.to_a.empty?
|
129
|
-
descr_changed = true
|
130
|
-
cpu.elements.each do |elem|
|
131
|
-
cpu.delete_element(elem)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# Graphics
|
137
|
-
graphics = REXML::XPath.first(xml_descr, '/domain/devices/graphics')
|
138
|
-
if config.graphics_type != 'none'
|
139
|
-
if graphics.nil?
|
140
|
-
descr_changed = true
|
141
|
-
graphics = REXML::Element.new('graphics', REXML::XPath.first(xml_descr, '/domain/devices'))
|
142
|
-
end
|
143
|
-
if graphics.attributes['type'] != config.graphics_type
|
144
|
-
descr_changed = true
|
145
|
-
graphics.attributes['type'] = config.graphics_type
|
146
|
-
end
|
147
|
-
if graphics.attributes['listen'] != config.graphics_ip
|
148
|
-
descr_changed = true
|
149
|
-
graphics.attributes['listen'] = config.graphics_ip
|
150
|
-
graphics.delete_element('//listen')
|
151
|
-
end
|
152
|
-
if graphics.attributes['autoport'] != config.graphics_autoport
|
153
|
-
descr_changed = true
|
154
|
-
graphics.attributes['autoport'] = config.graphics_autoport
|
155
|
-
if config.graphics_autoport == 'no'
|
156
|
-
graphics.attributes['port'] = config.graphics_port
|
157
|
-
end
|
158
|
-
end
|
159
|
-
if graphics.attributes['keymap'] != config.keymap
|
160
|
-
descr_changed = true
|
161
|
-
graphics.attributes['keymap'] = config.keymap
|
162
|
-
end
|
163
|
-
if graphics.attributes['passwd'] != config.graphics_passwd
|
164
|
-
descr_changed = true
|
165
|
-
if config.graphics_passwd.nil?
|
166
|
-
graphics.attributes.delete 'passwd'
|
167
|
-
else
|
168
|
-
graphics.attributes['passwd'] = config.graphics_passwd
|
169
|
-
end
|
170
|
-
end
|
171
|
-
else
|
172
|
-
# graphics_type = none, remove entire element
|
173
|
-
graphics.parent.delete_element(graphics) unless graphics.nil?
|
174
|
-
end
|
175
|
-
|
176
|
-
# TPM
|
177
|
-
if config.tpm_path
|
178
|
-
raise Errors::FogCreateServerError, 'The TPM Path must be fully qualified' unless config.tpm_path[0].chr == '/'
|
179
|
-
|
180
|
-
tpm = REXML::XPath.first(xml_descr, '/domain/devices/tpm')
|
181
|
-
if tpm.nil?
|
182
|
-
descr_changed = true
|
183
|
-
tpm = REXML::Element.new('tpm', REXML::XPath.first(xml_descr, '/domain/devices/tpm/model'))
|
184
|
-
tpm.attributes['model'] = config.tpm_model
|
185
|
-
tpm_backend_type = tpm.add_element('backend')
|
186
|
-
tpm_backend_type.attributes['type'] = config.tpm_type
|
187
|
-
tpm_device_path = tpm_backend_type.add_element('device')
|
188
|
-
tpm_device_path.attributes['path'] = config.tpm_path
|
189
|
-
else
|
190
|
-
if tpm.attributes['model'] != config.tpm_model
|
191
|
-
descr_changed = true
|
192
|
-
tpm.attributes['model'] = config.tpm_model
|
193
|
-
end
|
194
|
-
if tpm.elements['backend'].attributes['type'] != config.tpm_type
|
195
|
-
descr_changed = true
|
196
|
-
tpm.elements['backend'].attributes['type'] = config.tpm_type
|
197
|
-
end
|
198
|
-
if tpm.elements['backend'].elements['device'].attributes['path'] != config.tpm_path
|
199
|
-
descr_changed = true
|
200
|
-
tpm.elements['backend'].elements['device'].attributes['path'] = config.tpm_path
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# Video device
|
206
|
-
video = REXML::XPath.first(xml_descr, '/domain/devices/video')
|
207
|
-
if !video.nil? && (config.graphics_type == 'none')
|
208
|
-
# graphics_type = none, video devices are removed since there is no possible output
|
209
|
-
descr_changed = true
|
210
|
-
video.parent.delete_element(video)
|
211
|
-
else
|
212
|
-
video_model = REXML::XPath.first(xml_descr, '/domain/devices/video/model')
|
213
|
-
if video_model.nil?
|
214
|
-
video_model = REXML::Element.new('model', REXML::XPath.first(xml_descr, '/domain/devices/video'))
|
215
|
-
video_model.attributes['type'] = config.video_type
|
216
|
-
video_model.attributes['vram'] = config.video_vram
|
217
|
-
else
|
218
|
-
if video_model.attributes['type'] != config.video_type || video_model.attributes['vram'] != config.video_vram
|
219
|
-
descr_changed = true
|
220
|
-
video_model.attributes['type'] = config.video_type
|
221
|
-
video_model.attributes['vram'] = config.video_vram
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
# Sound device
|
227
|
-
if config.sound_type
|
228
|
-
sound = REXML::XPath.first(xml_descr,'/domain/devices/sound/model')
|
229
|
-
end
|
230
|
-
|
231
|
-
|
232
|
-
# dtb
|
233
|
-
if config.dtb
|
234
|
-
dtb = REXML::XPath.first(xml_descr, '/domain/os/dtb')
|
235
|
-
if dtb.nil?
|
236
|
-
descr_changed = true
|
237
|
-
dtb = REXML::Element.new('dtb', REXML::XPath.first(xml_descr, '/domain/os'))
|
238
|
-
dtb.text = config.dtb
|
239
|
-
else
|
240
|
-
if dtb.text != config.dtb
|
241
|
-
descr_changed = true
|
242
|
-
dtb.text = config.dtb
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
# kernel and initrd
|
248
|
-
if config.kernel
|
249
|
-
kernel = REXML::XPath.first(xml_descr, '/domain/os/kernel')
|
250
|
-
if kernel.nil?
|
251
|
-
descr_changed = true
|
252
|
-
kernel = REXML::Element.new('kernel', REXML::XPath.first(xml_descr, '/domain/os'))
|
253
|
-
kernel.text = config.kernel
|
254
|
-
else
|
255
|
-
if kernel.text != config.kernel
|
256
|
-
descr_changed = true
|
257
|
-
kernel.text = config.kernel
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
if config.initrd
|
262
|
-
initrd = REXML::XPath.first(xml_descr, '/domain/os/initrd')
|
263
|
-
if initrd.nil?
|
264
|
-
descr_changed = true
|
265
|
-
initrd = REXML::Element.new('initrd', REXML::XPath.first(xml_descr, '/domain/os'))
|
266
|
-
initrd.text = config.initrd
|
267
|
-
else
|
268
|
-
if initrd.text != config.initrd
|
269
|
-
descr_changed = true
|
270
|
-
initrd.text = config.initrd
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
# Apply
|
276
|
-
if descr_changed
|
277
|
-
begin
|
278
|
-
libvirt_domain.undefine
|
279
|
-
new_descr = ''
|
280
|
-
xml_descr.write new_descr
|
281
|
-
server = env[:machine].provider.driver.connection.servers.create(xml: new_descr)
|
282
|
-
rescue Fog::Errors::Error => e
|
283
|
-
server = env[:machine].provider.driver.connection.servers.create(xml: descr)
|
284
|
-
raise Errors::FogCreateServerError, error_message: e.message
|
285
|
-
end
|
286
|
-
end
|
287
|
-
rescue => e
|
288
|
-
env[:ui].error("Error when updating domain settings: #{e.message}")
|
289
|
-
end
|
290
|
-
# Autostart with host if enabled in Vagrantfile
|
291
|
-
libvirt_domain.autostart = config.autostart
|
292
|
-
# Actually start the domain
|
293
|
-
domain.start
|
294
|
-
rescue => e
|
295
|
-
raise Errors::FogError, message: e.message
|
296
|
-
end
|
297
|
-
|
298
|
-
@app.call(env)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|