mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
adding support for smartcard device
This commit is contained in:
parent
74a5857341
commit
639fb240b8
22
README.md
22
README.md
@ -53,6 +53,7 @@ In the table below, build passing means that specific version combination of Vag
|
||||
- [USB Redirector Devices](#usb-redirector-devices)
|
||||
- [Random number generator passthrough](#random-number-generator-passthrough)
|
||||
- [Watchdog·Device](#watchdog-device)
|
||||
- [Smartcard device](#smartcard-device)
|
||||
- [CPU Features](#cpu-features)
|
||||
- [No box and PXE boot](#no-box-and-pxe-boot)
|
||||
- [SSH Access To VM](#ssh-access-to-vm)
|
||||
@ -881,6 +882,27 @@ Vagrant.configure("2") do |config|
|
||||
end
|
||||
```
|
||||
|
||||
## Smartcard device
|
||||
A virtual smartcard device can be supplied to the guest via the `libvirt.smartcard` element. The option `mode` is mandatory and currently only value `passthrough` is supported. The value `spicevmc` for option `type` is default value and can be supressed. On using `type = tcp`, the options `source_mode`, `source_host` and `source_service` are mandatory.
|
||||
|
||||
```ruby
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
# Add smartcard device with type 'spicevmc'
|
||||
libvirt.smartcard :mode => 'passthrough', :type => 'spicevmc'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
```ruby
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
# Add smartcard device with type 'tcp'
|
||||
domain.smartcard :mode => 'passthrough', :type => 'tcp', :source_mode => 'bind', :source_host => '127.0.0.1', :source_service => '2001'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## CPU features
|
||||
|
||||
You can specify CPU feature policies via `libvirt.cpu_feature`. Available
|
||||
|
@ -96,6 +96,9 @@ module VagrantPlugins
|
||||
@redirdevs = config.redirdevs
|
||||
@redirfilters = config.redirfilters
|
||||
|
||||
# smartcard device
|
||||
@smartcard_dev = config.smartcard_dev
|
||||
|
||||
# RNG device passthrough
|
||||
@rng = config.rng
|
||||
|
||||
@ -266,6 +269,10 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
|
||||
if not @smartcard_dev.empty?
|
||||
env[:ui].info(" -- smartcard device: mode=#{@smartcard_dev[:mode]}, type=#{@smartcard_dev[:type]}")
|
||||
end
|
||||
|
||||
env[:ui].info(" -- Command line : #{@cmd_line}")
|
||||
|
||||
# Create libvirt domain.
|
||||
|
@ -126,6 +126,9 @@ module VagrantPlugins
|
||||
attr_accessor :redirdevs
|
||||
attr_accessor :redirfilters
|
||||
|
||||
# smartcard device
|
||||
attr_accessor :smartcard_dev
|
||||
|
||||
# Suspend mode
|
||||
attr_accessor :suspend_mode
|
||||
|
||||
@ -218,6 +221,9 @@ module VagrantPlugins
|
||||
@redirdevs = UNSET_VALUE
|
||||
@redirfilters = UNSET_VALUE
|
||||
|
||||
# smartcard device
|
||||
@smartcard_dev = UNSET_VALUE
|
||||
|
||||
# Suspend mode
|
||||
@suspend_mode = UNSET_VALUE
|
||||
|
||||
@ -398,6 +404,26 @@ module VagrantPlugins
|
||||
allow: options[:allow])
|
||||
end
|
||||
|
||||
def smartcard(options = {})
|
||||
if options[:mode].nil?
|
||||
raise 'Option mode must be specified.'
|
||||
elsif options[:mode] != 'passthrough'
|
||||
raise 'Currently only passthrough mode is supported!'
|
||||
elsif options[:type] == 'tcp' && (options[:source_mode].nil? || options[:source_host].nil? || options[:source_service].nil?)
|
||||
raise 'If using type "tcp", option "source_mode", "source_host" and "source_service" must be specified.'
|
||||
end
|
||||
|
||||
if @smartcard_dev == UNSET_VALUE
|
||||
@smartcard_dev = {}
|
||||
end
|
||||
|
||||
@smartcard_dev[:mode] = options[:mode]
|
||||
@smartcard_dev[:type] = options[:type] || 'spicevmc'
|
||||
@smartcard_dev[:source_mode] = options[:source_mode] if @smartcard_dev[:type] == 'tcp'
|
||||
@smartcard_dev[:source_host] = options[:source_host] if @smartcard_dev[:type] == 'tcp'
|
||||
@smartcard_dev[:source_service] = options[:source_service] if @smartcard_dev[:type] == 'tcp'
|
||||
end
|
||||
|
||||
# NOTE: this will run twice for each time it's needed- keep it idempotent
|
||||
def storage(storage_type, options = {})
|
||||
if storage_type == :file
|
||||
@ -604,6 +630,9 @@ module VagrantPlugins
|
||||
@redirdevs = [] if @redirdevs == UNSET_VALUE
|
||||
@redirfilters = [] if @redirfilters == UNSET_VALUE
|
||||
|
||||
# smartcard device
|
||||
@smartcard_dev = {} if @smartcard_dev == UNSET_VALUE
|
||||
|
||||
# Suspend mode
|
||||
@suspend_mode = 'pause' if @suspend_mode == UNSET_VALUE
|
||||
|
||||
|
@ -188,6 +188,18 @@
|
||||
<watchdog model='<%= @watchdog_dev[:model] %>' action='<%= @watchdog_dev[:action] %>'/>
|
||||
<% end %>
|
||||
|
||||
<% unless @smartcard_dev.empty? -%>
|
||||
<% if @smartcard_dev[:mode] == 'passthrough' %>
|
||||
<% if @smartcard_dev[:type] == 'tcp' %>
|
||||
<smartcard mode='<%= @smartcard_dev[:mode] %>' type='<%= @smartcard_dev[:type] %>'>
|
||||
<source mode='<%= @smartcard_dev[:source_mode] %>' host='<%= @smartcard_dev[:source_host] %>' service='<%= @smartcard_dev[:source_service] %>'/>
|
||||
</smartcard>
|
||||
<% else %>
|
||||
<smartcard mode='<%= @smartcard_dev[:mode] %>' type='<%= @smartcard_dev[:type] %>'/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end -%>
|
||||
|
||||
<% if @tpm_path -%>
|
||||
<%# TPM Device -%>
|
||||
<tpm model='<%= @tpm_model %>'>
|
||||
|
@ -117,6 +117,8 @@
|
||||
</redirfilter>
|
||||
<watchdog model='i6300esb' action='reset'/>
|
||||
|
||||
<smartcard mode='passthrough' type='spicevmc'/>
|
||||
|
||||
<tpm model='tpm-tis'>
|
||||
<backend type='passthrough'>
|
||||
<device path='/dev/tpm0'/>
|
||||
|
@ -40,5 +40,6 @@
|
||||
<model type='cirrus' vram='9216' heads='1'/>
|
||||
</video>
|
||||
|
||||
|
||||
</devices>
|
||||
</domain>
|
||||
|
@ -59,6 +59,7 @@ describe 'templates/domain' do
|
||||
domain.redirfilter(class: '0x0b', vendor: '0x08e6',
|
||||
product: '0x3437', version: '2.00', allow: 'yes')
|
||||
domain.watchdog(model: 'i6300esb', action: 'reset')
|
||||
domain.smartcard(mode: 'passthrough')
|
||||
domain.tpm_path = '/dev/tpm0'
|
||||
end
|
||||
let(:test_file) { 'domain_all_settings.xml' }
|
||||
|
Loading…
Reference in New Issue
Block a user