vagrant-azure 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +19 -15
  3. data/CHANGELOG.md +24 -24
  4. data/Gemfile +20 -15
  5. data/LICENSE +4 -4
  6. data/README.md +189 -125
  7. data/Rakefile +15 -14
  8. data/lib/vagrant-azure.rb +31 -33
  9. data/lib/vagrant-azure/action.rb +267 -243
  10. data/lib/vagrant-azure/action/connect_azure.rb +49 -46
  11. data/lib/vagrant-azure/action/os_type.rb +34 -0
  12. data/lib/vagrant-azure/action/powershell_run.rb +28 -0
  13. data/lib/vagrant-azure/action/provision.rb +42 -49
  14. data/lib/vagrant-azure/action/rdp.rb +63 -62
  15. data/lib/vagrant-azure/action/read_ssh_info.rb +54 -51
  16. data/lib/vagrant-azure/action/read_state.rb +47 -46
  17. data/lib/vagrant-azure/action/read_winrm_info.rb +57 -0
  18. data/lib/vagrant-azure/action/restart_vm.rb +28 -27
  19. data/lib/vagrant-azure/action/run_instance.rb +123 -115
  20. data/lib/vagrant-azure/action/start_instance.rb +35 -35
  21. data/lib/vagrant-azure/action/stop_instance.rb +42 -38
  22. data/lib/vagrant-azure/action/sync_folders.rb +64 -63
  23. data/lib/vagrant-azure/action/terminate_instance.rb +34 -34
  24. data/lib/vagrant-azure/action/vagrant_azure_service.rb +44 -43
  25. data/lib/vagrant-azure/action/wait_for_communicate.rb +39 -38
  26. data/lib/vagrant-azure/action/wait_for_state.rb +50 -49
  27. data/lib/vagrant-azure/capabilities/winrm.rb +12 -0
  28. data/lib/vagrant-azure/command/powershell.rb +43 -0
  29. data/lib/vagrant-azure/command/rdp.rb +24 -0
  30. data/lib/vagrant-azure/config.rb +158 -147
  31. data/lib/vagrant-azure/driver.rb +48 -84
  32. data/lib/vagrant-azure/errors.rb +28 -27
  33. data/lib/vagrant-azure/monkey_patch/azure.rb +46 -0
  34. data/lib/vagrant-azure/monkey_patch/winrm.rb +77 -0
  35. data/lib/vagrant-azure/plugin.rb +102 -91
  36. data/lib/vagrant-azure/provider.rb +74 -70
  37. data/lib/vagrant-azure/provisioner/chef-solo.rb +178 -177
  38. data/lib/vagrant-azure/provisioner/puppet.rb +116 -115
  39. data/lib/vagrant-azure/version.rb +11 -10
  40. data/locales/en.yml +37 -37
  41. data/templates/provisioners/chef-solo/solo.erb +51 -51
  42. data/vagrant-azure.gemspec +59 -58
  43. metadata +48 -38
  44. data/lib/vagrant-azure/command/rdp/command.rb +0 -21
  45. data/lib/vagrant-azure/communication/powershell.rb +0 -41
  46. data/lib/vagrant-azure/monkey_patch/machine.rb +0 -22
  47. data/lib/vagrant-azure/provisioner/shell.rb +0 -83
  48. data/lib/vagrant-azure/scripts/check_winrm.ps1 +0 -47
  49. data/lib/vagrant-azure/scripts/export_vm.ps1 +0 -31
  50. data/lib/vagrant-azure/scripts/file_sync.ps1 +0 -145
  51. data/lib/vagrant-azure/scripts/host_info.ps1 +0 -25
  52. data/lib/vagrant-azure/scripts/hyperv_manager.ps1 +0 -36
  53. data/lib/vagrant-azure/scripts/run_in_remote.ps1 +0 -32
  54. data/lib/vagrant-azure/scripts/upload_file.ps1 +0 -95
  55. data/lib/vagrant-azure/scripts/utils/create_session.ps1 +0 -34
  56. data/lib/vagrant-azure/scripts/utils/write_messages.ps1 +0 -18
@@ -1,21 +0,0 @@
1
- #--------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
- module VagrantPlugins
6
- module WinAzure
7
- class Command < Vagrant.plugin('2', :command)
8
- def self.synopsis
9
- 'Opens an RDP session for a vagrant machine'
10
- end
11
-
12
- def execute
13
- with_target_vms do |vm|
14
- vm.action(:rdp)
15
- end
16
-
17
- 0
18
- end
19
- end
20
- end
21
- end
@@ -1,41 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- module VagrantPlugins
7
- module WinAzure
8
- module Communicator
9
- class PowerShell < Vagrant.plugin("2", :communicator)
10
- def initialize(machine)
11
- @machine = machine
12
- end
13
-
14
- def wait_for_ready(timeout)
15
- ready?
16
- end
17
-
18
- def ready?
19
- # Return True when the guest has enabled WinRM
20
- # In this case we can try any remote PowerShell commands to see if
21
- # further vagrant can be carried out using this communication
22
- if !@winrm_status
23
- status = false
24
- response = @machine.provider.driver.check_winrm
25
- message = nil
26
- if response && response["message"]
27
- message = response["message"]
28
- @winrm_status = message == "Running"
29
- end
30
- raise Errors::WinRMNotReady, message: message if !@winrm_status
31
- end
32
- @winrm_status
33
- end
34
-
35
- def test(command, opts=nil)
36
- true
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,22 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- module Vagrant
7
- class Machine
8
-
9
- ssh_communicate = instance_method(:communicate)
10
-
11
- define_method(:communicate) do
12
- unless @communicator
13
- if @config.vm.guest == :windows
14
- @communicator = VagrantPlugins::WinAzure::Communicator::PowerShell.new(self)
15
- else
16
- @communicator = ssh_communicate.bind(self).()
17
- end
18
- end
19
- @communicator
20
- end
21
- end
22
- end
@@ -1,83 +0,0 @@
1
- #---------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #---------------------------------------------------------------------------
5
- module VagrantPlugins
6
- module WinAzure
7
- module Provisioner
8
- class Shell
9
- attr_reader :provisioner
10
-
11
- def initialize(env)
12
- @env = env
13
- @provisioner = env[:provisioner]
14
- end
15
-
16
- def provision_for_windows
17
- arguments = ''
18
- arguments = "#{config.args}" if config.args
19
-
20
- with_windows_script_file do |path|
21
- guest_path = if File.extname(config.upload_path) == ''
22
- "#{config.upload_path}#{File.extname(path.to_s)}"
23
- else
24
- config.upload_path
25
- end
26
-
27
- @env[:ui].detail "Uploading [#{path}] to [#{guest_path}]"
28
-
29
- response = @env[:machine].provider.driver.upload(path, guest_path)
30
-
31
- command = "powershell.exe #{guest_path} #{arguments}"
32
- @env[:machine].provider.driver.run_remote_ps(
33
- command
34
- ) do |type, data|
35
- if type == :stdout || type == :stderr
36
- @env[:ui].detail data
37
- end
38
- end
39
- end
40
- end
41
-
42
- protected
43
-
44
- def config
45
- provisioner.config
46
- end
47
-
48
- def with_windows_script_file
49
- if config.remote?
50
- download_path = @env[:machine].env.tmp_path.join(
51
- "#{env[:mahine].id}-remote-script#{File.extname(config.path)}"
52
- )
53
-
54
- download_path.delete if download_path.file?
55
-
56
- begin
57
- Vagrant::Util::Downloader.new(
58
- config.path, download_path
59
- ).download!
60
- yield download_path
61
- ensure
62
- download_path.delete
63
- end
64
- elsif config.path
65
- yield config.path
66
- else
67
- # We have an inline script. Create a temp file and handle it.
68
- file = Tempfile.new(['vagrant-powershell', '.ps1'])
69
-
70
- begin
71
- file.write(config.inline)
72
- file.fsync
73
- file.close
74
- yield file.path
75
- ensure
76
- file.close
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,47 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- param (
7
- [string]$guest_ip = $(throw "-guest_ip is required."),
8
- [string]$username = $(throw "-guest_username is required."),
9
- [string]$password = $(throw "-guest_password is required."),
10
- [string]$guest_port = $(throw "-guest_port is required")
11
- )
12
-
13
- # Include the following modules
14
- $presentDir = Split-Path -parent $PSCommandPath
15
- . ([System.IO.Path]::Combine($presentDir, "utils\write_messages.ps1"))
16
- . ([System.IO.Path]::Combine($presentDir, "utils\create_session.ps1"))
17
-
18
- try {
19
- $response = Create-Remote-Session $guest_ip $guest_port $username $password
20
- if (!$response["session"] -and $response["error"]) {
21
- $session_message = $response['error']
22
- $resultHash = @{
23
- message = "$session_message"
24
- }
25
- Write-Output-Message $resultHash
26
- return
27
- }
28
- function Remote-Execute() {
29
- $winrm_state = ""
30
- get-service winrm | ForEach-Object {
31
- $winrm_state = $_.status
32
- }
33
- return "$winrm_state"
34
- }
35
- $result = Invoke-Command -Session $response["session"] -ScriptBlock ${function:Remote-Execute} -ErrorAction "stop"
36
- $resultHash = @{
37
- message = "$result"
38
- }
39
- Write-Output-Message $resultHash
40
- } catch {
41
- $errortHash = @{
42
- type = "PowerShellError"
43
- error ="$_"
44
- }
45
- Write-Error-Message $errortHash
46
- return
47
- }
@@ -1,31 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- param (
7
- [string]$vm_id = $(throw "-vm_id is required."),
8
- [string]$path = $(throw "-path is required.")
9
- )
10
-
11
- # Include the following modules
12
- $presentDir = Split-Path -parent $PSCommandPath
13
- . ([System.IO.Path]::Combine($presentDir, "utils\write_messages.ps1"))
14
-
15
-
16
- # Export the Virtual Machine
17
- try {
18
- $vm = Get-Vm -Id $vm_id
19
- $vm | Export-VM -Path $path -ErrorAction "stop"
20
- $name = $vm.name
21
- $resultHash = @{
22
- name = "$name"
23
- }
24
- Write-Output-Message $resultHash
25
- } catch {
26
- $errortHash = @{
27
- type = "PowerShellError"
28
- error = "Failed to export a VM $_"
29
- }
30
- Write-Error-Message $errortHash
31
- }
@@ -1,145 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- param (
7
- [string]$vm_id = $(throw "-vm_id is required."),
8
- [string]$guest_ip = $(throw "-guest_ip is required."),
9
- [string]$username = $(throw "-guest_username is required."),
10
- [string]$password = $(throw "-guest_password is required."),
11
- [string]$host_path = $(throw "-host_path is required."),
12
- [string]$guest_path = $(throw "-guest_path is required.")
13
- )
14
-
15
- # Include the following modules
16
- $presentDir = Split-Path -parent $PSCommandPath
17
- $modules = @()
18
- $modules += $presentDir + "\utils\write_messages.ps1"
19
- $modules += $presentDir + "\utils\create_session.ps1"
20
- forEach ($module in $modules) { . $module }
21
-
22
- function Get-file-hash($source_path, $delimiter) {
23
- $source_files = @()
24
- (Get-ChildItem $source_path -rec -force | ForEach-Object -Process {
25
- Get-FileHash -Path $_.FullName -Algorithm MD5 } ) |
26
- ForEach-Object -Process {
27
- $source_files += $_.Path.Replace($source_path, "") + $delimiter + $_.Hash
28
- }
29
- $source_files
30
- }
31
-
32
- function Get-remote-file-hash($source_path, $delimiter, $session) {
33
- Invoke-Command -Session $session -ScriptBlock ${function:Get-file-hash} -ArgumentList $source_path, $delimiter
34
- # TODO:
35
- # Check if remote PS Scripting errors
36
- }
37
-
38
- function Sync-Remote-Machine($machine, $remove_files, $copy_files, $host_path, $guest_path) {
39
- ForEach ($item in $copy_files) {
40
- $from = $host_path + $item
41
- $to = $guest_path + $item
42
- # Copy VM can also take a VM object
43
- Copy-VMFile -VM $machine -SourcePath $from -DestinationPath $to -CreateFullPath -FileSource Host -Force
44
- }
45
- }
46
-
47
- function Create-Remote-Folders($empty_source_folders, $guest_path) {
48
-
49
- ForEach ($item in $empty_source_folders) {
50
- $new_name = $guest_path + $item
51
- New-Item "$new_name" -type directory -Force
52
- }
53
- }
54
-
55
- function Create-Guest-Folder($guest_path) {
56
- try {
57
- if (Test-Path $guest_path) {
58
- $junction = Get-Item $guest_path
59
- $junction.Delete()
60
- }
61
- }
62
- # Catch any [IOException]
63
- catch {
64
- Remove-Item "$guest_path" -Force -Recurse
65
- }
66
- New-Item "$guest_path" -type directory -Force
67
- }
68
-
69
- function Get-Empty-folders-From-Source($host_path) {
70
- Get-ChildItem $host_path -recurse |
71
- Where-Object {$_.PSIsContainer -eq $True} |
72
- Where-Object {$_.GetFiles().Count -eq 0} |
73
- Select-Object FullName | ForEach-Object -Process {
74
- $empty_source_folders += ($_.FullName.Replace($host_path, ""))
75
- }
76
- }
77
-
78
- $delimiter = " || "
79
-
80
- $machine = Get-VM -Id $vm_id
81
-
82
- # FIXME: PowerShell guys please fix this.
83
- # The below script checks for all VMIntegrationService which are not enabled
84
- # and will enable this.
85
- # When when all the services are enabled this throws an error.
86
- # Enable VMIntegrationService to true
87
- try {
88
- Get-VM -Id $vm_id | Get-VMIntegrationService -Name "Guest Service Interface" | Enable-VMIntegrationService -Passthru
89
- }
90
- catch { }
91
-
92
-
93
- $response = Create-Remote-Session $guest_ip $username $password
94
- if (!$response["session"] -and $response["error"]) {
95
- $errortHash = @{
96
- type = "PowerShellError"
97
- error = $response["error"]
98
- }
99
- Write-Error-Message $errortHash
100
- return
101
- }
102
-
103
- $session = $response["session"]
104
- # Create the guest folder if not exist
105
- $result = Invoke-Command -Session $session -ScriptBlock ${function:Create-Guest-Folder} -ArgumentList $guest_path
106
-
107
-
108
- $source_files = Get-file-hash $host_path $delimiter
109
- $destination_files = Get-remote-file-hash $guest_path $delimiter $session
110
-
111
- if (!$destination_files) {
112
- $destination_files = @()
113
- }
114
- if (!$source_files) {
115
- $source_files = @()
116
- }
117
-
118
- # Compare source and destination files
119
- $remove_files = @()
120
- $copy_files = @()
121
-
122
-
123
- Compare-Object -ReferenceObject $source_files -DifferenceObject $destination_files | ForEach-Object {
124
- if ($_.SideIndicator -eq '=>') {
125
- $remove_files += $_.InputObject.Split($delimiter)[0]
126
- } else {
127
- $copy_files += $_.InputObject.Split($delimiter)[0]
128
- }
129
- }
130
-
131
- # Update the files to remote machine
132
- Sync-Remote-Machine $machine $remove_files $copy_files $host_path $guest_path
133
-
134
- # Create any empty folders which missed to sync to remote machine
135
- $empty_source_folders = @()
136
- $directories = Get-Empty-folders-From-Source $host_path
137
-
138
- $result = Invoke-Command -Session $session -ScriptBlock ${function:Create-Remote-Folders} -ArgumentList $empty_source_folders, $guest_path
139
- # Always remove the connection after Use
140
- Remove-PSSession -Id $session.Id
141
-
142
- $resultHash = @{
143
- message = "OK"
144
- }
145
- Write-Output-Message $resultHash
@@ -1,25 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- # Include the following modules
7
- $presentDir = Split-Path -parent $PSCommandPath
8
- . ([System.IO.Path]::Combine($presentDir, "utils\write_messages.ps1"))
9
-
10
- try {
11
- $hostname = $(whoami)
12
- $ip = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0]
13
- $resultHash = @{
14
- host_name = "$username"
15
- host_ip = "$ip"
16
- }
17
- Write-Output-Message $resultHash
18
- }
19
- catch {
20
- $errortHash = @{
21
- type = "PowerShellError"
22
- error = "$_"
23
- }
24
- Write-Error-Message $errortHash
25
- }
@@ -1,36 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
-
6
- param (
7
- [string]$vm_id = $(throw "-vm_id is required."),
8
- [string]$command = ""
9
- )
10
-
11
- # Include the following modules
12
- $presentDir = Split-Path -parent $PSCommandPath
13
- . ([System.IO.Path]::Combine($presentDir, "utils\write_messages.ps1"))
14
-
15
- try {
16
- $vm = Get-VM -Id $vm_id -ErrorAction "stop"
17
- switch ($command) {
18
- "start" { Start-VM $vm }
19
- "stop" { Stop-VM $vm }
20
- "suspend" { Suspend-VM $vm }
21
- "resume" { Resume-VM $vm }
22
- }
23
-
24
- $state = $vm.state
25
- $status = $vm.status
26
- $name = $vm.name
27
- } catch [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException] {
28
- $state = "not_created"
29
- $status = "Not Created"
30
- }
31
- $resultHash = @{
32
- state = "$state"
33
- status = "$status"
34
- name = "$name"
35
- }
36
- Write-Output-Message $resultHash