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,46 +1,49 @@
1
- #---------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
- require 'azure'
6
- require 'log4r'
7
-
8
- # FIXME:
9
- # This is a required to patch few exception handling which are not done in
10
- # Azure Ruby SDK
11
- require_relative "vagrant_azure_service"
12
-
13
- module VagrantPlugins
14
- module WinAzure
15
- module Action
16
- class ConnectAzure
17
- def initialize(app, env)
18
- @app = app
19
- @logger = Log4r::Logger.new('vagrant_azure::action::connect_aws')
20
- end
21
-
22
- def call (env)
23
- config = env[:machine].provider_config
24
-
25
- Azure.configure do |c|
26
- c.subscription_id = config.subscription_id
27
- c.management_certificate = config.mgmt_certificate
28
- c.management_endpoint = config.mgmt_endpoint
29
- c.storage_account_name = config.storage_acct_name
30
- c.storage_access_key = config.storage_access_key
31
- end
32
-
33
- # FIXME:
34
- # Defining a new class VagrantAzureService
35
- # Here we call the native azure virtual machine management service method
36
- # and add some exception handling.
37
- # Remove this once the Azure SDK adds the exception handling for the
38
- # methods defined in VagrantAzureService
39
- env[:azure_vm_service] = VagrantAzureService.new(Azure::VirtualMachineManagementService.new)
40
-
41
- @app.call(env)
42
- end
43
- end
44
- end
45
- end
46
- end
1
+ #---------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache License, Version 2.0.
4
+ # See License.txt in the project root for license information.
5
+ #--------------------------------------------------------------------------
6
+ require 'azure'
7
+ require 'log4r'
8
+
9
+ # FIXME:
10
+ # This is a required to patch few exception handling which are not done in
11
+ # Azure Ruby SDK
12
+ require_relative "vagrant_azure_service"
13
+
14
+ module VagrantPlugins
15
+ module WinAzure
16
+ module Action
17
+ class ConnectAzure
18
+ def initialize(app, env)
19
+ @app = app
20
+ @logger = Log4r::Logger.new('vagrant_azure::action::connect_aws')
21
+ end
22
+
23
+ def call (env)
24
+ if env[:azure_vm_service].nil?
25
+ config = env[:machine].provider_config
26
+
27
+ Azure.configure do |c|
28
+ c.subscription_id = config.subscription_id
29
+ c.management_certificate = config.mgmt_certificate
30
+ c.management_endpoint = config.mgmt_endpoint
31
+ c.storage_account_name = config.storage_acct_name
32
+ c.storage_access_key = config.storage_access_key
33
+ end
34
+
35
+ # FIXME:
36
+ # Defining a new class VagrantAzureService
37
+ # Here we call the native azure virtual machine management service method
38
+ # and add some exception handling.
39
+ # Remove this once the Azure SDK adds the exception handling for the
40
+ # methods defined in VagrantAzureService
41
+ env[:azure_vm_service] = VagrantAzureService.new(Azure::VirtualMachineManagementService.new)
42
+ end
43
+
44
+ @app.call(env)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache License, Version 2.0.
4
+ # See License.txt in the project root for license information.
5
+ #--------------------------------------------------------------------------
6
+ require 'log4r'
7
+
8
+ module VagrantPlugins
9
+ module WinAzure
10
+ module Action
11
+ class OSType
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new('vagrant_azure::action::os_type')
15
+ end
16
+
17
+ def call(env)
18
+
19
+ unless env[:machine].config.vm.guest
20
+ env[:ui].info 'Determining OS Type By Image'
21
+ guest_os_type = env[:azure_vm_service].send(:get_os_type, env[:machine].provider_config.vm_image)
22
+ env[:machine].config.vm.guest = guest_os_type && guest_os_type.downcase.to_sym
23
+ if env[:machine].config.vm.guest == :windows && env[:machine].config.vm.communicator.nil?
24
+ env[:machine].config.vm.communicator = :winrm
25
+ end
26
+ env[:ui].info "OS Type is #{guest_os_type}"
27
+ end
28
+
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ module VagrantPlugins
2
+ module WinAzure
3
+ module Action
4
+ class PowerShellRun
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant_azure::action::powershell_run_command')
8
+ end
9
+
10
+ def call(env)
11
+
12
+ if env[:machine].communicate.ready?
13
+ env[:machine].ui.detail("PowerShell Executing: #{env[:powershell_command]}")
14
+ env[:powershell_command_exit_status] = env[:machine].communicate.execute(env[:powershell_command]) do |type, stream|
15
+ if type == :stdout
16
+ env[:machine].ui.success(stream) unless (stream || '').chomp.empty?
17
+ else
18
+ env[:machine].ui.error(stream) unless (stream || '').chomp.empty?
19
+ end
20
+ end
21
+ end
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,49 +1,42 @@
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 Action
9
- class Provision < Vagrant::Action::Builtin::Provision
10
- # Override the core vagrant method and branch out for windows
11
- def run_provisioner(env)
12
- env[:ui].info "Provisioner: #{env[:provisioner].class.to_s}"
13
-
14
- env[:machine].id =~ /@/
15
- vm = env[:azure_vm_service].get_virtual_machine($`, $')
16
- env[:ui].info "VM OS: #{vm.os_type.to_sym}"
17
-
18
- if vm.os_type.to_sym == :Windows
19
- # Raise an error if we're not on a Windows Host.
20
- # Non-Windows OS will be supported once we move to WinRb/WinRm
21
- env[:ui].info "Is Host OS Windows?: #{Vagrant::Util::Platform.windows?}"
22
- raise 'Unsupported OS for Windows Provisioning' unless \
23
- Vagrant::Util::Platform.windows?
24
- env[:ui].info "Provisioning for Windows"
25
-
26
- # TODO: Add Shell, Chef-solo and other provisioners
27
- case env[:provisioner].class.to_s
28
- when "VagrantPlugins::Shell::Provisioner"
29
- VagrantPlugins::WinAzure::Provisioner::Shell.new(
30
- env
31
- ).provision_for_windows
32
- when "VagrantPlugins::Puppet::Provisioner::Puppet"
33
- VagrantPlugins::WinAzure::Provisioner::Puppet.new(
34
- env
35
- ).provision_for_windows
36
- when "VagrantPlugins::Chef::Provisioner::ChefSolo"
37
- VagrantPlugins::WinAzure::Provisioner::ChefSolo.new(
38
- env
39
- ).provision_for_windows
40
- end
41
- else
42
- env[:ui].info "Provisioning using SSH"
43
- env[:provisioner].provision
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
1
+ #---------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache License, Version 2.0.
4
+ # See License.txt in the project root for license information.
5
+ #---------------------------------------------------------------------------
6
+
7
+ module VagrantPlugins
8
+ module WinAzure
9
+ module Action
10
+ class Provision < Vagrant::Action::Builtin::Provision
11
+ # Override the core vagrant method and branch out for windows
12
+ def run_provisioner(env)
13
+ env[:machine].id =~ /@/
14
+ vm = env[:azure_vm_service].get_virtual_machine($`, $')
15
+ env[:ui].info "VM OS: #{vm.os_type.to_sym}"
16
+
17
+ if vm.os_type.to_sym == :Windows
18
+ env[:ui].info 'Provisioning for Windows'
19
+
20
+ case env[:provisioner].class.to_s
21
+ when 'VagrantPlugins::Shell::Provisioner'
22
+ env[:provisioner].provision
23
+ when 'VagrantPlugins::Puppet::Provisioner::Puppet'
24
+ VagrantPlugins::WinAzure::Provisioner::Puppet.new(
25
+ env
26
+ ).provision_for_windows
27
+ when 'VagrantPlugins::Chef::Provisioner::ChefSolo'
28
+ VagrantPlugins::WinAzure::Provisioner::ChefSolo.new(
29
+ env
30
+ ).provision_for_windows
31
+ else
32
+ env[:provisioner].provision
33
+ end
34
+ else
35
+ env[:ui].info 'Provisioning using SSH'
36
+ env[:provisioner].provision
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,62 +1,63 @@
1
- #--------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
- require 'log4r'
6
- require 'pathname'
7
- require 'vagrant/util/subprocess'
8
- require 'vagrant/util/platform'
9
-
10
- module VagrantPlugins
11
- module WinAzure
12
- module Action
13
- class Rdp
14
- def initialize(app, env)
15
- @app = app
16
- @logger = Log4r::Logger.new('vagrant_azure::action::rdp')
17
- @rdp_file = 'machine.rdp'
18
- end
19
-
20
- def call(env)
21
- if Vagrant::Util::Platform.windows?
22
- generate_rdp_file env[:machine]
23
- command = ['mstsc', @rdp_file]
24
- Vagrant::Util::Subprocess.execute(*command)
25
- elsif Vagrant::Util::Platform.darwin?
26
- generate_rdp_file env[:machine]
27
- command = ['open', @rdp_file]
28
- result = Vagrant::Util::Subprocess.execute(*command)
29
-
30
- if result.exit_code == 1
31
- raise result.stderr
32
- end
33
- else
34
- # TODO: Add support for RDP on *Nix systems
35
- raise 'Unsupported operating system for RDP operation.'
36
- end
37
-
38
- @app.call(env)
39
- end
40
-
41
- def generate_rdp_file(machine)
42
- File.delete(@rdp_file) if File.exists?(@rdp_file)
43
-
44
- info = machine.provider.rdp_info
45
-
46
- rdp_options = {
47
- 'drivestoredirect:s' => '*',
48
- 'username:s' => machine.provider_config.vm_user,
49
- 'prompt for credentials:i' => '1',
50
- 'full address:s' => "#{info[:host]}:#{info[:port]}"
51
- }
52
-
53
- file = File.open(@rdp_file, 'w')
54
- rdp_options.each do |key, value|
55
- file.puts "#{key}:#{value}"
56
- end
57
- file.close
58
- end
59
- end
60
- end
61
- end
62
- end
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache License, Version 2.0.
4
+ # See License.txt in the project root for license information.
5
+ #--------------------------------------------------------------------------
6
+ require 'log4r'
7
+ require 'pathname'
8
+ require 'vagrant/util/subprocess'
9
+ require 'vagrant/util/platform'
10
+
11
+ module VagrantPlugins
12
+ module WinAzure
13
+ module Action
14
+ class Rdp
15
+ def initialize(app, env)
16
+ @app = app
17
+ @logger = Log4r::Logger.new('vagrant_azure::action::rdp')
18
+ @rdp_file = 'machine.rdp'
19
+ end
20
+
21
+ def call(env)
22
+ if Vagrant::Util::Platform.windows?
23
+ generate_rdp_file env[:machine]
24
+ command = ['mstsc', @rdp_file]
25
+ Vagrant::Util::Subprocess.execute(*command)
26
+ elsif Vagrant::Util::Platform.darwin?
27
+ generate_rdp_file env[:machine]
28
+ command = ['open', @rdp_file]
29
+ result = Vagrant::Util::Subprocess.execute(*command)
30
+
31
+ if result.exit_code == 1
32
+ raise result.stderr
33
+ end
34
+ else
35
+ # TODO: Add support for RDP on *Nix systems
36
+ raise 'Unsupported operating system for RDP operation.'
37
+ end
38
+
39
+ @app.call(env)
40
+ end
41
+
42
+ def generate_rdp_file(machine)
43
+ File.delete(@rdp_file) if File.exists?(@rdp_file)
44
+
45
+ info = machine.provider.rdp_info
46
+
47
+ rdp_options = {
48
+ 'drivestoredirect:s' => '*',
49
+ 'username:s' => machine.provider_config.vm_user,
50
+ 'prompt for credentials:i' => '1',
51
+ 'full address:s' => "#{info[:host]}:#{info[:port]}"
52
+ }
53
+
54
+ file = File.open(@rdp_file, 'w')
55
+ rdp_options.each do |key, value|
56
+ file.puts "#{key}:#{value}"
57
+ end
58
+ file.close
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,51 +1,54 @@
1
- #--------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
- require 'log4r'
6
-
7
- module VagrantPlugins
8
- module WinAzure
9
- module Action
10
- class ReadSSHInfo
11
- def initialize(app, env, port = 22)
12
- @app = app
13
- @port = port
14
- @logger = Log4r::Logger.new('vagrant_azure::action::read_ssh_info')
15
- end
16
-
17
- def call(env)
18
- env[:ui].info "Looking for #{@port}"
19
-
20
- env[:machine_ssh_info] = read_ssh_info(
21
- env[:azure_vm_service],
22
- env[:machine]
23
- )
24
-
25
- @app.call(env)
26
- end
27
-
28
- def read_ssh_info(azure, machine)
29
- return nil if machine.id.nil?
30
- machine.id =~ /@/
31
- vm = azure.get_virtual_machine($`, $')
32
-
33
- if vm.nil? || !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine)
34
- # Machine cannot be found
35
- @logger.info 'Machine not found. Assuming it was destroyed'
36
- machine.id = nil
37
- return nil
38
- end
39
-
40
- vm.tcp_endpoints.each do |endpoint|
41
- if endpoint[:local_port] == "#{@port}"
42
- return { :host => "#{vm.cloud_service_name}.cloudapp.net", :port => endpoint[:public_port] }
43
- end
44
- end
45
-
46
- return nil
47
- end
48
- end
49
- end
50
- end
51
- end
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache License, Version 2.0.
4
+ # See License.txt in the project root for license information.
5
+ #--------------------------------------------------------------------------
6
+ require 'log4r'
7
+
8
+ module VagrantPlugins
9
+ module WinAzure
10
+ module Action
11
+ class ReadSSHInfo
12
+ def initialize(app, env, port = 22)
13
+ @app = app
14
+ @port = port
15
+ @logger = Log4r::Logger.new('vagrant_azure::action::read_ssh_info')
16
+ end
17
+
18
+ def call(env)
19
+ env[:ui].info "Looking for local port #{@port}"
20
+
21
+ env[:machine_ssh_info] = read_ssh_info(
22
+ env[:azure_vm_service],
23
+ env[:machine]
24
+ )
25
+
26
+ env[:ui].info "Found port mapping #{env[:machine_ssh_info][:port]} --> #{@port}"
27
+
28
+ @app.call(env)
29
+ end
30
+
31
+ def read_ssh_info(azure, machine)
32
+ return nil if machine.id.nil?
33
+ machine.id =~ /@/
34
+ vm = azure.get_virtual_machine($`, $')
35
+
36
+ if vm.nil? || !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine)
37
+ # Machine cannot be found
38
+ @logger.info 'Machine not found. Assuming it was destroyed'
39
+ machine.id = nil
40
+ return nil
41
+ end
42
+
43
+ vm.tcp_endpoints.each do |endpoint|
44
+ if endpoint[:local_port] == "#{@port}"
45
+ return { :host => "#{vm.cloud_service_name}.cloudapp.net", :port => endpoint[:public_port] }
46
+ end
47
+ end
48
+
49
+ return nil
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end