Class: VagrantPlugins::WinAzure::Driver

Inherits:
HyperV::Driver
  • Object
show all
Defined in:
lib/vagrant-azure/driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Driver

Returns a new instance of Driver.



11
12
13
14
# File 'lib/vagrant-azure/driver.rb', line 11

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

Instance Method Details

#check_winrmObject



63
64
65
66
# File 'lib/vagrant-azure/driver.rb', line 63

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

#remote_credentialsObject



23
24
25
26
27
28
29
30
# File 'lib/vagrant-azure/driver.rb', line 23

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

#run_remote_ps(command, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vagrant-azure/driver.rb', line 32

def run_remote_ps(command, &block)
  options = remote_credentials.merge(command: command)
  script_path = local_script_path('run_in_remote.ps1')

  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



16
17
18
19
20
21
# File 'lib/vagrant-azure/driver.rb', line 16

def ssh_info
  @ssh_info ||= @machine.provider.winrm_info
  @ssh_info[:username] ||= @machine.config.ssh.username
  @ssh_info[:password] ||= @machine.config.ssh.password
  @ssh_info
end

#upload(from, to) ⇒ Object



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

def upload(from, to)
  options = {
    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