vagrant-azure 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/Gemfile +19 -0
  4. data/LICENSE +4 -0
  5. data/README.md +9 -0
  6. data/Rakefile +14 -0
  7. data/lib/vagrant-azure.rb +24 -0
  8. data/lib/vagrant-azure/action.rb +249 -0
  9. data/lib/vagrant-azure/action/connect_azure.rb +41 -0
  10. data/lib/vagrant-azure/action/provision.rb +40 -0
  11. data/lib/vagrant-azure/action/rdp.rb +62 -0
  12. data/lib/vagrant-azure/action/read_ssh_info.rb +51 -0
  13. data/lib/vagrant-azure/action/read_state.rb +46 -0
  14. data/lib/vagrant-azure/action/restart_vm.rb +27 -0
  15. data/lib/vagrant-azure/action/run_instance.rb +111 -0
  16. data/lib/vagrant-azure/action/start_instance.rb +35 -0
  17. data/lib/vagrant-azure/action/stop_instance.rb +38 -0
  18. data/lib/vagrant-azure/action/terminate_instance.rb +34 -0
  19. data/lib/vagrant-azure/action/wait_for_state.rb +49 -0
  20. data/lib/vagrant-azure/command/rdp/command.rb +21 -0
  21. data/lib/vagrant-azure/config.rb +147 -0
  22. data/lib/vagrant-azure/driver.rb +79 -0
  23. data/lib/vagrant-azure/plugin.rb +87 -0
  24. data/lib/vagrant-azure/provider.rb +70 -0
  25. data/lib/vagrant-azure/provisioner/puppet.rb +109 -0
  26. data/lib/vagrant-azure/scripts/check_winrm.ps1 +41 -0
  27. data/lib/vagrant-azure/scripts/export_vm.ps1 +31 -0
  28. data/lib/vagrant-azure/scripts/file_sync.ps1 +145 -0
  29. data/lib/vagrant-azure/scripts/host_info.ps1 +25 -0
  30. data/lib/vagrant-azure/scripts/hyperv_manager.ps1 +36 -0
  31. data/lib/vagrant-azure/scripts/run_in_remote.ps1 +32 -0
  32. data/lib/vagrant-azure/scripts/upload_file.ps1 +95 -0
  33. data/lib/vagrant-azure/scripts/utils/create_session.ps1 +34 -0
  34. data/lib/vagrant-azure/scripts/utils/write_messages.ps1 +18 -0
  35. data/lib/vagrant-azure/version.rb +10 -0
  36. data/locales/en.yml +14 -0
  37. data/vagrant-azure.gemspec +58 -0
  38. metadata +167 -0
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,32 @@
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]$guest_port = $(throw "-guest_port is required."),
9
+ [string]$username = $(throw "-guest_username is required."),
10
+ [string]$password = $(throw "-guest_password is required."),
11
+ [string]$command = ""
12
+ )
13
+
14
+ # Include the following modules
15
+ $presentDir = Split-Path -parent $PSCommandPath
16
+ . ([System.IO.Path]::Combine($presentDir, "utils\write_messages.ps1"))
17
+ . ([System.IO.Path]::Combine($presentDir, "utils\create_session.ps1"))
18
+
19
+ try {
20
+ $response = Create-Remote-Session $guest_ip $guest_port $username $password
21
+ if (!$response["session"] -and $response["error"]) {
22
+ Write-Host $response["error"]
23
+ return
24
+ }
25
+ function Remote-Execute($command) {
26
+ cmd /c $command
27
+ }
28
+ Invoke-Command -Session $response["session"] -ScriptBlock ${function:Remote-Execute} -ArgumentList $command -ErrorAction "stop"
29
+ } catch {
30
+ Write-Host $_
31
+ return
32
+ }
@@ -0,0 +1,95 @@
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]$host_path = $(throw "-host_path is required."),
8
+ [string]$guest_path = $(throw "-guest_path is required."),
9
+ [string]$guest_ip = $(throw "-guest_ip is required."),
10
+ [string]$guest_port = $(throw "-guest_port is required."),
11
+ [string]$username = $(throw "-guest_username is required."),
12
+ [string]$password = $(throw "-guest_password is required.")
13
+ )
14
+
15
+ # Include the following modules
16
+ $presentDir = Split-Path -parent $PSCommandPath
17
+ . ([System.IO.Path]::Combine($presentDir, "utils\write_messages.ps1"))
18
+ . ([System.IO.Path]::Combine($presentDir, "utils\create_session.ps1"))
19
+
20
+ try {
21
+ function Copy-File-To-VM($path, $content) {
22
+ if (!(Test-Path $path)) {
23
+ $folder = Split-Path $path
24
+ New-Item $folder -type directory -Force
25
+ }
26
+
27
+ [IO.File]::WriteAllBytes($path, $content)
28
+ }
29
+
30
+ function Upload-FIle-To-VM($host_path, $guest_path, $session) {
31
+ $contents = [IO.File]::ReadAllBytes($host_path)
32
+ Invoke-Command -Session $session -ScriptBlock ${function:Copy-File-To-VM} -ArgumentList $guest_path,$contents
33
+ }
34
+
35
+ function Prepare-Guest-Folder($session) {
36
+ # Create the guest folder if not exist
37
+ $result = Invoke-Command -Session $session -ScriptBlock ${function:Create-Guest-Folder} -ArgumentList $guest_path
38
+ }
39
+
40
+ function Create-Guest-Folder($guest_path) {
41
+ try {
42
+ if (Test-Path $guest_path) {
43
+ # First attempt to remove a Junction drive. The fall back to removing a
44
+ # folder
45
+ $junction = Get-Item $guest_path
46
+ $junction.Delete()
47
+ }
48
+ }
49
+ # Catch any [IOException]
50
+ catch {
51
+ Remove-Item "$guest_path" -Force -Recurse
52
+ }
53
+ New-Item "$guest_path" -type directory -Force
54
+ }
55
+
56
+ $response = Create-Remote-Session $guest_ip $guest_port $username $password
57
+ if (!$response["session"] -and $response["error"]) {
58
+ $errortHash = @{
59
+ type = "PowerShellError"
60
+ message = $response["error"]
61
+ }
62
+ Write-Error-Message $errorResult
63
+ return
64
+ }
65
+ $session = $response["session"]
66
+
67
+ # When Host path is a folder.
68
+ # Find all files within it and copy to the Guest
69
+ if (Test-Path $host_path -pathtype container) {
70
+ # Open a remote PS Session with the guest
71
+ Prepare-Guest-Folder $session
72
+ # Copy all files from Host path to Guest Path
73
+ Get-ChildItem $host_path -rec |
74
+ Where-Object {$_.PSIsContainer -eq $false} |
75
+ ForEach-Object -Process {
76
+ $file_name = $_.Fullname.SubString($host_path.length)
77
+ $from = $host_path + $file_name
78
+ $to = $guest_path + $file_name
79
+ Upload-FIle-To-VM $from $to $session
80
+ }
81
+ } elseif (Test-Path $host_path) {
82
+ Upload-FIle-To-VM $host_path $guest_path $session
83
+ }
84
+ $resultHash = @{
85
+ message = "OK"
86
+ }
87
+ Write-Output-Message $resultHash
88
+ } catch {
89
+ $errortHash = @{
90
+ type = "PowerShellError"
91
+ error ="Failed to copy file $_"
92
+ }
93
+ Write-Error-Message $errortHash
94
+ return
95
+ }
@@ -0,0 +1,34 @@
1
+ #-------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+
6
+ function Get-Remote-Session($guest_ip, $guest_port, $username, $password) {
7
+ $secstr = convertto-securestring -AsPlainText -Force -String $password
8
+ $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
9
+ New-PSSession -ComputerName $guest_ip -Port $guest_port -Credential $cred -UseSSL -ErrorAction "stop"
10
+ }
11
+
12
+ function Create-Remote-Session($guest_ip, $guest_port, $username, $password) {
13
+ $count = 0
14
+ $session_error = ""
15
+ $session = ""
16
+ do {
17
+ $count++
18
+ try {
19
+ $session = Get-Remote-Session $guest_ip $guest_port $username $password
20
+ $session_error = ""
21
+ }
22
+ catch {
23
+ Start-Sleep -s 1
24
+ $session_error = $_
25
+ $session = ""
26
+ }
27
+ }
28
+ while (!$session -and $count -lt 20)
29
+
30
+ return @{
31
+ session = $session
32
+ error = $session_error
33
+ }
34
+ }
@@ -0,0 +1,18 @@
1
+ #-------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+
6
+ function Write-Error-Message($message) {
7
+ $result = ConvertTo-Json $message
8
+ Write-Host "===Begin-Error==="
9
+ Write-Host $result
10
+ Write-Host "===End-Error==="
11
+ }
12
+
13
+ function Write-Output-Message($message) {
14
+ $result = ConvertTo-Json $message
15
+ Write-Host "===Begin-Output==="
16
+ Write-Host $result
17
+ Write-Host "===End-Output==="
18
+ }
@@ -0,0 +1,10 @@
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
+ VERSION = '1.0.1'
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ en:
2
+ vagrant_azure:
3
+ not_created: |-
4
+ The machine does not exist. Please run `vagrant up` first.
5
+ will_not_destroy: |-
6
+ The machine '%{name}' will not be destroyed as the user declined confirmation.
7
+ already_status: |-
8
+ The machine is already %{status}.
9
+ stopping: |-
10
+ Stopping '%{vm_name}' in '%{cloud_service_name}'
11
+ rdp_not_ready: |-
12
+ RDP not ready
13
+ vm_started: |-
14
+ VM '%{name}' has been started
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-azure/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "vagrant-azure"
8
+ s.version = VagrantPlugins::WinAzure::VERSION
9
+ s.authors = ["MSOpenTech"]
10
+ s.description = "Enable Vagrant to manage machines in Azure"
11
+ s.summary = "Enable Vagrant to manage machines in Azure"
12
+ s.homepage = "https://github.com/MSOpenTech/vagrant-azure"
13
+ s.license = "Apache 2.0"
14
+
15
+ s.require_paths = ["lib"]
16
+
17
+ # The following block of code determines the files that should be included
18
+ # in the gem. It does this by reading all the files in the directory where
19
+ # this gemspec is, and parsing out the ignored files from the gitignore.
20
+ # Note that the entire gitignore(5) syntax is not supported, specifically
21
+ # the "!" syntax, but it should mostly work correctly.
22
+ root_path = File.dirname(__FILE__)
23
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
24
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
25
+ gitignore_path = File.join(root_path, ".gitignore")
26
+ gitignore = File.readlines(gitignore_path)
27
+ gitignore.map! { |line| line.chomp.strip }
28
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
29
+
30
+ unignored_files = all_files.reject do |file|
31
+ # Ignore any directories, the gemspec only cares about files
32
+ next true if File.directory?(file)
33
+
34
+ # Ignore any paths that match anything in the gitignore. We do
35
+ # two tests here:
36
+ #
37
+ # - First, test to see if the entire path matches the gitignore.
38
+ # - Second, match if the basename does, this makes it so that things
39
+ # like '.DS_Store' will match sub-directories too (same behavior
40
+ # as git).
41
+ #
42
+ gitignore.any? do |ignore|
43
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
44
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
45
+ end
46
+ end
47
+
48
+ s.files = unignored_files
49
+ s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
50
+
51
+ s.add_runtime_dependency "azure", "0.6.3"
52
+
53
+ s.add_development_dependency "bundler", "~> 1.3"
54
+ s.add_development_dependency "rake"
55
+ s.add_development_dependency "minitest"
56
+ s.add_development_dependency "minitest-reporters"
57
+ s.add_development_dependency "mocha"
58
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-azure
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - MSOpenTech
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: azure
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Enable Vagrant to manage machines in Azure
98
+ email:
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - example_box/metadata.json
104
+ - example_box/vagbuntu.box
105
+ - Gemfile
106
+ - lib/vagrant-azure/action/connect_azure.rb
107
+ - lib/vagrant-azure/action/provision.rb
108
+ - lib/vagrant-azure/action/rdp.rb
109
+ - lib/vagrant-azure/action/read_ssh_info.rb
110
+ - lib/vagrant-azure/action/read_state.rb
111
+ - lib/vagrant-azure/action/restart_vm.rb
112
+ - lib/vagrant-azure/action/run_instance.rb
113
+ - lib/vagrant-azure/action/start_instance.rb
114
+ - lib/vagrant-azure/action/stop_instance.rb
115
+ - lib/vagrant-azure/action/terminate_instance.rb
116
+ - lib/vagrant-azure/action/wait_for_state.rb
117
+ - lib/vagrant-azure/action.rb
118
+ - lib/vagrant-azure/command/rdp/command.rb
119
+ - lib/vagrant-azure/config.rb
120
+ - lib/vagrant-azure/driver.rb
121
+ - lib/vagrant-azure/plugin.rb
122
+ - lib/vagrant-azure/provider.rb
123
+ - lib/vagrant-azure/provisioner/puppet.rb
124
+ - lib/vagrant-azure/scripts/check_winrm.ps1
125
+ - lib/vagrant-azure/scripts/export_vm.ps1
126
+ - lib/vagrant-azure/scripts/file_sync.ps1
127
+ - lib/vagrant-azure/scripts/host_info.ps1
128
+ - lib/vagrant-azure/scripts/hyperv_manager.ps1
129
+ - lib/vagrant-azure/scripts/run_in_remote.ps1
130
+ - lib/vagrant-azure/scripts/upload_file.ps1
131
+ - lib/vagrant-azure/scripts/utils/create_session.ps1
132
+ - lib/vagrant-azure/scripts/utils/write_messages.ps1
133
+ - lib/vagrant-azure/version.rb
134
+ - lib/vagrant-azure.rb
135
+ - LICENSE
136
+ - locales/en.yml
137
+ - manifests/default.pp
138
+ - pkg/vagrant-azure-1.0.0.gem
139
+ - Rakefile
140
+ - README.md
141
+ - vagrant-azure.gemspec
142
+ - .gitignore
143
+ homepage: https://github.com/MSOpenTech/vagrant-azure
144
+ licenses:
145
+ - Apache 2.0
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.0.14
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Enable Vagrant to manage machines in Azure
167
+ test_files: []