2014-02-15 23:29:16 +00:00
|
|
|
require "log4r"
|
2014-02-16 00:28:11 +00:00
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module HyperV
|
|
|
|
module Action
|
|
|
|
class ReadState
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::hyperv::connection")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
if env[:machine].id
|
|
|
|
begin
|
|
|
|
options = { vm_id: env[:machine].id }
|
|
|
|
response = env[:machine].provider.driver.execute('get_vm_status.ps1', options)
|
|
|
|
env[:machine_state_id] = response["state"].downcase.to_sym
|
2014-02-16 00:28:11 +00:00
|
|
|
rescue Error::SubprocessError
|
2014-02-15 23:29:16 +00:00
|
|
|
env[:machine].id = nil
|
|
|
|
env[:ui].info "Could not find a machine, assuming it to be deleted or terminated."
|
|
|
|
env[:machine_state_id] = :not_created
|
|
|
|
end
|
|
|
|
else
|
|
|
|
env[:machine_state_id] = :not_created
|
|
|
|
end
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|