Merge pull request #3068 from MSOpenTech/driver-methods
provider/hyperv: move to Driver based model
This commit is contained in:
parent
c9623a2a3f
commit
d1dc010073
|
@ -8,8 +8,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:ui].info("Deleting the machine...")
|
env[:ui].info("Deleting the machine...")
|
||||||
options = { VmId: env[:machine].id }
|
env[:machine].provider.driver.delete_vm
|
||||||
env[:machine].provider.driver.execute('delete_vm.ps1', options)
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,8 +78,7 @@ module VagrantPlugins
|
||||||
options[:switchname] = switch if switch
|
options[:switchname] = switch if switch
|
||||||
|
|
||||||
env[:ui].detail("Creating and registering the VM...")
|
env[:ui].detail("Creating and registering the VM...")
|
||||||
server = env[:machine].provider.driver.execute(
|
server = env[:machine].provider.driver.import(options)
|
||||||
'import_vm.ps1', options)
|
|
||||||
env[:ui].detail("Successfully imported a VM with name: #{server['name']}")
|
env[:ui].detail("Successfully imported a VM with name: #{server['name']}")
|
||||||
env[:machine].id = server["id"]
|
env[:machine].id = server["id"]
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
@ -26,8 +26,7 @@ module VagrantPlugins
|
||||||
begin
|
begin
|
||||||
Timeout.timeout(120) do
|
Timeout.timeout(120) do
|
||||||
begin
|
begin
|
||||||
options = { VmId: env[:machine].id }
|
network_info = env[:machine].provider.driver.read_guest_ip
|
||||||
network_info = env[:machine].provider.driver.execute('get_network_config.ps1', options)
|
|
||||||
host_ip = network_info["ip"]
|
host_ip = network_info["ip"]
|
||||||
sleep 10 if host_ip.empty?
|
sleep 10 if host_ip.empty?
|
||||||
end while host_ip.empty?
|
end while host_ip.empty?
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
|
@ -11,9 +12,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
if env[:machine].id
|
if env[:machine].id
|
||||||
options = { VmId: env[:machine].id }
|
response = env[:machine].provider.driver.get_current_state
|
||||||
response = env[:machine].provider.driver.execute(
|
|
||||||
"get_vm_status.ps1", options)
|
|
||||||
env[:machine_state_id] = response["state"].downcase.to_sym
|
env[:machine_state_id] = response["state"].downcase.to_sym
|
||||||
|
|
||||||
# If the machine isn't created, then our ID is stale, so just
|
# If the machine isn't created, then our ID is stale, so just
|
||||||
|
|
|
@ -8,8 +8,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:ui].info("Resuming the machine...")
|
env[:ui].info("Resuming the machine...")
|
||||||
options = { VmId: env[:machine].id }
|
env[:machine].provider.driver.resume
|
||||||
env[:machine].provider.driver.execute("resume_vm.ps1", options)
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,9 +8,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:ui].output('Starting the machine...')
|
env[:ui].output('Starting the machine...')
|
||||||
options = { vm_id: env[:machine].id }
|
env[:machine].provider.driver.start
|
||||||
env[:machine].provider.driver.execute('start_vm.ps1', options)
|
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,8 +8,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:ui].info("Stopping the machine...")
|
env[:ui].info("Stopping the machine...")
|
||||||
options = { VmId: env[:machine].id }
|
env[:machine].provider.driver.stop
|
||||||
env[:machine].provider.driver.execute('stop_vm.ps1', options)
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,8 +8,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:ui].info("Suspending the machine...")
|
env[:ui].info("Suspending the machine...")
|
||||||
options = { VmId: env[:machine].id }
|
env[:machine].provider.driver.suspend
|
||||||
env[:machine].provider.driver.execute("suspend_vm.ps1", options)
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,8 +23,7 @@ module VagrantPlugins
|
||||||
return if env[:interrupted]
|
return if env[:interrupted]
|
||||||
|
|
||||||
# Try to get the IP
|
# Try to get the IP
|
||||||
network_info = env[:machine].provider.driver.execute(
|
network_info = env[:machine].provider.driver.read_guest_ip
|
||||||
"get_network_config.ps1", VmId: env[:machine].id)
|
|
||||||
guest_ip = network_info["ip"]
|
guest_ip = network_info["ip"]
|
||||||
|
|
||||||
if guest_ip
|
if guest_ip
|
||||||
|
|
|
@ -9,6 +9,12 @@ module VagrantPlugins
|
||||||
class Driver
|
class Driver
|
||||||
ERROR_REGEXP = /===Begin-Error===(.+?)===End-Error===/m
|
ERROR_REGEXP = /===Begin-Error===(.+?)===End-Error===/m
|
||||||
OUTPUT_REGEXP = /===Begin-Output===(.+?)===End-Output===/m
|
OUTPUT_REGEXP = /===Begin-Output===(.+?)===End-Output===/m
|
||||||
|
attr_reader :vm_id, :machine
|
||||||
|
|
||||||
|
def initialize(machine)
|
||||||
|
@vm_id = machine.id
|
||||||
|
@machine = machine
|
||||||
|
end
|
||||||
|
|
||||||
def execute(path, options)
|
def execute(path, options)
|
||||||
r = execute_powershell(path, options)
|
r = execute_powershell(path, options)
|
||||||
|
@ -39,6 +45,38 @@ module VagrantPlugins
|
||||||
return JSON.parse(output_match[1])
|
return JSON.parse(output_match[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_current_state
|
||||||
|
execute('get_vm_status.ps1', { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_vm
|
||||||
|
execute('delete_vm.ps1', { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_guest_ip
|
||||||
|
execute('get_network_config.ps1', { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def resume
|
||||||
|
execute('resume_vm.ps1', { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
execute('start_vm.ps1', { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
execute('stop_vm.ps1', { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def suspend
|
||||||
|
execute("suspend_vm.ps1", { VmId: vm_id })
|
||||||
|
end
|
||||||
|
|
||||||
|
def import(options)
|
||||||
|
execute('import_vm.ps1', options)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def execute_powershell(path, options, &block)
|
def execute_powershell(path, options, &block)
|
||||||
|
|
|
@ -12,7 +12,6 @@ module VagrantPlugins
|
||||||
attr_reader :driver
|
attr_reader :driver
|
||||||
|
|
||||||
def initialize(machine)
|
def initialize(machine)
|
||||||
@driver = Driver.new
|
|
||||||
@machine = machine
|
@machine = machine
|
||||||
|
|
||||||
if !Vagrant::Util::Platform.windows?
|
if !Vagrant::Util::Platform.windows?
|
||||||
|
@ -26,6 +25,16 @@ module VagrantPlugins
|
||||||
if !Vagrant::Util::PowerShell.available?
|
if !Vagrant::Util::PowerShell.available?
|
||||||
raise Errors::PowerShellRequired
|
raise Errors::PowerShellRequired
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This method will load in our driver, so we call it now to
|
||||||
|
# initialize it.
|
||||||
|
machine_id_changed
|
||||||
|
end
|
||||||
|
|
||||||
|
# If the machine ID changed, then we need to rebuild our underlying
|
||||||
|
# driver.
|
||||||
|
def machine_id_changed
|
||||||
|
@driver = Driver.new(@machine)
|
||||||
end
|
end
|
||||||
|
|
||||||
def action(name)
|
def action(name)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
param (
|
param (
|
||||||
[string]$vm_id = $(throw "-vm_id is required.")
|
[string]$VmId = $(throw "-VmId is required.")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include the following modules
|
# Include the following modules
|
||||||
|
@ -9,7 +9,7 @@ $modules += $presentDir + "\utils\write_messages.ps1"
|
||||||
forEach ($module in $modules) { . $module }
|
forEach ($module in $modules) { . $module }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$vm = Get-VM -Id $vm_id -ErrorAction "stop"
|
$vm = Get-VM -Id $VmId -ErrorAction "stop"
|
||||||
Start-VM $vm
|
Start-VM $vm
|
||||||
$state = $vm.state
|
$state = $vm.state
|
||||||
$status = $vm.status
|
$status = $vm.status
|
||||||
|
|
Loading…
Reference in New Issue