mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
feat: add websocket graphics config (#1672)
This adds websocket functionality for VNC. The websocket attribute may be used to specify the port to listen on (with -1 meaning auto-allocation and autoport having no effect due to security reasons).
This commit is contained in:
parent
6c4b7758aa
commit
0363459bec
@ -175,6 +175,9 @@ end
|
||||
or "spice".
|
||||
* `graphics_port` - Sets the port for the display protocol to bind to.
|
||||
Defaults to `-1`, which will be set automatically by libvirt.
|
||||
* `graphics_websocket` - Sets the websocket port for the display protocol to bind to.
|
||||
Defaults to `-1`, which will be set automatically by libvirt.
|
||||
The autoport configuration has no effect on the websocket port due to security reasons.
|
||||
* `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to
|
||||
"127.0.0.1".
|
||||
* `graphics_passwd` - Sets the password for the display protocol. Working for
|
||||
@ -311,6 +314,7 @@ defined domain:
|
||||
* `cpu_mode` - Updated. Pay attention that custom mode is not supported
|
||||
* `graphics_type` - Updated
|
||||
* `graphics_port` - Updated
|
||||
* `graphics_websocket` - Updated
|
||||
* `graphics_ip` - Updated
|
||||
* `graphics_passwd` - Updated
|
||||
* `graphics_autoport` - Updated
|
||||
|
@ -66,6 +66,7 @@ module VagrantPlugins
|
||||
@graphics_type = config.graphics_type
|
||||
@graphics_autoport = config.graphics_autoport
|
||||
@graphics_port = config.graphics_port
|
||||
@graphics_websocket = config.graphics_websocket
|
||||
@graphics_ip = config.graphics_ip
|
||||
@graphics_passwd = config.graphics_passwd
|
||||
@graphics_gl = config.graphics_gl
|
||||
@ -271,6 +272,7 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
env[:ui].info(" -- Graphics Type: #{@graphics_type}")
|
||||
env[:ui].info(" -- Graphics Websocket: #{@graphics_websocket}") if @graphics_websocket != -1
|
||||
if !@graphics_autoport
|
||||
env[:ui].info(" -- Graphics Port: #{@graphics_port}")
|
||||
env[:ui].info(" -- Graphics IP: #{@graphics_ip}")
|
||||
|
@ -280,6 +280,10 @@ module VagrantPlugins
|
||||
graphics.attributes['port'] = config.graphics_port
|
||||
end
|
||||
end
|
||||
if graphics.attributes['websocket'] != config.graphics_websocket.to_s
|
||||
descr_changed = true
|
||||
graphics.attributes['websocket'] = config.graphics_websocket
|
||||
end
|
||||
if graphics.attributes['keymap'] != config.keymap
|
||||
descr_changed = true
|
||||
graphics.attributes['keymap'] = config.keymap
|
||||
@ -544,14 +548,21 @@ 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'}")
|
||||
#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')
|
||||
|
||||
if !graphics.nil?
|
||||
if config.graphics_autoport
|
||||
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
|
||||
|
||||
if config.graphics_websocket == -1
|
||||
env[:ui].info(" -- Graphics Websocket: #{graphics.attributes['websocket']}")
|
||||
end
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
|
@ -121,6 +121,7 @@ module VagrantPlugins
|
||||
attr_accessor :graphics_type
|
||||
attr_accessor :graphics_autoport
|
||||
attr_accessor :graphics_port
|
||||
attr_accessor :graphics_websocket
|
||||
attr_accessor :graphics_passwd
|
||||
attr_accessor :graphics_ip
|
||||
attr_accessor :graphics_gl
|
||||
@ -296,6 +297,7 @@ module VagrantPlugins
|
||||
@graphics_type = UNSET_VALUE
|
||||
@graphics_autoport = UNSET_VALUE
|
||||
@graphics_port = UNSET_VALUE
|
||||
@graphics_websocket = UNSET_VALUE
|
||||
@graphics_ip = UNSET_VALUE
|
||||
@graphics_passwd = UNSET_VALUE
|
||||
@graphics_gl = UNSET_VALUE
|
||||
@ -1025,6 +1027,7 @@ module VagrantPlugins
|
||||
@graphics_passwd = nil
|
||||
end
|
||||
@graphics_port = @graphics_type == 'spice' ? nil : -1 if @graphics_port == UNSET_VALUE
|
||||
@graphics_websocket = @graphics_type == 'spice' ? nil : -1 if @graphics_websocket == UNSET_VALUE
|
||||
@graphics_ip = @graphics_type == 'spice' ? nil : '127.0.0.1' if @graphics_ip == UNSET_VALUE
|
||||
@video_accel3d = false if @video_accel3d == UNSET_VALUE
|
||||
@graphics_gl = @video_accel3d if @graphics_gl == UNSET_VALUE
|
||||
|
@ -259,6 +259,7 @@
|
||||
'type' => @graphics_type,
|
||||
'port' => @graphics_port,
|
||||
'autoport' => @graphics_autoport,
|
||||
'websocket' => @graphics_websocket,
|
||||
'listen' => @graphics_ip,
|
||||
'keymap' => @keymap,
|
||||
'passwd' => @graphics_passwd,
|
||||
|
@ -20,7 +20,7 @@ class EnvironmentHelper
|
||||
1024
|
||||
end
|
||||
|
||||
%w(cpus cpu_mode loader nvram boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms floppies driver).each do |name|
|
||||
%w(cpus cpu_mode loader nvram boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_websocket graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms floppies driver).each do |name|
|
||||
define_method(name.to_sym) do
|
||||
nil
|
||||
end
|
||||
|
@ -66,13 +66,15 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
<<-EOF
|
||||
libvirt.graphics_port = 5900
|
||||
libvirt.graphics_websocket = 5700
|
||||
EOF
|
||||
end
|
||||
|
||||
it 'should emit the graphics port' do
|
||||
it 'should emit the graphics port and websocket' 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(ui).to receive(:info).with(' -- Graphics Websocket: 5700')
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
|
@ -43,7 +43,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -37,7 +37,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -37,7 +37,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -60,7 +60,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -43,7 +43,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -43,7 +43,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -344,7 +344,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
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(ui).to receive(:info).with(' -- Graphics Port: 5900')
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
|
@ -30,7 +30,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -30,7 +30,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -31,7 +31,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -28,7 +28,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -28,7 +28,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -28,7 +28,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -29,7 +29,7 @@
|
||||
<target port='0'/>
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='16384'/>
|
||||
</video>
|
||||
|
@ -48,7 +48,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' websocket='-1'>
|
||||
<listen type='address' address='127.0.0.1'/>
|
||||
</graphics>
|
||||
<audio id='1' type='none'/>
|
||||
|
@ -48,7 +48,7 @@
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<input bus='ps2' type='keyboard'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'>
|
||||
<listen address='127.0.0.1' type='address'/>
|
||||
</graphics>
|
||||
<audio id='1' type='none'/>
|
||||
|
@ -48,7 +48,7 @@
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<input bus='ps2' type='keyboard'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket="-1">
|
||||
<listen address='127.0.0.1' type='address'/>
|
||||
</graphics>
|
||||
<audio id='1' type='none'/>
|
||||
|
@ -50,7 +50,7 @@
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<input bus='ps2' type='keyboard'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'>
|
||||
<listen address='127.0.0.1' type='address'/>
|
||||
</graphics>
|
||||
<audio id='1' type='none'/>
|
||||
|
@ -50,7 +50,7 @@
|
||||
</console>
|
||||
<input bus='ps2' type='mouse'/>
|
||||
<input bus='ps2' type='keyboard'/>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'>
|
||||
<listen address='127.0.0.1' type='address'/>
|
||||
</graphics>
|
||||
<audio id='1' type='none'/>
|
||||
|
@ -660,6 +660,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
|
||||
expect(subject.graphics_type).to eq('vnc')
|
||||
expect(subject.graphics_port).to eq(-1)
|
||||
expect(subject.graphics_websocket).to eq(-1)
|
||||
expect(subject.graphics_ip).to eq('127.0.0.1')
|
||||
expect(subject.graphics_autoport).to eq('yes')
|
||||
expect(subject.channels).to be_empty
|
||||
@ -670,6 +671,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
subject.finalize!
|
||||
|
||||
expect(subject.graphics_port).to eq(nil)
|
||||
expect(subject.graphics_websocket).to eq(nil)
|
||||
expect(subject.graphics_ip).to eq(nil)
|
||||
expect(subject.graphics_autoport).to eq(nil)
|
||||
expect(subject.channels).to match([a_hash_including({:target_name => 'com.redhat.spice.0'})])
|
||||
|
@ -124,7 +124,7 @@
|
||||
</channel>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'>
|
||||
<gl enable='yes'/>
|
||||
</graphics>
|
||||
<video>
|
||||
|
@ -33,7 +33,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -31,7 +31,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -31,7 +31,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -38,7 +38,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -38,7 +38,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -124,7 +124,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -31,7 +31,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
@ -31,7 +31,7 @@
|
||||
</console>
|
||||
<input type='mouse' bus='ps2'>
|
||||
</input>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1'/>
|
||||
</video>
|
||||
|
Loading…
Reference in New Issue
Block a user