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,47 @@
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 ReadState
11
- def initialize(app, env)
12
- @app = app
13
- @logger = Log4r::Logger.new('vagrant_azure::action::read_state')
14
- end
15
-
16
- def call(env)
17
- env[:machine_state_id] = read_state(env)
18
-
19
- @app.call(env)
20
- end
21
-
22
- def read_state(env)
23
- env[:machine].id = "#{env[:machine].provider_config.vm_name}@#{env[:machine].provider_config.cloud_service_name}" unless env[:machine].id
24
-
25
- env[:machine].id =~ /@/
26
-
27
- env[:ui].info "Attempting to read state for #{$`} in #{$'}"
28
-
29
- vm = env[:azure_vm_service].get_virtual_machine($`, $')
30
-
31
- if vm.nil? || \
32
- !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine) || \
33
- [ :DeletingVM ].include?(vm.status.to_sym)
34
- # Machine can't be found
35
- @logger.info 'Machine cannot be found'
36
- env[:machine].id = nil
37
- return :NotCreated
38
- end
39
-
40
- env[:ui].info "VM Status: #{vm.status.to_sym}"
41
- return vm.status.to_sym
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 'log4r'
7
+
8
+ module VagrantPlugins
9
+ module WinAzure
10
+ module Action
11
+ class ReadState
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new('vagrant_azure::action::read_state')
15
+ end
16
+
17
+ def call(env)
18
+ env[:machine_state_id] = read_state(env)
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ def read_state(env)
24
+ env[:machine].id = "#{env[:machine].provider_config.vm_name}@#{env[:machine].provider_config.cloud_service_name}" unless env[:machine].id
25
+
26
+ env[:machine].id =~ /@/
27
+
28
+ env[:ui].info "Attempting to read state for #{$`} in #{$'}"
29
+
30
+ vm = env[:azure_vm_service].get_virtual_machine($`, $')
31
+
32
+ if vm.nil? || \
33
+ !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine) || \
34
+ [ :DeletingVM ].include?(vm.status.to_sym)
35
+ # Machine can't be found
36
+ @logger.info 'Machine cannot be found'
37
+ env[:machine].id = nil
38
+ return :NotCreated
39
+ end
40
+
41
+ env[:ui].info "VM Status: #{vm.status.to_sym}"
42
+ return vm.status.to_sym
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,57 @@
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 ReadWinrmInfo
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new('vagrant_azure::action::read_winrm_info')
15
+ end
16
+
17
+ def call(env)
18
+ if env[:machine].config.vm.guest == :windows
19
+ env[:ui].info 'Looking for WinRM'
20
+
21
+ env[:machine_winrm_info] = read_winrm_info(
22
+ env[:azure_vm_service],
23
+ env[:machine]
24
+ )
25
+
26
+ env[:ui].info "Found public port #{env[:machine_winrm_info][:port]}"
27
+ end
28
+
29
+ @app.call(env)
30
+ end
31
+
32
+ def read_winrm_info(azure, machine)
33
+ return nil if machine.id.nil?
34
+ machine.id =~ /@/
35
+ vm = azure.get_virtual_machine($`, $')
36
+
37
+ if vm.nil? || !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine)
38
+ # Machine cannot be found
39
+ @logger.info 'Machine not found. Assuming it was destroyed'
40
+ machine.id = nil
41
+ return nil
42
+ end
43
+
44
+ vm.tcp_endpoints.each do |endpoint|
45
+ if endpoint[:name] == 'PowerShell'
46
+ machine.config.winrm.host = "#{vm.cloud_service_name}.cloudapp.net"
47
+ machine.config.winrm.port = endpoint[:public_port]
48
+ return { :host => "#{vm.cloud_service_name}.cloudapp.net", :port => endpoint[:public_port] }
49
+ end
50
+ end
51
+
52
+ nil
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -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
- require 'log4r'
6
-
7
- module VagrantPlugins
8
- module WinAzure
9
- module Action
10
- class RestartVM
11
- def initialize(app, env)
12
- @app = app
13
- @logger = Log4r::Logger.new('vagrant_azure::action::restart_vm')
14
- end
15
-
16
- def call(env)
17
- env[:machine].id =~ /@/
18
-
19
- env[:ui].info "Restarting #{$`} in #{$'}"
20
- env[:azure_vm_service].restart_virtual_machine($`, $')
21
-
22
- @app.call(env)
23
- end
24
- end
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
+ require 'log4r'
7
+
8
+ module VagrantPlugins
9
+ module WinAzure
10
+ module Action
11
+ class RestartVM
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new('vagrant_azure::action::restart_vm')
15
+ end
16
+
17
+ def call(env)
18
+ env[:machine].id =~ /@/
19
+
20
+ env[:ui].info "Restarting #{$`} in #{$'}"
21
+ env[:azure_vm_service].restart_virtual_machine($`, $')
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,115 +1,123 @@
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 'json'
7
- require 'azure'
8
-
9
- require 'vagrant/util/retryable'
10
-
11
- module VagrantPlugins
12
- module WinAzure
13
- module Action
14
- class RunInstance
15
- include Vagrant::Util::Retryable
16
-
17
- def initialize(app, env)
18
- @app = app
19
- @logger = Log4r::Logger.new('vagrant_azure::action::run_instance')
20
- end
21
-
22
- def call(env)
23
- config = env[:machine].provider_config
24
-
25
- # Add the mandatory parameters and options
26
- params = {
27
- vm_name: config.vm_name,
28
- vm_user: config.vm_user,
29
- image: config.vm_image
30
- }
31
-
32
- options = {
33
- cloud_service_name: config.cloud_service_name
34
- }
35
-
36
-
37
- # Add the optional parameters and options if not nil
38
- params[:password] = config.vm_password unless config.vm_password.nil?
39
- params[:location] = config.vm_location unless config.vm_location.nil?
40
- params[:affinity_group] = config.vm_affinity_group unless \
41
- config.vm_affinity_group.nil?
42
-
43
- options[:storage_account_name] = config.storage_acct_name unless \
44
- config.storage_acct_name.nil?
45
- options[:deployment_name] = config.deployment_name unless \
46
- config.deployment_name.nil?
47
- options[:tcp_endpoints] = config.tcp_endpoints unless \
48
- config.tcp_endpoints.nil?
49
- options[:private_key_file] = config.ssh_private_key_file unless \
50
- config.ssh_private_key_file.nil?
51
- options[:certificate_file] = config.ssh_certificate_file unless \
52
- config.ssh_certificate_file.nil?
53
- options[:ssh_port] = config.ssh_port unless \
54
- config.ssh_port.nil?
55
- options[:vm_size] = config.vm_size unless \
56
- config.vm_size.nil?
57
- options[:winrm_transport] = config.winrm_transport unless \
58
- config.winrm_transport.nil?
59
- options[:winrm_http_port] = config.winrm_http_port unless \
60
- config.winrm_http_port.nil?
61
- options[:winrm_https_port] = config.winrm_https_port unless \
62
- config.winrm_https_port.nil?
63
- options[:availability_set_name] = config.availability_set_name unless \
64
- config.availability_set_name.nil?
65
-
66
- add_role = false
67
-
68
- env[:ui].info(params.inspect)
69
- env[:ui].info(options.inspect)
70
-
71
- # Check if the cloud service exists and if yes, does it contain
72
- # a deployment.
73
- if config.cloud_service_name && !config.cloud_service_name.empty?
74
- begin
75
- cloud_service = ManagementHttpRequest.new(
76
- :get,
77
- "/services/hostedservices/#{config.cloud_service_name}?embed-detail=true"
78
- ).call
79
-
80
- deployments = cloud_service.css 'HostedService Deployments Deployment'
81
-
82
- # Lets see if any deployments exist. Set add_role = true if yes.
83
- # We're not worried about deployment slots, because the SDK has
84
- # hard coded 'Production' as deployment slot and you can have only
85
- # one deployment per deployment slot.
86
- add_role = deployments.length == 1
87
- rescue Exception => e
88
- add_role = false
89
- end
90
- end
91
- env[:ui].info("Add Role? - #{add_role}")
92
-
93
- server = env[:azure_vm_service].create_virtual_machine(
94
- params, options, add_role
95
- )
96
-
97
- if server.nil?
98
- raise Errors::CreateVMFailure
99
- end
100
-
101
- # The Ruby SDK returns any exception encountered on create virtual
102
- # machine as a string.
103
-
104
- if server.instance_of? String
105
- raise Errors::ServerNotCreated, message: server
106
- end
107
-
108
- env[:machine].id = "#{server.vm_name}@#{server.cloud_service_name}"
109
-
110
- @app.call(env)
111
- end
112
- end
113
- end
114
- end
115
- 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 'json'
8
+ require 'azure'
9
+
10
+ require 'vagrant/util/retryable'
11
+
12
+ module VagrantPlugins
13
+ module WinAzure
14
+ module Action
15
+ class RunInstance
16
+ include Vagrant::Util::Retryable
17
+
18
+ def initialize(app, env)
19
+ @app = app
20
+ @logger = Log4r::Logger.new('vagrant_azure::action::run_instance')
21
+ end
22
+
23
+ def call(env)
24
+ config = env[:machine].provider_config
25
+
26
+ # Add the mandatory parameters and options
27
+ params = {
28
+ vm_name: config.vm_name,
29
+ vm_user: config.vm_user,
30
+ image: config.vm_image
31
+ }
32
+
33
+ options = {
34
+ cloud_service_name: config.cloud_service_name
35
+ }
36
+
37
+
38
+ # Add the optional parameters and options if not nil
39
+ params[:password] = config.vm_password unless config.vm_password.nil?
40
+ params[:location] = config.vm_location unless config.vm_location.nil?
41
+ params[:affinity_group] = config.vm_affinity_group unless \
42
+ config.vm_affinity_group.nil?
43
+
44
+ options[:storage_account_name] = config.storage_acct_name unless \
45
+ config.storage_acct_name.nil?
46
+ options[:deployment_name] = config.deployment_name unless \
47
+ config.deployment_name.nil?
48
+ options[:tcp_endpoints] = config.tcp_endpoints unless \
49
+ config.tcp_endpoints.nil?
50
+ options[:private_key_file] = config.private_key_file unless \
51
+ config.private_key_file.nil?
52
+ options[:certificate_file] = config.certificate_file unless \
53
+ config.certificate_file.nil?
54
+ options[:ssh_port] = config.ssh_port unless \
55
+ config.ssh_port.nil?
56
+ options[:vm_size] = config.vm_size unless \
57
+ config.vm_size.nil?
58
+ options[:winrm_transport] = config.winrm_transport unless \
59
+ config.winrm_transport.nil?
60
+ options[:winrm_http_port] = config.winrm_http_port unless \
61
+ config.winrm_http_port.nil?
62
+ options[:winrm_https_port] = config.winrm_https_port unless \
63
+ config.winrm_https_port.nil?
64
+ options[:availability_set_name] = config.availability_set_name unless \
65
+ config.availability_set_name.nil?
66
+ options[:vm_virtual_network_name] = config.vm_virtual_network_name unless \
67
+ config.vm_virtual_network_name.nil?
68
+
69
+ add_role = false
70
+
71
+ env[:ui].info(params.inspect)
72
+ env[:ui].info(options.inspect)
73
+
74
+ server = VagrantPlugins::WinAzure::CLOUD_SERVICE_SEMAPHORE.synchronize do
75
+ # Check if the cloud service exists and if yes, does it contain
76
+ # a deployment.
77
+ if config.cloud_service_name && !config.cloud_service_name.empty?
78
+ begin
79
+ cloud_service = ManagementHttpRequest.new(
80
+ :get,
81
+ "/services/hostedservices/#{config.cloud_service_name}?embed-detail=true"
82
+ ).call
83
+
84
+ deployments = cloud_service.css 'HostedService Deployments Deployment'
85
+
86
+ # Lets see if any deployments exist. Set add_role = true if yes.
87
+ # We're not worried about deployment slots, because the SDK has
88
+ # hard coded 'Production' as deployment slot and you can have only
89
+ # one deployment per deployment slot.
90
+ add_role = deployments.length == 1
91
+ rescue Exception => e
92
+ add_role = false
93
+ end
94
+ end
95
+
96
+ env[:ui].info("Add Role? - #{add_role}")
97
+
98
+ if add_role
99
+ env[:azure_vm_service].add_role(params.clone.merge(cloud_service_name: config.cloud_service_name), options)
100
+ else
101
+ env[:azure_vm_service].create_virtual_machine(params, options)
102
+ end
103
+ end
104
+
105
+ if server.nil?
106
+ raise Errors::CreateVMFailure
107
+ end
108
+
109
+ # The Ruby SDK returns any exception encountered on create virtual
110
+ # machine as a string.
111
+
112
+ if server.instance_of? String
113
+ raise Errors::ServerNotCreated, message: server
114
+ end
115
+
116
+ env[:machine].id = "#{server.vm_name}@#{server.cloud_service_name}"
117
+
118
+ @app.call(env)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -1,35 +1,35 @@
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
- # require 'vagrant/util/retryable'
8
-
9
- # Barebones basic implemenation. This a work in progress in very early stages
10
- module VagrantPlugins
11
- module WinAzure
12
- module Action
13
- # This starts a stopped instance
14
- class StartInstance
15
- # include Vagrant:Util::Retryable
16
-
17
- def initialize(app, env)
18
- @app = app
19
- @logger = Log4r::Logger.new('vagrant_azure:action::start_instance')
20
- end
21
-
22
- def call(env)
23
- env[:machine].id = "#{env[:machine].provider_config.vm_name}@#{env[:machine].provider_config.cloud_service_name}" unless env[:machine].id
24
- env[:machine].id =~ /@/
25
-
26
- env[:ui].info "Attempting to start '#{$`}' in '#{$'}'"
27
-
28
- env[:azure_vm_service].start_virtual_machine($`, $')
29
-
30
- @app.call(env)
31
- end
32
- end
33
- end
34
- end
35
- 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
+ # require 'vagrant/util/retryable'
9
+
10
+ # Barebones basic implemenation. This a work in progress in very early stages
11
+ module VagrantPlugins
12
+ module WinAzure
13
+ module Action
14
+ # This starts a stopped instance
15
+ class StartInstance
16
+
17
+ def initialize(app, env)
18
+ @app = app
19
+ @logger = Log4r::Logger.new('vagrant_azure:action::start_instance')
20
+ end
21
+
22
+ def call(env)
23
+ env[:machine].id = "#{env[:machine].provider_config.vm_name}@#{env[:machine].provider_config.cloud_service_name}" unless env[:machine].id
24
+ env[:machine].id =~ /@/
25
+
26
+ VagrantPlugins::WinAzure::CLOUD_SERVICE_SEMAPHORE.synchronize do
27
+ env[:ui].info "Attempting to start '#{$`}' in '#{$'}'"
28
+ env[:azure_vm_service].start_virtual_machine($`, $')
29
+ end
30
+ @app.call(env)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end