vagrant-azure 1.3.0 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -6
  5. data/LICENSE +21 -4
  6. data/README.md +36 -178
  7. data/Rakefile +3 -5
  8. data/example_box/Vagrantfile +7 -8
  9. data/lib/vagrant-azure/action/connect_azure.rb +9 -30
  10. data/lib/vagrant-azure/action/is_created.rb +19 -0
  11. data/lib/vagrant-azure/action/is_stopped.rb +19 -0
  12. data/lib/vagrant-azure/action/message_already_created.rb +19 -0
  13. data/lib/vagrant-azure/action/message_not_created.rb +19 -0
  14. data/lib/vagrant-azure/action/message_will_not_destroy.rb +19 -0
  15. data/lib/vagrant-azure/action/read_ssh_info.rb +13 -33
  16. data/lib/vagrant-azure/action/read_state.rb +28 -26
  17. data/lib/vagrant-azure/action/restart_vm.rb +11 -11
  18. data/lib/vagrant-azure/action/run_instance.rb +164 -80
  19. data/lib/vagrant-azure/action/start_instance.rb +34 -15
  20. data/lib/vagrant-azure/action/stop_instance.rb +36 -21
  21. data/lib/vagrant-azure/action/terminate_instance.rb +18 -14
  22. data/lib/vagrant-azure/action/wait_for_state.rb +17 -23
  23. data/lib/vagrant-azure/action.rb +49 -124
  24. data/lib/vagrant-azure/config.rb +107 -111
  25. data/lib/vagrant-azure/errors.rb +9 -11
  26. data/lib/vagrant-azure/plugin.rb +8 -32
  27. data/lib/vagrant-azure/provider.rb +7 -29
  28. data/lib/vagrant-azure/services/azure_resource_manager.rb +80 -0
  29. data/lib/vagrant-azure/util/machine_id_helper.rb +20 -0
  30. data/lib/vagrant-azure/util/timer.rb +15 -0
  31. data/lib/vagrant-azure/util/vm_await.rb +36 -0
  32. data/lib/vagrant-azure/util/vm_status_translator.rb +59 -0
  33. data/lib/vagrant-azure/version.rb +5 -7
  34. data/lib/vagrant-azure.rb +4 -9
  35. data/locales/en.yml +74 -3
  36. data/spec/spec_helper.rb +40 -0
  37. data/spec/vagrant-azure/config_spec.rb +18 -0
  38. data/spec/vagrant-azure/services/azure_resource_manager_spec.rb +19 -0
  39. data/templates/arm/deployment.json.erb +264 -0
  40. data/vagrant-azure.gemspec +19 -14
  41. metadata +96 -51
  42. data/lib/vagrant-azure/action/os_type.rb +0 -34
  43. data/lib/vagrant-azure/action/powershell_run.rb +0 -28
  44. data/lib/vagrant-azure/action/rdp.rb +0 -63
  45. data/lib/vagrant-azure/action/read_winrm_info.rb +0 -57
  46. data/lib/vagrant-azure/action/sync_folders.rb +0 -64
  47. data/lib/vagrant-azure/action/vagrant_azure_service.rb +0 -44
  48. data/lib/vagrant-azure/capabilities/winrm.rb +0 -12
  49. data/lib/vagrant-azure/command/powershell.rb +0 -43
  50. data/lib/vagrant-azure/command/rdp.rb +0 -24
  51. data/lib/vagrant-azure/driver.rb +0 -48
  52. data/lib/vagrant-azure/monkey_patch/winrm.rb +0 -12
@@ -1,47 +1,41 @@
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
- #--------------------------------------------------------------------------
1
+ # encoding: utf-8
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License in the project root for license information.
6
4
  require 'log4r'
7
5
  require 'timeout'
8
6
 
9
7
  module VagrantPlugins
10
- module WinAzure
8
+ module Azure
11
9
  module Action
12
10
  class WaitForState
13
- def initialize(app, env, state)
14
- @app = app
15
- @state = state
16
- @logger = Log4r::Logger.new("vagrant_azure::action::wait_for_state")
11
+ # env[:result] will be false in case of timeout.
12
+ # @param [Symbol] state Target machine state.
13
+ # @param [Number] timeout Timeout in seconds.
14
+ # @param [Object] env vagrant environment
15
+ def initialize(app, env, state, timeout)
16
+ @app = app
17
+ @logger = Log4r::Logger.new('vagrant_azure::action::wait_for_state')
18
+ @state = state
19
+ @timeout = timeout
20
+ @env = env
17
21
  end
18
22
 
19
23
  def call(env)
20
24
  env[:result] = true
21
-
22
25
  if env[:machine].state.id == @state
23
- @logger.info(
24
- I18n.t('vagrant_azure.already_status', :status => @state)
25
- )
26
+ @logger.info(I18n.t('vagrant_azure.already_status', :status => @state))
26
27
  else
27
- timeout = env[:machine].provider_config.state_read_timeout || env[:machine].config.vm.boot_timeout
28
-
29
- env[:ui].info "Waiting for machine to reach state #{@state}"
30
28
  @logger.info("Waiting for machine to reach state #{@state}")
31
-
32
29
  begin
33
- Timeout.timeout(timeout) do
30
+ Timeout.timeout(@timeout) do
34
31
  until env[:machine].state.id == @state
35
- sleep 30
32
+ sleep 2
36
33
  end
37
34
  end
38
- env[:ui].success "Machine reached state #{@state}"
39
35
  rescue Timeout::Error
40
- env[:ui].error "Machine failed to reached state '#{@state}' in '#{timeout}' seconds."
41
36
  env[:result] = false # couldn't reach state in time
42
37
  end
43
38
  end
44
-
45
39
  @app.call(env)
46
40
  end
47
41
  end
@@ -1,15 +1,13 @@
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
- #--------------------------------------------------------------------------
1
+ # encoding: utf-8
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License in the project root for license information.
6
4
  require 'pathname'
7
5
 
8
6
  require 'vagrant/action/builder'
9
7
  require 'vagrant/action/builtin/wait_for_communicator'
10
8
 
11
9
  module VagrantPlugins
12
- module WinAzure
10
+ module Azure
13
11
  module Action
14
12
  # Include the built-in modules so we can use them as top-level things.
15
13
  include Vagrant::Action::Builtin
@@ -18,9 +16,9 @@ module VagrantPlugins
18
16
  def self.action_halt
19
17
  Vagrant::Action::Builder.new.tap do |b|
20
18
  b.use ConfigValidate
21
- b.use Call, IsState, :NotCreated do |env, b2|
22
- if env[:result]
23
- b2.use Message, I18n.t('vagrant_azure.not_created')
19
+ b.use Call, IsCreated do |env, b2|
20
+ unless env[:result]
21
+ b2.use MessageNotCreated
24
22
  next
25
23
  end
26
24
 
@@ -36,22 +34,17 @@ module VagrantPlugins
36
34
  b.use Call, DestroyConfirm do |env, b2|
37
35
  if env[:result]
38
36
  b2.use ConfigValidate
39
- b2.use Call, IsState, :NotCreated do |env2, b3|
40
- if env2[:result]
41
- b3.use Message, I18n.t('vagrant_azure.not_created')
37
+ b2.use Call, IsCreated do |env2, b3|
38
+ unless env2[:result]
39
+ b3.use MessageNotCreated
42
40
  next
43
41
  end
42
+ b3.use ConnectAzure
43
+ b3.use TerminateInstance
44
+ b3.use ProvisionerCleanup if defined?(ProvisionerCleanup)
44
45
  end
45
-
46
- b2.use ConnectAzure
47
- b2.use TerminateInstance
48
- b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
49
46
  else
50
- env[:machine].id =~ /@/
51
- b2.use Message, I18n.t(
52
- 'vagrant_azure.will_not_destroy',
53
- :name => $`
54
- )
47
+ b2.use MessageWillNotDestroy
55
48
  end
56
49
  end
57
50
  end
@@ -60,18 +53,14 @@ module VagrantPlugins
60
53
  # This action is called when `vagrant provision` is called.
61
54
  def self.action_provision
62
55
  Vagrant::Action::Builder.new.tap do |b|
63
- b.use ConnectAzure
64
56
  b.use ConfigValidate
65
- b.use OSType
66
- b.use ReadWinrmInfo
67
- b.use Call, IsState, :NotCreated do |env, b2|
68
- if env[:result]
69
- b2.use Message, I18n.t('vagrant_azure.not_created')
57
+ b.use Call, IsCreated do |env, b2|
58
+ unless env[:result]
59
+ b2.use MessageNotCreated
70
60
  next
71
61
  end
72
62
 
73
63
  b2.use Provision
74
- b2.use SyncFolders
75
64
  end
76
65
  end
77
66
  end
@@ -82,27 +71,13 @@ module VagrantPlugins
82
71
  Vagrant::Action::Builder.new.tap do |b|
83
72
  b.use ConfigValidate
84
73
  b.use ConnectAzure
85
- b.use ReadSSHInfo, 22
86
- end
87
- end
88
-
89
- def self.action_read_rdp_info
90
- Vagrant::Action::Builder.new.tap do |b|
91
- b.use ConfigValidate
92
- b.use ConnectAzure
93
- b.use ReadSSHInfo, 3389
94
- end
95
- end
96
-
97
- def self.action_read_winrm_info
98
- Vagrant::Action::Builder.new.tap do |b|
99
- b.use ConfigValidate
100
- b.use ConnectAzure
101
- b.use OSType
102
- b.use ReadWinrmInfo
74
+ b.use ReadSSHInfo
103
75
  end
104
76
  end
105
77
 
78
+ # This action is called to read the state of the machine. The
79
+ # resulting state is expected to be put into the `:machine_state_id`
80
+ # key.
106
81
  def self.action_read_state
107
82
  Vagrant::Action::Builder.new.tap do |b|
108
83
  b.use ConfigValidate
@@ -111,14 +86,13 @@ module VagrantPlugins
111
86
  end
112
87
  end
113
88
 
114
- # This action is called to SSH into the machine
89
+ # This action is called to SSH into the machine.
115
90
  def self.action_ssh
116
91
  Vagrant::Action::Builder.new.tap do |b|
117
- b.use ConnectAzure
118
92
  b.use ConfigValidate
119
- b.use Call, IsState, :NotCreated do |env, b2|
120
- if env[:result]
121
- b2.use Message, I18n.t('vagrant_azure.not_created')
93
+ b.use Call, IsCreated do |env, b2|
94
+ unless env[:result]
95
+ b2.use MessageNotCreated
122
96
  next
123
97
  end
124
98
 
@@ -127,49 +101,12 @@ module VagrantPlugins
127
101
  end
128
102
  end
129
103
 
130
- def self.action_powershell_run
131
- Vagrant::Action::Builder.new.tap do |b|
132
- b.use action_read_winrm_info
133
- b.use Call, IsState, :NotCreated do |env, b2|
134
- if env[:result]
135
- b2.use Message, I18n.t('vagrant_azure.not_created')
136
- next
137
- end
138
-
139
- b2.use PowerShellRun
140
- end
141
- end
142
- end
143
-
144
- def self.action_rdp
145
- Vagrant::Action::Builder.new.tap do |b|
146
- b.use ConnectAzure
147
- b.use ConfigValidate
148
- b.use Call, IsState, :NotCreated do |env1, b1|
149
- if env1[:result]
150
- b1.use Message, I18n.t('vagrant_azure.not_created')
151
- next
152
- end
153
-
154
- b1.use Call, IsState, :ReadyRole do |env2, b2|
155
- if !env2[:result]
156
- b2.use Message, I18n.t('vagrant_azure.rdp_not_ready')
157
- next
158
- end
159
-
160
- b2.use Rdp
161
- end
162
- end
163
- end
164
- end
165
-
166
104
  def self.action_ssh_run
167
105
  Vagrant::Action::Builder.new.tap do |b|
168
- b.use ConnectAzure
169
106
  b.use ConfigValidate
170
- b.use Call, IsState, :NotCreated do |env, b2|
171
- if env[:result]
172
- b2.use Message, I18n.t('vagrant_azure.not_created')
107
+ b.use Call, IsCreated do |env, b2|
108
+ unless env[:result]
109
+ b2.use MessageNotCreated
173
110
  next
174
111
  end
175
112
 
@@ -180,42 +117,31 @@ module VagrantPlugins
180
117
 
181
118
  def self.action_prepare_boot
182
119
  Vagrant::Action::Builder.new.tap do |b|
183
- b.use Call, WaitForState, :ReadyRole do |env, b1|
184
- if env[:result]
185
- env[:machine].id =~ /@/
186
- b1.use Message, I18n.t(
187
- 'vagrant_azure.vm_started', :name => $`
188
- )
189
- b1.use action_read_winrm_info
190
- b1.use WaitForCommunicator
191
- b1.use action_provision
192
- end
193
- end
120
+ b.use Provision
121
+ b.use SyncedFolders
194
122
  end
195
123
  end
196
124
 
197
- # This action is called to bring the box up from nothing
125
+ # This action is called to bring the box up from nothing.
198
126
  def self.action_up
199
127
  Vagrant::Action::Builder.new.tap do |b|
200
128
  b.use HandleBox
201
129
  b.use ConfigValidate
130
+ b.use BoxCheckOutdated
202
131
  b.use ConnectAzure
203
- b.use OSType
204
- b.use Call, IsState, :NotCreated do |env1, b1|
205
- if !env1[:result]
206
- b1.use Call, IsState, :StoppedDeallocated do |env2, b2|
132
+ b.use Call, IsCreated do |env1, b1|
133
+ if env1[:result]
134
+ b1.use Call, IsStopped do |env2, b2|
207
135
  if env2[:result]
208
- b2.use StartInstance # start this instance again
209
136
  b2.use action_prepare_boot
137
+ b2.use StartInstance # restart this instance
210
138
  else
211
- b2.use Message, I18n.t(
212
- 'vagrant_azure.already_status', :status => 'created'
213
- )
139
+ b2.use MessageAlreadyCreated
214
140
  end
215
141
  end
216
142
  else
217
- b1.use RunInstance # Launch a new instance
218
143
  b1.use action_prepare_boot
144
+ b1.use RunInstance # launch a new instance
219
145
  end
220
146
  end
221
147
  end
@@ -225,20 +151,18 @@ module VagrantPlugins
225
151
  Vagrant::Action::Builder.new.tap do |b|
226
152
  b.use ConfigValidate
227
153
  b.use ConnectAzure
228
- b.use Call, IsState, :NotCreated do |env, b2|
229
- if env[:result]
230
- b2.use Message, I18n.t('vagrant_azure.not_created')
154
+ b.use Call, IsCreated do |env, b2|
155
+ unless env[:result]
156
+ b2.use MessageNotCreated
231
157
  next
232
158
  end
233
159
 
234
160
  b2.use action_halt
235
- b2.use Call, WaitForState, :StoppedDeallocated do |env2, b3|
161
+ b2.use Call, WaitForState, :stopped, 120 do |env2, b3|
236
162
  if env2[:result]
237
- env2[:machine].id =~ /@/
238
- b3.use Message, I18n.t('vagrant_azure.vm_stopped', name: $`)
239
163
  b3.use action_up
240
164
  else
241
- b3.use Message, 'Not able to stop the machine. Please retry.'
165
+ # ??? it didn't stop
242
166
  end
243
167
  end
244
168
  end
@@ -248,18 +172,19 @@ module VagrantPlugins
248
172
  # The autoload farm
249
173
  action_root = Pathname.new(File.expand_path('../action', __FILE__))
250
174
  autoload :ConnectAzure, action_root.join('connect_azure')
251
- autoload :Rdp, action_root.join('rdp')
175
+ autoload :IsCreated, action_root.join('is_created')
176
+ autoload :IsStopped, action_root.join('is_stopped')
177
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
178
+ autoload :MessageNotCreated, action_root.join('message_not_created')
179
+ autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
252
180
  autoload :ReadSSHInfo, action_root.join('read_ssh_info')
253
- autoload :ReadWinrmInfo, action_root.join('read_winrm_info')
254
- autoload :PowerShellRun, action_root.join('powershell_run')
255
- autoload :OSType, action_root.join('os_type')
256
181
  autoload :ReadState, action_root.join('read_state')
257
182
  autoload :RestartVM, action_root.join('restart_vm')
258
183
  autoload :RunInstance, action_root.join('run_instance')
259
184
  autoload :StartInstance, action_root.join('start_instance')
260
185
  autoload :StopInstance, action_root.join('stop_instance')
261
- autoload :SyncFolders, action_root.join('sync_folders')
262
186
  autoload :TerminateInstance, action_root.join('terminate_instance')
187
+ autoload :TimedProvision, action_root.join('timed_provision')
263
188
  autoload :WaitForState, action_root.join('wait_for_state')
264
189
  end
265
190
  end
@@ -1,151 +1,147 @@
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
- #--------------------------------------------------------------------------
1
+ # encoding: utf-8
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License in the project root for license information.
6
4
  require 'vagrant'
7
- require 'azure'
5
+ require 'haikunator'
8
6
 
9
7
  module VagrantPlugins
10
- module WinAzure
8
+ module Azure
11
9
  class Config < Vagrant.plugin('2', :config)
12
10
 
13
- attr_accessor :mgmt_certificate
14
- attr_accessor :mgmt_endpoint
11
+ # The Azure Active Directory Tenant ID -- ENV['AZURE_TENANT_ID']
12
+ #
13
+ # @return [String]
14
+ attr_accessor :tenant_id
15
+
16
+ # The Azure Active Directory Application Client ID -- ENV['AZURE_CLIENT_ID']
17
+ #
18
+ # @return [String]
19
+ attr_accessor :client_id
20
+
21
+ # The Azure Active Directory Application Client Secret -- ENV['AZURE_CLIENT_SECRET']
22
+ #
23
+ # @return [String]
24
+ attr_accessor :client_secret
25
+
26
+ # The Azure Subscription ID to use -- ENV['AZURE_SUBSCRIPTION_ID']
27
+ #
28
+ # @return [String]
15
29
  attr_accessor :subscription_id
16
- attr_accessor :storage_acct_name
17
- attr_accessor :storage_access_key
18
30
 
31
+ # (Optional) Name of the resource group to use.
32
+ #
33
+ # @return [String]
34
+ attr_accessor :resource_group_name
35
+
36
+ # (Optional) Azure location to build the VM -- defaults to 'westus'
37
+ #
38
+ # @return [String]
39
+ attr_accessor :location
40
+
41
+ # (Optional) Name of the virtual machine
42
+ #
43
+ # @return [String]
19
44
  attr_accessor :vm_name
20
- attr_accessor :vm_user
45
+
46
+ # Password for the VM -- This is not recommended for *nix deployments
47
+ #
48
+ # @return [String]
21
49
  attr_accessor :vm_password
22
- attr_accessor :vm_image
23
- attr_accessor :vm_location
24
- attr_accessor :vm_affinity_group
25
- attr_accessor :vm_virtual_network_name
26
50
 
27
- attr_accessor :cloud_service_name
28
- attr_accessor :deployment_name
29
- attr_accessor :tcp_endpoints
51
+ # (Optional) VM size to be used -- defaults to 'Standard_D1'. See: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/
52
+ #
53
+ # @return [String]
54
+ attr_accessor :vm_size
30
55
 
31
- # ssh_private_key and ssh_certificate_file is overly specific and probably should be deprecated in favor of
32
- # private_key_file and certificate_file as they are in Azure ruby sdk.
33
- # This is here to not break compatibility with previous versions.
34
- attr_accessor :private_key_file
35
- alias :ssh_private_key_file :private_key_file
36
- alias :ssh_private_key_file= :private_key_file=
56
+ # (Optional) Name of the virtual machine image urn to use -- defaults to 'canonical:ubuntuserver:16.04.0-DAILY-LTS:latest'. See: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/
57
+ #
58
+ # @return [String]
59
+ attr_accessor :vm_image_urn
37
60
 
38
- attr_accessor :ssh_port
39
- attr_accessor :vm_size
40
- attr_accessor :winrm_transport
41
- attr_accessor :winrm_http_port
42
- attr_accessor :winrm_https_port
61
+ # (Optional) Name of the virtual network resource
62
+ #
63
+ # @return [String]
64
+ attr_accessor :virtual_network_name
65
+
66
+ # (Optional) Name of the virtual network subnet resource
67
+ #
68
+ # @return [String]
69
+ attr_accessor :subnet_name
70
+
71
+ # (Optional) TCP endpoints to open up for the VM
72
+ #
73
+ # @return [String]
74
+ attr_accessor :tcp_endpoints
75
+
76
+ # (Optional) Name of the virtual machine image
77
+ #
78
+ # @return [String]
43
79
  attr_accessor :availability_set_name
44
80
 
45
- attr_accessor :state_read_timeout
81
+ # (Optional) The timeout to wait for an instance to become ready -- default 120 seconds.
82
+ #
83
+ # @return [Fixnum]
84
+ attr_accessor :instance_ready_timeout
85
+
86
+ # (Optional) The interval to wait for checking an instance's state -- default 2 seconds.
87
+ #
88
+ # @return [Fixnum]
89
+ attr_accessor :instance_check_interval
90
+
91
+ # (Optional) The Azure Management API endpoint -- default 'https://management.azure.com' seconds -- ENV['AZURE_MANAGEMENT_ENDPOINT'].
92
+ #
93
+ # @return [String]
94
+ attr_accessor :endpoint
46
95
 
47
96
  def initialize
48
- @storage_acct_name = UNSET_VALUE
49
- @storage_access_key = UNSET_VALUE
50
- @mgmt_certificate = UNSET_VALUE
51
- @mgmt_endpoint = UNSET_VALUE
97
+ @tenant_id = UNSET_VALUE
98
+ @client_id = UNSET_VALUE
99
+ @client_secret = UNSET_VALUE
100
+ @endpoint = UNSET_VALUE
52
101
  @subscription_id = UNSET_VALUE
53
-
102
+ @resource_group_name = UNSET_VALUE
103
+ @location = UNSET_VALUE
54
104
  @vm_name = UNSET_VALUE
55
- @vm_user = UNSET_VALUE
56
105
  @vm_password = UNSET_VALUE
57
- @vm_image = UNSET_VALUE
58
- @vm_location = UNSET_VALUE
59
- @vm_affinity_group = UNSET_VALUE
60
- @vm_virtual_network_name = UNSET_VALUE
61
-
62
- @cloud_service_name = UNSET_VALUE
63
- @deployment_name = UNSET_VALUE
106
+ @vm_image_urn = UNSET_VALUE
107
+ @virtual_network_name = UNSET_VALUE
108
+ @subnet_name = UNSET_VALUE
64
109
  @tcp_endpoints = UNSET_VALUE
65
- @private_key_file = UNSET_VALUE
66
- @ssh_port = UNSET_VALUE
67
110
  @vm_size = UNSET_VALUE
68
- @winrm_transport = UNSET_VALUE
69
- @winrm_http_port = UNSET_VALUE
70
- @winrm_https_port = UNSET_VALUE
71
111
  @availability_set_name = UNSET_VALUE
72
- @state_read_timeout = UNSET_VALUE
112
+ @instance_ready_timeout = UNSET_VALUE
113
+ @instance_check_interval = UNSET_VALUE
73
114
  end
74
115
 
75
116
  def finalize!
76
- @storage_acct_name = ENV['AZURE_STORAGE_ACCOUNT'] if @storage_acct_name == UNSET_VALUE
77
- @storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY'] if @storage_access_key == UNSET_VALUE
78
- @mgmt_certificate = ENV['AZURE_MANAGEMENT_CERTIFICATE'] if @mgmt_certificate == UNSET_VALUE
79
- @mgmt_endpoint = ENV['AZURE_MANAGEMENT_ENDPOINT'] if @mgmt_endpoint == UNSET_VALUE
117
+ @endpoint = (ENV['AZURE_MANAGEMENT_ENDPOINT'] || 'https://management.azure.com') if @endpoint == UNSET_VALUE
80
118
  @subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] if @subscription_id == UNSET_VALUE
119
+ @tenant_id = ENV['AZURE_TENANT_ID'] if @tenant_id == UNSET_VALUE
120
+ @client_id = ENV['AZURE_CLIENT_ID'] if @client_id == UNSET_VALUE
121
+ @client_secret = ENV['AZURE_CLIENT_SECRET'] if @client_secret == UNSET_VALUE
81
122
 
82
- @vm_name = nil if @vm_name == UNSET_VALUE
83
- @vm_user = 'vagrant' if @vm_user == UNSET_VALUE
123
+ @vm_name = Haikunator.haikunate(100) if @vm_name == UNSET_VALUE
124
+ @resource_group_name = Haikunator.haikunate(100) if @resource_group_name == UNSET_VALUE
84
125
  @vm_password = nil if @vm_password == UNSET_VALUE
85
- @vm_image = nil if @vm_image == UNSET_VALUE
86
- @vm_location = 'West US' if @vm_location == UNSET_VALUE
87
- @vm_affinity_group = nil if @vm_affinity_group == UNSET_VALUE
88
- @vm_virtual_network_name = nil if @vm_virtual_network_name == UNSET_VALUE
89
-
90
- @cloud_service_name = nil if @cloud_service_name == UNSET_VALUE
91
- @deployment_name = nil if @deployment_name == UNSET_VALUE
126
+ @vm_image_urn = 'canonical:ubuntuserver:16.04.0-DAILY-LTS:latest' if @vm_image_urn == UNSET_VALUE
127
+ @location = 'westus' if @location == UNSET_VALUE
128
+ @virtual_network_name = nil if @virtual_network_name == UNSET_VALUE
129
+ @subnet_name = nil if @subnet_name == UNSET_VALUE
92
130
  @tcp_endpoints = nil if @tcp_endpoints == UNSET_VALUE
93
- @private_key_file = nil if @private_key_file == UNSET_VALUE
94
-
95
- @ssh_port = nil if @ssh_port == UNSET_VALUE
96
- @vm_size = nil if @vm_size == UNSET_VALUE
97
- @winrm_transport = nil if @winrm_transport == UNSET_VALUE
98
- @winrm_http_port = nil if @winrm_http_port == UNSET_VALUE
99
- @winrm_https_port = nil if @winrm_https_port == UNSET_VALUE
131
+ @vm_size = 'Standard_D1' if @vm_size == UNSET_VALUE
100
132
  @availability_set_name = nil if @availability_set_name == UNSET_VALUE
101
133
 
102
- @state_read_timeout = nil if @state_read_timeout == UNSET_VALUE
103
-
104
- utils = Class.new.extend(Azure::Core::Utility)
105
-
106
- # This done due to a bug in Ruby SDK - it doesn't generate a storage
107
- # account name if add_role = true
108
- if @storage_acct_name.nil? || @storage_acct_name.empty?
109
- @storage_acct_name = utils.random_string("#{@vm_name}storage").gsub(/[^0-9a-z ]/i, '').downcase[0..23]
110
- end
111
-
112
- if @cloud_service_name.nil? || @cloud_service_name.empty?
113
- @cloud_service_name = utils.random_string("#{@vm_name}-service-")
114
- end
134
+ @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
135
+ @instance_check_interval = 2 if @instance_check_interval == UNSET_VALUE
115
136
  end
116
137
 
117
138
  def validate(machine)
118
139
  errors = _detected_errors
119
140
 
120
141
  # Azure connection properties related validation.
121
- errors << 'vagrant_azure.subscription_id.required' if @subscription_id.nil?
122
- errors << 'vagrant_azure.mgmt_certificate.required' if @mgmt_certificate.nil?
123
- errors << 'vagrant_azure.mgmt_endpoint.required' if @mgmt_endpoint.nil?
124
-
125
- # Azure Virtual Machine related validation
126
- errors << 'vagrant_azure.vm_name.required' if @vm_name.nil?
127
-
128
- paths = machine.config.ssh.private_key_path
129
- unless @vm_password || machine.config.ssh.password || @private_key_file || (paths && paths.count > 0)
130
- errors << 'You must provide one of the following: ssh.private_key_path, azure.private_key_file, ssh.password or azure.vm_password.'
131
- end
132
-
133
- if (@private_key_file || (paths && paths.count > 0)) && (@vm_password || machine.config.ssh.password)
134
- machine.config.ssh.password = @vm_password = nil
135
- machine.ui.warn('You specified both private_key and password. Vagrant-Azure will only use the private_key in this case.')
136
- end
137
-
138
- if machine.config.ssh.password.nil? && @vm_password
139
- machine.config.ssh.password = @vm_password
140
- elsif machine.config.ssh.password && @vm_password.nil?
141
- @vm_password = machine.config.ssh.password
142
- end
143
-
144
- if machine.config.ssh.private_key_path.nil? && @private_key_file
145
- machine.config.ssh.private_key_path = [File.expand_path(@private_key_file)]
146
- elsif machine.config.ssh.private_key_path && @private_key_file.nil?
147
- @private_key_file = File.expand_path(paths.first)
148
- end
142
+ errors << I18n.t('vagrant_azure.subscription_id.required') if @subscription_id.nil?
143
+ errors << I18n.t('vagrant_azure.mgmt_endpoint.required') if @endpoint.nil?
144
+ errors << I18n.t('vagrant_azure.auth.required') if @tenant_id.nil? || @client_secret.nil? || @client_id.nil?
149
145
 
150
146
  { 'Microsoft Azure Provider' => errors }
151
147
  end
@@ -1,25 +1,23 @@
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
- #--------------------------------------------------------------------------
1
+ # encoding: utf-8
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License in the project root for license information.
6
4
 
7
5
  module VagrantPlugins
8
- module WinAzure
6
+ module Azure
9
7
  module Errors
10
- class WinAzureError < Vagrant::Errors::VagrantError
11
- error_namespace("vagrant_azure.errors")
8
+ class AzureError < Vagrant::Errors::VagrantError
9
+ error_namespace('vagrant_azure.errors')
12
10
  end
13
11
 
14
- class WinRMNotReady < WinAzureError
12
+ class WinRMNotReady < AzureError
15
13
  error_key(:win_rm_not_ready)
16
14
  end
17
15
 
18
- class ServerNotCreated < WinAzureError
16
+ class ServerNotCreated < AzureError
19
17
  error_key(:server_not_created)
20
18
  end
21
19
 
22
- class CreateVMFailure < WinAzureError
20
+ class CreateVMFailure < AzureError
23
21
  error_key(:create_vm_failure)
24
22
  end
25
23