2014-02-15 23:29:16 +00:00
|
|
|
require "log4r"
|
2014-02-15 23:38:11 +00:00
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module HyperV
|
|
|
|
module Action
|
|
|
|
class Import
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::hyperv::connection")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
box_directory = env[:machine].box.directory.to_s
|
|
|
|
path = Pathname.new(box_directory.to_s + '/Virtual Machines')
|
|
|
|
config_path = ""
|
|
|
|
path.each_child do |f|
|
|
|
|
config_path = f.to_s if f.extname.downcase == ".xml"
|
|
|
|
end
|
|
|
|
|
|
|
|
path = Pathname.new(box_directory.to_s + '/Virtual Hard Disks')
|
|
|
|
vhdx_path = ""
|
|
|
|
path.each_child do |f|
|
|
|
|
vhdx_path = f.to_s if f.extname.downcase == ".vhdx"
|
|
|
|
end
|
|
|
|
|
|
|
|
options = {
|
|
|
|
vm_xml_config: config_path.gsub("/", "\\"),
|
|
|
|
vhdx_path: vhdx_path.gsub("/", "\\")
|
|
|
|
}
|
|
|
|
|
|
|
|
env[:ui].info "Importing a Hyper-V instance"
|
2014-02-16 00:35:04 +00:00
|
|
|
server = env[:machine].provider.driver.execute('import_vm.ps1', options)
|
2014-02-15 23:29:16 +00:00
|
|
|
env[:ui].info "Successfully imported a VM with name #{server['name']}"
|
|
|
|
env[:machine].id = server["id"]
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|