Class: VagrantPlugins::VagrantHyperV::Driver

Inherits:
HyperV::Driver show all
Defined in:
lib/vagrant-windows-hyperv/driver.rb

Instance Method Summary collapse

Methods inherited from HyperV::Driver

#add_swith_to_vm, #create_network_switch, #find_vm_switch_name, #import, #list_net_adapters, #switch_exist

Constructor Details

#initialize(machine) ⇒ Driver

Returns a new instance of Driver.



13
14
15
16
# File 'lib/vagrant-windows-hyperv/driver.rb', line 13

def initialize(machine)
  @vm_id = machine.id
  @machine = machine
end

Instance Method Details

#check_winrmObject



62
63
64
65
# File 'lib/vagrant-windows-hyperv/driver.rb', line 62

def check_winrm
  script_path = local_script_path('check_winrm.ps1')
  execute(script_path, remote_credentials)
end

#export_vm_to(path) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/vagrant-windows-hyperv/driver.rb', line 43

def export_vm_to(path)
  options = {
     vm_id: vm_id,
     path: windows_path(path)
   }
  script_path = local_script_path('export_vm.ps1')
  execute(script_path, options)
end

#get_host_ipObject



67
68
69
70
# File 'lib/vagrant-windows-hyperv/driver.rb', line 67

def get_host_ip
  script_path = local_script_path('host_info.ps1')
  execute(script_path, {})
end

#remote_credentialsObject



22
23
24
25
26
# File 'lib/vagrant-windows-hyperv/driver.rb', line 22

def remote_credentials
  @remote_credentials ||= {  guest_ip: ssh_info[:host],
     username:  ssh_info[:username],
     password: "vagrant" }
end

#run_remote_ps(command, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-windows-hyperv/driver.rb', line 28

def run_remote_ps(command, &block)
  options = remote_credentials.merge(command: command)
  script_path = local_script_path('run_in_remote.ps1')
  # FIXME:  Vagrant's core driver method which executes PowerShell,
  # need to take an &block so that this piece of code can be avoided.
  ps_options = []
  options.each do |key, value|
    ps_options << "-#{key}"
    ps_options << "'#{value}'"
  end
  ps_options << "-ErrorAction" << "Stop"
  opts = { notify: [:stdout, :stderr, :stdin] }
  Vagrant::Util::PowerShell.execute(script_path, *ps_options, **opts, &block)
end

#ssh_infoObject



18
19
20
# File 'lib/vagrant-windows-hyperv/driver.rb', line 18

def ssh_info
  @ssh_info ||= @machine.ssh_info
end

#upload(from, to) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/vagrant-windows-hyperv/driver.rb', line 52

def upload(from, to)
  options = {
    vm_id: vm_id,
    host_path: windows_path(from),
    guest_path: windows_path(to)
  }.merge(remote_credentials)
  script_path = local_script_path('upload_file.ps1')
  execute(script_path, options)
end