mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Report graphics port after resolving (#1622)
Allow libvirt to start the domain before reading back the XML to retrieve the port assigned automatically for subsequent graphics access when autoport is enabled. Fixes: #992
This commit is contained in:
@@ -258,9 +258,11 @@ module VagrantPlugins
|
||||
env[:ui].info(" -- Kernel: #{@kernel}")
|
||||
env[:ui].info(" -- Initrd: #{@initrd}")
|
||||
env[:ui].info(" -- Graphics Type: #{@graphics_type}")
|
||||
env[:ui].info(" -- Graphics Port: #{@graphics_port}")
|
||||
env[:ui].info(" -- Graphics IP: #{@graphics_ip}")
|
||||
env[:ui].info(" -- Graphics Password: #{@graphics_passwd.nil? ? 'Not defined' : 'Defined'}")
|
||||
if !@graphics_autoport
|
||||
env[:ui].info(" -- Graphics Port: #{@graphics_port}")
|
||||
env[:ui].info(" -- Graphics IP: #{@graphics_ip}")
|
||||
env[:ui].info(" -- Graphics Password: #{@graphics_passwd.nil? ? 'Not defined' : 'Defined'}")
|
||||
end
|
||||
env[:ui].info(" -- Video Type: #{@video_type}")
|
||||
env[:ui].info(" -- Video VRAM: #{@video_vram}")
|
||||
env[:ui].info(" -- Video 3D accel: #{@video_accel3d}")
|
||||
|
||||
@@ -478,6 +478,16 @@ module VagrantPlugins
|
||||
raise Errors::DomainStartError, error_message: e.message
|
||||
end
|
||||
|
||||
if config.graphics_autoport
|
||||
#libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
|
||||
xmldoc = REXML::Document.new(libvirt_domain.xml_desc)
|
||||
graphics = REXML::XPath.first(xmldoc, '/domain/devices/graphics')
|
||||
env[:ui].info(I18n.t('vagrant_libvirt.starting_domain_with_graphics'))
|
||||
env[:ui].info(" -- Graphics Port: #{graphics.attributes['port']}")
|
||||
env[:ui].info(" -- Graphics IP: #{graphics.attributes['listen']}")
|
||||
env[:ui].info(" -- Graphics Password: #{config.graphics_passwd.nil? ? 'Not defined' : 'Defined'}")
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,6 +29,8 @@ en:
|
||||
Updating domain definition due to configuration change
|
||||
starting_domain: |-
|
||||
Starting domain.
|
||||
starting_domain_with_graphics: |-
|
||||
Domain launching with graphics connection settings...
|
||||
terminating: |-
|
||||
Removing domain...
|
||||
poweroff_domain: |-
|
||||
|
||||
@@ -64,6 +64,22 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
|
||||
context 'graphics autoport disabled' do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
<<-EOF
|
||||
libvirt.graphics_port = 5900
|
||||
EOF
|
||||
end
|
||||
|
||||
it 'should emit the graphics port' do
|
||||
expect(servers).to receive(:create).and_return(machine)
|
||||
expect(volumes).to_not receive(:create) # additional disks only
|
||||
expect(ui).to receive(:info).with(' -- Graphics Port: 5900')
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'additional disks' do
|
||||
let(:disks) do
|
||||
[
|
||||
|
||||
@@ -34,6 +34,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
|
||||
allow(logger).to receive(:debug)
|
||||
allow(logger).to receive(:info)
|
||||
allow(ui).to receive(:info)
|
||||
|
||||
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
||||
|
||||
@@ -162,6 +163,28 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
end
|
||||
end
|
||||
|
||||
context 'graphics' do
|
||||
context 'autoport not disabled' do
|
||||
let(:test_file) { 'existing.xml' }
|
||||
let(:launched_domain_xml) {
|
||||
new_xml = domain_xml.dup
|
||||
new_xml.gsub!(/graphics type='vnc' port='-1'/m, "graphics type='vnc' port='5900'")
|
||||
new_xml
|
||||
}
|
||||
|
||||
it 'should retrieve the port from XML' do
|
||||
expect(ui).to_not receive(:warn)
|
||||
expect(connection).to_not receive(:define_domain)
|
||||
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, launched_domain_xml)
|
||||
expect(libvirt_domain).to receive(:autostart=)
|
||||
expect(domain).to receive(:start)
|
||||
expect(ui).to receive(:info).with(' -- Graphics Port: 5900')
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'nvram' do
|
||||
context 'when being added to existing' do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
|
||||
Reference in New Issue
Block a user