adding support for smartcard device

This commit is contained in:
Steffen Froemer
2017-01-12 09:31:12 +01:00
parent 74a5857341
commit 639fb240b8
7 changed files with 74 additions and 0 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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 %>'>