Add support for clock setup (#1047)

This adds support for setting clock offset and timers.

See https://libvirt.org/formatdomain.html#elementsTime for more info.
This commit is contained in:
zzambers
2020-12-16 20:19:24 +01:00
committed by GitHub
parent 92964823d0
commit d0787c803d
14 changed files with 275 additions and 6 deletions

View File

@@ -42,6 +42,8 @@ module VagrantPlugins
@nodeset = config.nodeset
@features = config.features
@features_hyperv = config.features_hyperv
@clock_offset = config.clock_offset
@clock_timers = config.clock_timers
@shares = config.shares
@cpu_mode = config.cpu_mode
@cpu_model = config.cpu_model
@@ -226,6 +228,10 @@ module VagrantPlugins
@features_hyperv.each do |feature|
env[:ui].info(" -- Feature (HyperV): name=#{feature[:name]}, state=#{feature[:state]}")
end
env[:ui].info(" -- Clock offset: #{@clock_offset}")
@clock_timers.each do |timer|
env[:ui].info(" -- Clock timer: #{timer.map { |k,v| "#{k}=#{v}"}.join(', ')}")
end
env[:ui].info(" -- Memory: #{@memory_size / 1024}M")
unless @nodeset.nil?
env[:ui].info(" -- Nodeset: #{@nodeset}")

View File

@@ -37,6 +37,9 @@ module VagrantPlugins
xml_descr = REXML::Document.new descr
descr_changed = false
# For outputting XML for comparison
formatter = REXML::Formatters::Pretty.new
# additional disk bus
config.disks.each do |disk|
device = disk[:device]
@@ -152,6 +155,34 @@ module VagrantPlugins
end
end
# Clock
clock = REXML::XPath.first(xml_descr, '/domain/clock')
if clock.attributes['offset'] != config.clock_offset
@logger.debug "clock offset changed"
descr_changed = true
clock.attributes['offset'] = config.clock_offset
end
# clock timers - because timers can be added/removed, just rebuild and then compare
if !config.clock_timers.empty? || clock.has_elements?
oldclock = ''
formatter.write(REXML::XPath.first(xml_descr, '/domain/clock'), oldclock)
clock.delete_element('//timer')
config.clock_timers.each do |clock_timer|
timer = REXML::Element.new('timer', clock)
clock_timer.each do |attr, value|
timer.attributes[attr.to_s] = value
end
end
newclock = ''
formatter.write(clock, newclock)
unless newclock.eql? oldclock
@logger.debug "clock timers config changed"
descr_changed = true
end
end
# Graphics
graphics = REXML::XPath.first(xml_descr, '/domain/devices/graphics')
if config.graphics_type != 'none'

View File

@@ -84,6 +84,8 @@ module VagrantPlugins
attr_accessor :shares
attr_accessor :features
attr_accessor :features_hyperv
attr_accessor :clock_offset
attr_accessor :clock_timers
attr_accessor :numa_nodes
attr_accessor :loader
attr_accessor :nvram
@@ -222,6 +224,8 @@ module VagrantPlugins
@shares = UNSET_VALUE
@features = UNSET_VALUE
@features_hyperv = UNSET_VALUE
@clock_offset = UNSET_VALUE
@clock_timers = []
@numa_nodes = UNSET_VALUE
@loader = UNSET_VALUE
@nvram = UNSET_VALUE
@@ -392,6 +396,25 @@ module VagrantPlugins
state: options[:state])
end
def clock_timer(options = {})
if options[:name].nil?
raise 'Clock timer name must be specified'
end
options.each do |key, value|
case key
when :name, :track, :tickpolicy, :frequency, :mode, :present
if value.nil?
raise "Value of timer option #{key} is nil"
end
else
raise "Unknown clock timer option: #{key}"
end
end
@clock_timers.push(options.dup)
end
def cputopology(options = {})
if options[:sockets].nil? || options[:cores].nil? || options[:threads].nil?
raise 'CPU topology must have all of sockets, cores and threads specified'
@@ -762,6 +785,8 @@ module VagrantPlugins
@shares = nil if @shares == UNSET_VALUE
@features = ['acpi','apic','pae'] if @features == UNSET_VALUE
@features_hyperv = [] if @features_hyperv == UNSET_VALUE
@clock_offset = 'utc' if @clock_offset == UNSET_VALUE
@clock_timers = [] if @clock_timers == UNSET_VALUE
@numa_nodes = @numa_nodes == UNSET_VALUE ? nil : _generate_numa
@loader = nil if @loader == UNSET_VALUE
@nvram = nil if @nvram == UNSET_VALUE
@@ -903,6 +928,10 @@ module VagrantPlugins
c += other.cdroms
result.cdroms = c
c = clock_timers.dup
c += other.clock_timers
result.clock_timers = c
c = qemu_env != UNSET_VALUE ? qemu_env.dup : {}
c.merge!(other.qemu_env) if other.qemu_env != UNSET_VALUE
result.qemu_env = c

View File

@@ -104,7 +104,11 @@
</hyperv>
<% end %>
</features>
<clock offset='utc'/>
<clock offset='<%= @clock_offset %>'>
<% @clock_timers.each do |clock_timer| %>
<timer<% clock_timer.each do |attr, value| %> <%= attr %>='<%= value %>'<% end %>/>
<% end %>
</clock>
<devices>
<% if @emulator_path %>
<emulator><%= @emulator_path %></emulator>