Class: VagrantPlugins::Azure::Config

Inherits:
Object
  • Object
show all
Includes:
Util::ManagedImagedHelper
Defined in:
lib/vagrant-azure/config.rb

Constant Summary

Constants included from Util::ManagedImagedHelper

Util::ManagedImagedHelper::ID_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::ManagedImagedHelper

#image_id_captures, #image_id_matches, #valid_image_id?

Constructor Details

#initializeConfig

Returns a new instance of Config.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/vagrant-azure/config.rb', line 185

def initialize
  @tenant_id = UNSET_VALUE
  @client_id = UNSET_VALUE
  @client_secret = UNSET_VALUE
  @endpoint = UNSET_VALUE
  @subscription_id = UNSET_VALUE
  @resource_group_name = UNSET_VALUE
  @location = UNSET_VALUE
  @vm_name = UNSET_VALUE
  @vm_password = UNSET_VALUE
  @vm_image_urn = UNSET_VALUE
  @vm_vhd_uri = UNSET_VALUE
  @vm_image_reference_id = UNSET_VALUE
  @vm_operating_system = UNSET_VALUE
  @vm_managed_image_id = UNSET_VALUE
  @data_disks = UNSET_VALUE
  @virtual_network_name = UNSET_VALUE
  @subnet_name = UNSET_VALUE
  @dsn_name = UNSET_VALUE
  @nsg_name = UNSET_VALUE
  @tcp_endpoints = UNSET_VALUE
  @vm_size = UNSET_VALUE
   = UNSET_VALUE
  @availability_set_name = UNSET_VALUE
  @instance_ready_timeout = UNSET_VALUE
  @instance_check_interval = UNSET_VALUE
  @admin_username = UNSET_VALUE
  @admin_password = UNSET_VALUE
  @winrm_install_self_signed_cert = UNSET_VALUE
  @deployment_template = UNSET_VALUE
  @wait_for_destroy = UNSET_VALUE
end

Instance Attribute Details

#admin_passwordString

(Optional - Required for Windows) The admin username for Windows templates – ENV

Returns:

  • (String)


167
168
169
# File 'lib/vagrant-azure/config.rb', line 167

def admin_password
  @admin_password
end

#admin_usernameString

(Optional - requrired for Windows) The admin username for Windows templates – ENV

Returns:

  • (String)


162
163
164
# File 'lib/vagrant-azure/config.rb', line 162

def admin_username
  @admin_username
end

#availability_set_nameString

(Optional) Name of the virtual machine image

Returns:

  • (String)


142
143
144
# File 'lib/vagrant-azure/config.rb', line 142

def availability_set_name
  @availability_set_name
end

#client_idString

The Azure Active Directory Application Client ID – ENV

Returns:

  • (String)


21
22
23
# File 'lib/vagrant-azure/config.rb', line 21

def client_id
  @client_id
end

#client_secretString

The Azure Active Directory Application Client Secret – ENV

Returns:

  • (String)


26
27
28
# File 'lib/vagrant-azure/config.rb', line 26

def client_secret
  @client_secret
end

#data_disksArray

(Optional) Array of data disks to attach to the VM

sample of creating empty data disk

{
    name: "mydatadisk1",
    size_gb: 30
}

sample of attaching an existing VHD as a data disk

{
    name: "mydatadisk2",
    vhd_uri: "http://mystorage.blob.core.windows.net/vhds/mydatadisk2.vhd"
},

sample of attaching a data disk from image

{
    name: "mydatadisk3",
    vhd_uri: "http://mystorage.blob.core.windows.net/vhds/mydatadisk3.vhd",
    image: "http: //storagename.blob.core.windows.net/vhds/VMImageName-datadisk.vhd"
}

Returns:

  • (Array)


122
123
124
# File 'lib/vagrant-azure/config.rb', line 122

def data_disks
  @data_disks
end

#deployment_templateString

(Optional - Required for Windows) The admin username for Windows templates – ENV

Returns:

  • (String)


177
178
179
# File 'lib/vagrant-azure/config.rb', line 177

def deployment_template
  @deployment_template
end

#dns_nameString

(Optional) DNS Name prefix of the virtual machine Uses value of vm_name if not specified. Note: this must conform to the following regular expression:

^[a-z][a-z0-9-]{1,61}[a-z0-9]

Therefore this field mustbe set if vm_name has capital letters (for ex.)

Returns:

  • (String)


57
58
59
# File 'lib/vagrant-azure/config.rb', line 57

def dns_name
  @dns_name
end

#endpointString

(Optional) The Azure Management API endpoint – default ‘management.azure.com’ seconds – ENV.

Returns:

  • (String)


157
158
159
# File 'lib/vagrant-azure/config.rb', line 157

def endpoint
  @endpoint
end

#instance_check_intervalFixnum

(Optional) The interval to wait for checking an instance’s state – default 2 seconds.

Returns:

  • (Fixnum)


152
153
154
# File 'lib/vagrant-azure/config.rb', line 152

def instance_check_interval
  @instance_check_interval
end

#instance_ready_timeoutFixnum

(Optional) The timeout to wait for an instance to become ready – default 120 seconds.

Returns:

  • (Fixnum)


147
148
149
# File 'lib/vagrant-azure/config.rb', line 147

def instance_ready_timeout
  @instance_ready_timeout
end

#locationString

(Optional) Azure location to build the VM – defaults to ‘westus’

Returns:

  • (String)


41
42
43
# File 'lib/vagrant-azure/config.rb', line 41

def location
  @location
end

#nsg_nameString

(Optional) Network Security Group Name prefix of the virtual machine

Returns:

  • (String)


62
63
64
# File 'lib/vagrant-azure/config.rb', line 62

def nsg_name
  @nsg_name
end

#resource_group_nameString

(Optional) Name of the resource group to use.

Returns:

  • (String)


36
37
38
# File 'lib/vagrant-azure/config.rb', line 36

def resource_group_name
  @resource_group_name
end

#subnet_nameString

(Optional) Name of the virtual network subnet resource

Returns:

  • (String)


132
133
134
# File 'lib/vagrant-azure/config.rb', line 132

def subnet_name
  @subnet_name
end

#subscription_idString

The Azure Subscription ID to use – ENV

Returns:

  • (String)


31
32
33
# File 'lib/vagrant-azure/config.rb', line 31

def subscription_id
  @subscription_id
end

#tcp_endpointsString

(Optional) TCP endpoints to open up for the VM

Returns:

  • (String)


137
138
139
# File 'lib/vagrant-azure/config.rb', line 137

def tcp_endpoints
  @tcp_endpoints
end

#tenant_idString

The Azure Active Directory Tenant ID – ENV

Returns:

  • (String)


16
17
18
# File 'lib/vagrant-azure/config.rb', line 16

def tenant_id
  @tenant_id
end

#virtual_network_nameString

(Optional) Name of the virtual network resource

Returns:

  • (String)


127
128
129
# File 'lib/vagrant-azure/config.rb', line 127

def virtual_network_name
  @virtual_network_name
end

#vm_image_urnString

(Optional) Name of the virtual machine image URN to use – defaults to ‘canonical:ubuntuserver:16.04.0-DAILY-LTS:latest’. See: azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/

Returns:

  • (String)


82
83
84
# File 'lib/vagrant-azure/config.rb', line 82

def vm_image_urn
  @vm_image_urn
end

#vm_managed_image_idString

(Optional) The Managed Image Id which will be used to build the VM (like: /subscriptions/sub_id/resourceGroups/group_name/providers/Microsoft.Compute/images/image_name) – default nil.

Returns:

  • (String)


93
94
95
# File 'lib/vagrant-azure/config.rb', line 93

def vm_managed_image_id
  @vm_managed_image_id
end

#vm_nameString

(Optional) Name of the virtual machine

Returns:

  • (String)


46
47
48
# File 'lib/vagrant-azure/config.rb', line 46

def vm_name
  @vm_name
end

#vm_operating_systemString

(Optional unless using custom image) OS of the custom image

Returns:

  • (String)

    “Linux” or “Windows”



98
99
100
# File 'lib/vagrant-azure/config.rb', line 98

def vm_operating_system
  @vm_operating_system
end

#vm_passwordString

Password for the VM – This is not recommended for *nix deployments

Returns:

  • (String)


67
68
69
# File 'lib/vagrant-azure/config.rb', line 67

def vm_password
  @vm_password
end

#vm_sizeString

(Optional) VM size to be used – defaults to ‘Standard_D1’. See: azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/

Returns:

  • (String)


72
73
74
# File 'lib/vagrant-azure/config.rb', line 72

def vm_size
  @vm_size
end

#vm_storage_account_typeString

(Optional) Storage account type to be used – defaults to ‘Premium_LRS’. Alt value is ‘Standard_LRS’ See: docs.microsoft.com/en-us/azure/storage/storage-about-disks-and-vhds-linux

Returns:

  • (String)


77
78
79
# File 'lib/vagrant-azure/config.rb', line 77

def 
  
end

#vm_vhd_uriString

(Optional) Custom OS Image URI (like: mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd) – default nil.

Returns:

  • (String)


87
88
89
# File 'lib/vagrant-azure/config.rb', line 87

def vm_vhd_uri
  @vm_vhd_uri
end

#wait_for_destroyString

(Optional) Wait for all resources to be deleted prior to completing Vagrant destroy – default false.

Returns:

  • (String)


182
183
184
# File 'lib/vagrant-azure/config.rb', line 182

def wait_for_destroy
  @wait_for_destroy
end

#winrm_install_self_signed_certBool

(Optional) Whether to automatically install a self-signed cert and open the firewall port for winrm over https – default true

Returns:

  • (Bool)


172
173
174
# File 'lib/vagrant-azure/config.rb', line 172

def winrm_install_self_signed_cert
  @winrm_install_self_signed_cert
end

Instance Method Details

#finalize!Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/vagrant-azure/config.rb', line 218

def finalize!
  @endpoint = (ENV['AZURE_MANAGEMENT_ENDPOINT'] || 'https://management.azure.com') if @endpoint == UNSET_VALUE
  @subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] if @subscription_id == UNSET_VALUE
  @tenant_id = ENV['AZURE_TENANT_ID'] if @tenant_id == UNSET_VALUE
  @client_id = ENV['AZURE_CLIENT_ID'] if @client_id == UNSET_VALUE
  @client_secret = ENV['AZURE_CLIENT_SECRET'] if @client_secret == UNSET_VALUE


  @resource_group_name = Haikunator.haikunate(100) if @resource_group_name == UNSET_VALUE
  @vm_name = Haikunator.haikunate(100) if @vm_name == UNSET_VALUE
  @vm_size = 'Standard_DS2_v2' if @vm_size == UNSET_VALUE
  @vm_password = nil if @vm_password == UNSET_VALUE
  @vm_image_urn = 'canonical:ubuntuserver:16.04.0-LTS:latest' if @vm_image_urn == UNSET_VALUE
  @vm_vhd_uri = nil if @vm_vhd_uri == UNSET_VALUE
   = nil if  == UNSET_VALUE
  @vm_operating_system = nil if @vm_operating_system == UNSET_VALUE
  @vm_managed_image_id = nil if @vm_managed_image_id == UNSET_VALUE
  @data_disks = [] if @data_disks == UNSET_VALUE

  @location = 'westus' if @location == UNSET_VALUE
  @virtual_network_name = nil if @virtual_network_name == UNSET_VALUE
  @subnet_name = nil if @subnet_name == UNSET_VALUE
  @dns_name = nil if @dns_name == UNSET_VALUE
  @nsg_name = nil if @nsg_name == UNSET_VALUE
  @tcp_endpoints = nil if @tcp_endpoints == UNSET_VALUE
   = 'Premium_LRS' if  == UNSET_VALUE
  @availability_set_name = nil if @availability_set_name == UNSET_VALUE

  @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
  @instance_check_interval = 2 if @instance_check_interval == UNSET_VALUE

  @admin_username = (ENV['AZURE_VM_ADMIN_USERNAME'] || 'vagrant') if @admin_username == UNSET_VALUE
  @admin_password = (ENV['AZURE_VM_ADMIN_PASSWORD'] || '$Vagrant(0)') if @admin_password == UNSET_VALUE
  @winrm_install_self_signed_cert = true if @winrm_install_self_signed_cert == UNSET_VALUE
  @wait_for_destroy = false if @wait_for_destroy == UNSET_VALUE
end

#validate(machine) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/vagrant-azure/config.rb', line 255

def validate(machine)
  errors = _detected_errors

  errors << I18n.t("vagrant_azure.custom_image_os_error") if !@vm_vhd_uri.nil? && @vm_operating_system.nil?
  errors << I18n.t("vagrant_azure.vhd_and_managed_image_error") if !@vm_vhd_uri.nil? && !@vm_managed_image_id.nil?
  errors << I18n.t("vagrant_azure.manage_image_id_format_error") if !@vm_managed_image_id.nil? && !valid_image_id?(@vm_managed_image_id)
  # Azure connection properties related validation.
  errors << I18n.t('vagrant_azure.subscription_id.required') if @subscription_id.nil?
  errors << I18n.t('vagrant_azure.mgmt_endpoint.required') if @endpoint.nil?
  errors << I18n.t('vagrant_azure.auth.required') if @tenant_id.nil? || @client_secret.nil? || @client_id.nil?

  { 'Microsoft Azure Provider' => errors }
end