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,27 +1,28 @@
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 Errors
9
- class WinAzureError < Vagrant::Errors::VagrantError
10
- error_namespace("vagrant_azure.errors")
11
- end
12
-
13
- class WinRMNotReady < WinAzureError
14
- error_key(:win_rm_not_ready)
15
- end
16
-
17
- class ServerNotCreated < WinAzureError
18
- error_key(:server_not_created)
19
- end
20
-
21
- class CreateVMFailure < WinAzureError
22
- error_key(:create_vm_failure)
23
- end
24
-
25
- end
26
- end
27
- 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 Errors
10
+ class WinAzureError < Vagrant::Errors::VagrantError
11
+ error_namespace("vagrant_azure.errors")
12
+ end
13
+
14
+ class WinRMNotReady < WinAzureError
15
+ error_key(:win_rm_not_ready)
16
+ end
17
+
18
+ class ServerNotCreated < WinAzureError
19
+ error_key(:server_not_created)
20
+ end
21
+
22
+ class CreateVMFailure < WinAzureError
23
+ error_key(:create_vm_failure)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+
2
+ require 'azure'
3
+
4
+ # Patch azure-ruby-sdk to enable vhds to be created every millisecond as opposed to every minute...
5
+ Azure::VirtualMachineManagement::Serialization.module_eval do
6
+ def self.role_to_xml(params, options)
7
+ builder = Nokogiri::XML::Builder.new do |xml|
8
+ xml.PersistentVMRole(
9
+ 'xmlns' => 'http://schemas.microsoft.com/windowsazure',
10
+ 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance'
11
+ ) do
12
+ xml.RoleName { xml.text params[:vm_name] }
13
+ xml.OsVersion('i:nil' => 'true')
14
+ xml.RoleType 'PersistentVMRole'
15
+
16
+ xml.ConfigurationSets do
17
+ provisioning_configuration_to_xml(xml, params, options)
18
+ xml.ConfigurationSet('i:type' => 'NetworkConfigurationSet') do
19
+ xml.ConfigurationSetType 'NetworkConfiguration'
20
+ xml.InputEndpoints do
21
+ default_endpoints_to_xml(xml, options)
22
+ tcp_endpoints_to_xml(
23
+ xml,
24
+ options[:tcp_endpoints],
25
+ options[:existing_ports]
26
+ ) if options[:tcp_endpoints]
27
+ end
28
+ if options[:virtual_network_name] && options[:subnet_name]
29
+ xml.SubnetNames do
30
+ xml.SubnetName options[:subnet_name]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ xml.AvailabilitySetName options[:availability_set_name]
36
+ xml.Label Base64.encode64(params[:vm_name]).strip
37
+ xml.OSVirtualHardDisk do
38
+ xml.MediaLink 'http://' + options[:storage_account_name] + '.blob.core.windows.net/vhds/' + (Time.now.strftime('disk_%Y_%m_%d_%H_%M_%S_%L')) + '.vhd'
39
+ xml.SourceImageName params[:image]
40
+ end
41
+ xml.RoleSize options[:vm_size]
42
+ end
43
+ end
44
+ builder.doc
45
+ end
46
+ end
@@ -0,0 +1,77 @@
1
+ # patch no_ssl_peer_validation for ssl based winrm
2
+
3
+ WinRM::HTTP::HttpTransport.class_eval do
4
+
5
+ # provide a patch for no peer verification.
6
+ # the patch exists upstream, but vagrant depends on an older version of winrm
7
+ def no_ssl_peer_verification!
8
+ @httpcli.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
9
+ end
10
+ end
11
+
12
+ WinRM::HTTP::HttpSSL.class_eval do
13
+
14
+ # provide a constructor that offers the ability to disable peer verification
15
+ def initialize(endpoint, user, pass, ca_trust_path = nil, opts)
16
+ super(endpoint)
17
+ @httpcli.set_auth(endpoint, user, pass)
18
+ @httpcli.ssl_config.set_trust_ca(ca_trust_path) unless ca_trust_path.nil?
19
+ no_sspi_auth! if opts[:disable_sspi]
20
+ basic_auth_only! if opts[:basic_auth_only]
21
+ no_ssl_peer_verification! if opts[:no_ssl_peer_verification]
22
+ end
23
+ end
24
+
25
+
26
+ VagrantPlugins::CommunicatorWinRM::WinRMShell.class_eval do
27
+ EXCEPTIONS = class_variable_get(:@@exceptions_to_retry_on)
28
+
29
+ protected
30
+
31
+ # patch the timeout being raised from openssl that is not handled properly
32
+ def execute_shell_with_retry(command, shell, &block)
33
+ retryable(:tries => @max_tries, :on => EXCEPTIONS, :sleep => 10) do
34
+ @logger.debug("#{shell} executing:\n#{command}")
35
+ begin
36
+ output = session.send(shell, command) do |out, err|
37
+ block.call(:stdout, out) if block_given? && out
38
+ block.call(:stderr, err) if block_given? && err
39
+ end
40
+ rescue Exception => ex
41
+ raise Timeout::Error if ex.message =~ /execution expired/ # received not friendly timeout, raise a more friendly error
42
+ raise # didn't include execution expired, so raise for retryable to handle
43
+ end
44
+ @logger.debug("Output: #{output.inspect}")
45
+ return output
46
+ end
47
+ end
48
+
49
+ # create a new session using ssl rather than kerberos or plaintext
50
+ def new_session
51
+ @logger.info("Attempting to connect to WinRM (patched)...")
52
+ @logger.info(" - Host: #{@host}")
53
+ @logger.info(" - Port: #{@port}")
54
+ @logger.info(" - Username: #{@username}")
55
+
56
+ client = ::WinRM::WinRMWebService.new(endpoint, :ssl, endpoint_options)
57
+ client.set_timeout(@timeout_in_seconds)
58
+ client.toggle_nori_type_casting(:off) #we don't want coersion of types
59
+ client
60
+ end
61
+
62
+ # override the internal http endpoint
63
+ def endpoint
64
+ "https://#{@host}:#{@port}/wsman"
65
+ end
66
+
67
+ # don't verify azure self signed certs and don't try to use sspi
68
+ def endpoint_options
69
+ {user: @username,
70
+ pass: @password,
71
+ host: @host,
72
+ port: @port,
73
+ operation_timeout: @timeout_in_seconds,
74
+ no_ssl_peer_verification: true,
75
+ disable_sspi: true}
76
+ end
77
+ end
@@ -1,91 +1,102 @@
1
- #--------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Open Technologies, Inc.
3
- # All Rights Reserved. Licensed under the Apache 2.0 License.
4
- #--------------------------------------------------------------------------
5
- begin
6
- require 'vagrant'
7
- rescue LoadError
8
- raise 'The Vagrant Azure plugin must be run within Vagrant.'
9
- end
10
-
11
- # This is a sanity check to make sure no one is attempting to install this into
12
- # an early Vagrant version.
13
- if Vagrant::VERSION < '1.2.0'
14
- raise 'The Vagrant Azure plugin is only compatible with Vagrant 1.2+'
15
- end
16
-
17
- module VagrantPlugins
18
- module WinAzure
19
- class Plugin < Vagrant.plugin('2')
20
- name 'azure'
21
- description <<-DESC
22
- This plugin installs a provider that allows Vagrant to manage
23
- machines in Windows Azure.
24
- DESC
25
-
26
- config(:azure, :provider) do
27
- require_relative 'config'
28
- Config
29
- end
30
-
31
- provider(:azure, parallel: true) do
32
- # Setup logging and i18n
33
- setup_logging
34
- setup_i18n
35
-
36
- # Return the provider
37
- require_relative 'provider'
38
- Provider
39
- end
40
-
41
- command 'rdp' do
42
- require_relative 'command/rdp/command'
43
- Command
44
- end
45
-
46
- def self.setup_i18n
47
- I18n.load_path << File.expand_path(
48
- 'locales/en.yml',
49
- WinAzure.source_root
50
- )
51
- I18n.load_path << File.expand_path(
52
- 'templates/locales/en.yml',
53
- Vagrant.source_root
54
- )
55
- I18n.load_path << File.expand_path(
56
- 'templates/locales/providers_hyperv.yml',
57
- Vagrant.source_root
58
- )
59
- I18n.reload!
60
- end
61
-
62
- def self.setup_logging
63
- require 'log4r'
64
-
65
- level = nil
66
- begin
67
- level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
68
- rescue NameError
69
- # This means that the logging constant wasn't found,
70
- # which is fine. We just keep `level` as `nil`. But
71
- # we tell the user.
72
- level = nil
73
- end
74
-
75
- # Some constants, such as "true" resolve to booleans, so the
76
- # above error checking doesn't catch it. This will check to make
77
- # sure that the log level is an integer, as Log4r requires.
78
- level = nil if !level.is_a?(Integer)
79
-
80
- # Set the logging level on all "vagrant" namespaced logs as long as
81
- # we have a valid level
82
- if level
83
- logger = Log4r::Logger.new("vagrant_azure")
84
- logger.outputters = Log4r::Outputter.stderr
85
- logger.level = level
86
- logger = nil
87
- end
88
- end
89
- end
90
- end
91
- 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
+ begin
7
+ require 'vagrant'
8
+ rescue LoadError
9
+ raise 'The Vagrant Azure plugin must be run within Vagrant.'
10
+ end
11
+
12
+ # This is a sanity check to make sure no one is attempting to install this into
13
+ # an early Vagrant version.
14
+ if Vagrant::VERSION < '1.6.0'
15
+ raise 'The Vagrant Azure plugin is only compatible with Vagrant 1.6+'
16
+ end
17
+
18
+ module VagrantPlugins
19
+ module WinAzure
20
+ class Plugin < Vagrant.plugin('2')
21
+ name 'azure'
22
+ description <<-DESC
23
+ This plugin installs a provider that allows Vagrant to manage
24
+ machines in Windows Azure.
25
+ DESC
26
+
27
+ config(:azure, :provider) do
28
+ require_relative 'config'
29
+ Config
30
+ end
31
+
32
+ provider(:azure, parallel: true) do
33
+ # Setup logging and i18n
34
+ setup_logging
35
+ setup_i18n
36
+
37
+ # Return the provider
38
+ require_relative 'provider'
39
+ Provider
40
+ end
41
+
42
+ provider_capability(:azure, :winrm_info) do
43
+ require_relative 'capabilities/winrm'
44
+ VagrantPlugins::WinAzure::Cap::WinRM
45
+ end
46
+
47
+ command 'powershell' do
48
+ require_relative 'command/powershell'
49
+ VagrantPlugins::WinAzure::Command::PowerShell
50
+ end
51
+
52
+ command 'rdp' do
53
+ require_relative 'command/rdp'
54
+ VagrantPlugins::WinAzure::Command::RDP
55
+ end
56
+
57
+ def self.setup_i18n
58
+ I18n.load_path << File.expand_path(
59
+ 'locales/en.yml',
60
+ WinAzure.source_root
61
+ )
62
+ I18n.load_path << File.expand_path(
63
+ 'templates/locales/en.yml',
64
+ Vagrant.source_root
65
+ )
66
+ I18n.load_path << File.expand_path(
67
+ 'templates/locales/providers_hyperv.yml',
68
+ Vagrant.source_root
69
+ )
70
+ I18n.reload!
71
+ end
72
+
73
+ def self.setup_logging
74
+ require 'log4r'
75
+
76
+ level = nil
77
+ begin
78
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
79
+ rescue NameError
80
+ # This means that the logging constant wasn't found,
81
+ # which is fine. We just keep `level` as `nil`. But
82
+ # we tell the user.
83
+ level = nil
84
+ end
85
+
86
+ # Some constants, such as "true" resolve to booleans, so the
87
+ # above error checking doesn't catch it. This will check to make
88
+ # sure that the log level is an integer, as Log4r requires.
89
+ level = nil if !level.is_a?(Integer)
90
+
91
+ # Set the logging level on all "vagrant" namespaced logs as long as
92
+ # we have a valid level
93
+ if level
94
+ logger = Log4r::Logger.new("vagrant_azure")
95
+ logger.outputters = Log4r::Outputter.stderr
96
+ logger.level = level
97
+ logger = nil
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,70 +1,74 @@
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 'vagrant'
7
-
8
- module VagrantPlugins
9
- module WinAzure
10
- class Provider < Vagrant.plugin('2', :provider)
11
- attr_reader :driver
12
-
13
- def initialize(machine)
14
- @machine = machine
15
-
16
- # Load the driver
17
- machine_id_changed
18
- end
19
-
20
- def action(name)
21
- # Attempt to get the action method from the Action class if it
22
- # exists, otherwise return nil to show that we don't support the
23
- # given action.
24
- action_method = "action_#{name}"
25
- return Action.send(action_method) if Action.respond_to?(action_method)
26
- nil
27
- end
28
-
29
- def machine_id_changed
30
- @driver = Driver.new(@machine)
31
- end
32
-
33
- def ssh_info
34
- # Run a custom action called "read_ssh_info" which does what it
35
- # says and puts the resulting SSH info into the `:machine_ssh_info`
36
- # key in the environment.
37
- env = @machine.action('read_ssh_info')
38
- env[:machine_ssh_info]
39
- end
40
-
41
- def rdp_info
42
- env = @machine.action('read_rdp_info')
43
- env[:machine_ssh_info]
44
- end
45
-
46
- def winrm_info
47
- env = @machine.action('read_winrm_info')
48
- env[:machine_ssh_info]
49
- end
50
-
51
- def state
52
- # Run a custom action we define called "read_state" which does what it
53
- # says. It puts the state in the `:machine_state_id` key in the env
54
- env = @machine.action('read_state')
55
- state_id = env[:machine_state_id]
56
-
57
- short = "Machine's current state is #{state_id}"
58
- long = ""
59
-
60
- # Return the MachineState object
61
- Vagrant::MachineState.new(state_id, short, long)
62
- end
63
-
64
- def to_s
65
- id = @machine.id.nil? ? 'new' : @machine.id
66
- "Azure (#{id})"
67
- end
68
- end
69
- end
70
- 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 'vagrant'
8
+
9
+ module VagrantPlugins
10
+ module WinAzure
11
+ class Provider < Vagrant.plugin('2', :provider)
12
+ attr_reader :driver
13
+
14
+ def initialize(machine)
15
+ @machine = machine
16
+
17
+ # Load the driver
18
+ machine_id_changed
19
+
20
+ @machine.config.winrm.password = @machine.provider_config.vm_password || @machine.provider_config.vm_user
21
+ @machine.config.winrm.username = @machine.provider_config.vm_user
22
+ end
23
+
24
+ def action(name)
25
+ # Attempt to get the action method from the Action class if it
26
+ # exists, otherwise return nil to show that we don't support the
27
+ # given action.
28
+ action_method = "action_#{name}"
29
+ return Action.send(action_method) if Action.respond_to?(action_method)
30
+ nil
31
+ end
32
+
33
+ def machine_id_changed
34
+ @driver = Driver.new(@machine)
35
+ end
36
+
37
+ def ssh_info
38
+ # Run a custom action called "read_ssh_info" which does what it
39
+ # says and puts the resulting SSH info into the `:machine_ssh_info`
40
+ # key in the environment.
41
+ env = @machine.action('read_ssh_info')
42
+ env[:machine_ssh_info]
43
+ end
44
+
45
+ def rdp_info
46
+ env = @machine.action('read_rdp_info')
47
+ env[:machine_ssh_info]
48
+ end
49
+
50
+ def winrm_info
51
+ env = @machine.action('read_winrm_info')
52
+ env[:machine_winrm_info]
53
+ end
54
+
55
+ def state
56
+ # Run a custom action we define called "read_state" which does what it
57
+ # says. It puts the state in the `:machine_state_id` key in the env
58
+ env = @machine.action('read_state')
59
+ state_id = env[:machine_state_id]
60
+
61
+ short = "Machine's current state is #{state_id}"
62
+ long = ""
63
+
64
+ # Return the MachineState object
65
+ Vagrant::MachineState.new(state_id, short, long)
66
+ end
67
+
68
+ def to_s
69
+ id = @machine.id.nil? ? 'new' : @machine.id
70
+ "Azure (#{id})"
71
+ end
72
+ end
73
+ end
74
+ end