providers/hyperv: better errors
This commit is contained in:
parent
a1958ee12f
commit
fb7dd73d95
|
@ -29,12 +29,7 @@ module VagrantPlugins
|
||||||
}
|
}
|
||||||
|
|
||||||
env[:ui].info "Importing a Hyper-V instance"
|
env[:ui].info "Importing a Hyper-V instance"
|
||||||
begin
|
server = env[:machine].provider.driver.execute('import_vm.ps1', options)
|
||||||
server = env[:machine].provider.driver.execute('import_vm.ps1', options)
|
|
||||||
rescue Error::SubprocessError => e
|
|
||||||
env[:ui].info e.message
|
|
||||||
return
|
|
||||||
end
|
|
||||||
env[:ui].info "Successfully imported a VM with name #{server['name']}"
|
env[:ui].info "Successfully imported a VM with name #{server['name']}"
|
||||||
env[:machine].id = server["id"]
|
env[:machine].id = server["id"]
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
@ -2,6 +2,8 @@ require "json"
|
||||||
|
|
||||||
require "vagrant/util/powershell"
|
require "vagrant/util/powershell"
|
||||||
|
|
||||||
|
require_relative "plugin"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module HyperV
|
module HyperV
|
||||||
class Driver
|
class Driver
|
||||||
|
@ -13,9 +15,15 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(path, options)
|
def execute(path, options)
|
||||||
execute_powershell(path, options) do |type, data|
|
r = execute_powershell(path, options) do |type, data|
|
||||||
process_output(type, data)
|
process_output(type, data)
|
||||||
end
|
end
|
||||||
|
if r.exit_code != 0
|
||||||
|
raise Errors::PowerShellError,
|
||||||
|
script: path,
|
||||||
|
stderr: r.stderr
|
||||||
|
end
|
||||||
|
|
||||||
if success?
|
if success?
|
||||||
JSON.parse(json_output[:success].join) unless json_output[:success].empty?
|
JSON.parse(json_output[:success].join) unless json_output[:success].empty?
|
||||||
else
|
else
|
||||||
|
|
|
@ -6,6 +6,10 @@ module VagrantPlugins
|
||||||
error_namespace("vagrant_hyperv.errors")
|
error_namespace("vagrant_hyperv.errors")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class PowerShellError < HyperVError
|
||||||
|
error_key(:powershell_error)
|
||||||
|
end
|
||||||
|
|
||||||
class PowerShellRequired < HyperVError
|
class PowerShellRequired < HyperVError
|
||||||
error_key(:powershell_required)
|
error_key(:powershell_required)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
en:
|
en:
|
||||||
vagrant_hyperv:
|
vagrant_hyperv:
|
||||||
errors:
|
errors:
|
||||||
|
powershell_error: |-
|
||||||
|
An error occurred while executing a PowerShell script. This error
|
||||||
|
is shown below. Please read the error message and see if this is
|
||||||
|
a configuration error with your system. If it is not, then please
|
||||||
|
report a bug.
|
||||||
|
|
||||||
|
Script: %{script}
|
||||||
|
Error:
|
||||||
|
|
||||||
|
%{stderr}
|
||||||
powershell_required: |-
|
powershell_required: |-
|
||||||
The Vagrant Hyper-V provider requires PowerShell to be available.
|
The Vagrant Hyper-V provider requires PowerShell to be available.
|
||||||
Please make sure "powershell.exe" is available on your PATH.
|
Please make sure "powershell.exe" is available on your PATH.
|
||||||
|
|
Loading…
Reference in New Issue