vagrant-azure 2.0.0.pre7 → 2.0.0.pre8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rubocop.yml +120 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -5
- data/README.md +98 -57
- data/docs/basic_linux/Vagrantfile +17 -0
- data/docs/basic_linux/readme.md +12 -0
- data/docs/basic_windows/Vagrantfile +20 -0
- data/docs/basic_windows/readme.md +12 -0
- data/docs/custom_vhd/Vagrantfile +16 -0
- data/docs/custom_vhd/readme.md +48 -0
- data/docs/data_disks/Vagrantfile +16 -0
- data/docs/data_disks/readme.md +20 -0
- data/docs/managed_image/Vagrantfile +15 -0
- data/docs/managed_image/readme.md +66 -0
- data/docs/readme.md +30 -0
- data/lib/vagrant-azure/action/run_instance.rb +95 -69
- data/lib/vagrant-azure/config.rb +75 -4
- data/lib/vagrant-azure/util/machine_id_helper.rb +4 -0
- data/lib/vagrant-azure/util/managed_image_helper.rb +26 -0
- data/lib/vagrant-azure/util/template_renderer.rb +54 -0
- data/lib/vagrant-azure/util/timer.rb +4 -0
- data/lib/vagrant-azure/util/vm_await.rb +4 -0
- data/lib/vagrant-azure/util/vm_status_translator.rb +4 -0
- data/lib/vagrant-azure/version.rb +1 -1
- data/locales/en.yml +6 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/templates/arm/deployment_spec.rb +169 -0
- data/spec/vagrant-azure/config_spec.rb +3 -3
- data/templates/arm/deployment.json.erb +50 -258
- data/templates/arm/resources/availability_set.json.erb +6 -0
- data/templates/arm/resources/data_disk.json.erb +21 -0
- data/templates/arm/resources/import_vhd_image.json.erb +23 -0
- data/templates/arm/resources/linux_reset_root_ext.json.erb +20 -0
- data/templates/arm/resources/network_interface.json.erb +26 -0
- data/templates/arm/resources/network_security_group.json.erb +85 -0
- data/templates/arm/resources/public_ip_address.json.erb +12 -0
- data/templates/arm/resources/storage_account.json.erb +9 -0
- data/templates/arm/resources/virtual_machine.json.erb +82 -0
- data/templates/arm/resources/virtual_network.json.erb +27 -0
- data/templates/arm/resources/windows_reset_access_ext.json.erb +21 -0
- data/vagrant-azure.gemspec +4 -6
- metadata +38 -40
- data/spec/vagrant-azure/services/azure_resource_manager_spec.rb +0 -19
@@ -0,0 +1,12 @@
|
|
1
|
+
# Basic Windows SQL Server 2016 Machine
|
2
|
+
This scenario will build a Windows SQL Server 2016 machine.
|
3
|
+
|
4
|
+
Before you attempt this scenario, ensure you have followed the [getting started docs](../../readme.md#getting-started).
|
5
|
+
|
6
|
+
## Vagrant up
|
7
|
+
- In this directory, run the following
|
8
|
+
```bash
|
9
|
+
vagrant up --provider=azure
|
10
|
+
```
|
11
|
+
|
12
|
+
To clean up, run `vagrant destroy`
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
Vagrant.configure("2") do |config|
|
3
|
+
config.vm.box = "azure"
|
4
|
+
|
5
|
+
# use local ssh key to connect to remote vagrant box
|
6
|
+
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
7
|
+
config.vm.provider :azure do |azure, override|
|
8
|
+
azure.location = "westus"
|
9
|
+
|
10
|
+
# change this URI to your storage account blob within the same region as specified above
|
11
|
+
azure.vm_vhd_uri = "https://vagrantimages.blob.core.windows.net/vhds/xenial-server-cloudimg-amd64-disk1.vhd"
|
12
|
+
azure.vm_operating_system = "Linux"
|
13
|
+
end
|
14
|
+
|
15
|
+
config.vm.provision "shell", inline: "echo Hello, World"
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Ubuntu Xenial Machine from VHD
|
2
|
+
This scenario will build a custom image from a prepared Ubuntu Xenial VHD. This will build an Azure Managed
|
3
|
+
Image from the custom generalized VHD. The Azure Managed Image will be used to create a new Azure Virtual
|
4
|
+
Machine.
|
5
|
+
|
6
|
+
To see more information about this scenario, see [Prepare an Ubuntu virtual machine for Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/create-upload-ubuntu)
|
7
|
+
|
8
|
+
Before you attempt this scenario, ensure you have followed the [getting started docs](../../readme.md#getting-started).
|
9
|
+
|
10
|
+
If you wanted to build a more customized image, you could do the same with your own VHD manually by following these
|
11
|
+
[instructions](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/create-upload-ubuntu?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json#manual-steps).
|
12
|
+
|
13
|
+
## Vagrant up
|
14
|
+
We will set this up with Azure CLI and then run Vagrant after we've provisioned the needed Azure resources.
|
15
|
+
- Login to Azure CLI (if not already logged in)
|
16
|
+
```bash
|
17
|
+
az login
|
18
|
+
```
|
19
|
+
- Create a resource group for your VHDs (assuming westus)
|
20
|
+
```bash
|
21
|
+
az group create -n vagrantimages -l westus
|
22
|
+
```
|
23
|
+
- Create a storage account in the region you'd like to deploy
|
24
|
+
```bash
|
25
|
+
# insert your own name for the storage account DNS name (-n)
|
26
|
+
az storage account create -g vagrantimages -n vagrantimagesXXXX --sku Standard_LRS -l westus
|
27
|
+
```
|
28
|
+
- Download and unzip the VHD from Ubuntu
|
29
|
+
```bash
|
30
|
+
wget -qO- -O tmp.zip http://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64-disk1.vhd.zip && unzip tmp.zip && rm tmp.zip
|
31
|
+
```
|
32
|
+
- Upload the VHD to your storage account in the vhds container
|
33
|
+
```bash
|
34
|
+
conn_string=$(az storage account show-connection-string -g vagrantimages -n vagrantimagesXXXX -o tsv)
|
35
|
+
az storage container create -n vhds --connection-string $conn_string
|
36
|
+
az storage container create -n vhds vagrantimagesXXXX
|
37
|
+
az storage blob upload -c vhds -n xenial-server-cloudimg-amd64-disk1.vhd -f xenial-server-cloudimg-amd64-disk1.vhd --connection-string $conn_string
|
38
|
+
```
|
39
|
+
- Update Vagrantfile with the URI of your uploaded blob (`azure.vm_vhd_uri`).
|
40
|
+
- Vagrant up
|
41
|
+
```bash
|
42
|
+
vagrant up --provider=azure
|
43
|
+
```
|
44
|
+
|
45
|
+
To clean up, run `vagrant destroy`
|
46
|
+
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
Vagrant.configure("2") do |config|
|
3
|
+
config.vm.box = "azure"
|
4
|
+
|
5
|
+
# use local ssh key to connect to remote vagrant box
|
6
|
+
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
7
|
+
config.vm.provider :azure do |azure, override|
|
8
|
+
azure.location = "westus"
|
9
|
+
|
10
|
+
azure.data_disks = [
|
11
|
+
{ name: "foo", size_gb: 30 }
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
config.vm.provision "shell", inline: "echo Hello, World"
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Linux Machine with Empty Data Disks
|
2
|
+
This scenario will build an Ubuntu 16.04 machine with data disks attached to the virtual machine.
|
3
|
+
|
4
|
+
To see more information about this scenario, see [How to Attach a Data Disk to a Linux VM](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/attach-disk)
|
5
|
+
|
6
|
+
Before you attempt this scenario, ensure you have followed the [getting started docs](../../readme.md#getting-started).
|
7
|
+
|
8
|
+
*Note: data disk support is preview and will likely change before becoming stable*
|
9
|
+
|
10
|
+
## Vagrant up
|
11
|
+
- In this directory, run the following
|
12
|
+
```bash
|
13
|
+
vagrant up --provider=azure
|
14
|
+
```
|
15
|
+
- The Vagrant file specifies on data disk named foo. The foo disk is not formatted, nor mounted. If you
|
16
|
+
would like to use the disk, you will need to format and mount the drive. For instructions on how to do that,
|
17
|
+
see: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/attach-disk#initialize-a-new-data-disk-in-linux.
|
18
|
+
In the next rev of data disks, we'll handle mounting and formatting.
|
19
|
+
|
20
|
+
To clean up, run `vagrant destroy`
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
Vagrant.configure("2") do |config|
|
3
|
+
config.vm.box = "azure"
|
4
|
+
|
5
|
+
# use local ssh key to connect to remote vagrant box
|
6
|
+
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
7
|
+
config.vm.provider :azure do |azure, override|
|
8
|
+
azure.location = "westus"
|
9
|
+
|
10
|
+
# replace this with your managed image resource id
|
11
|
+
azure.vm_managed_image_id = "/subscriptions/{subscription_id}/resourceGroups/{group}/providers/Microsoft.Compute/images/{image_name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
config.vm.provision "shell", inline: "echo Hello, World"
|
15
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Ubuntu Machine from a Captured Managed Image
|
2
|
+
This scenario will build a machine from a captured managed image. We will build a VM with Azure CLI, capture
|
3
|
+
an image of the VM and use that image reference for a new Vagrant machine.
|
4
|
+
|
5
|
+
To see more information about this scenario, see [Create a VM from the captured image](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/capture-image#step-3-create-a-vm-from-the-captured-image)
|
6
|
+
|
7
|
+
Before you attempt this scenario, ensure you have followed the [getting started docs](../../readme.md#getting-started).
|
8
|
+
|
9
|
+
## Vagrant up
|
10
|
+
We will set this up with Azure CLI and then run Vagrant after we've provisioned the needed Azure resources.
|
11
|
+
- Login to Azure CLI (if not already logged in)
|
12
|
+
```bash
|
13
|
+
az login
|
14
|
+
```
|
15
|
+
- Create a resource group for your VHDs (assuming westus)
|
16
|
+
```bash
|
17
|
+
az group create -n vagrant -l westus
|
18
|
+
```
|
19
|
+
- Create a new VM
|
20
|
+
```bash
|
21
|
+
az vm create -g vagrant -n vagrant-box --admin-username deploy --image UbuntuLTS
|
22
|
+
```
|
23
|
+
- Capture an image of the VM
|
24
|
+
```bash
|
25
|
+
az vm deallocate -g vagrant -n vagrant-box
|
26
|
+
az vm generalize -g vagrant -n vagrant-box
|
27
|
+
az image create -g vagrant --name vagrant-box-image --source vagrant-box
|
28
|
+
```
|
29
|
+
You should see json output from the `az image create` command. Extract the "id" value from below for use in your Vagrantfile.
|
30
|
+
```json
|
31
|
+
{
|
32
|
+
"id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/resourceGroups/vagrant/providers/Microsoft.Compute/images/vagrant-box-image",
|
33
|
+
"location": "westus",
|
34
|
+
"name": "vagrant-box-image",
|
35
|
+
"provisioningState": "Succeeded",
|
36
|
+
"resourceGroup": "vagrant",
|
37
|
+
"sourceVirtualMachine": {
|
38
|
+
"id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/resourceGroups/vagrant-test/providers/Microsoft.Compute/virtualMachines/vagrant-box",
|
39
|
+
"resourceGroup": "vagrant"
|
40
|
+
},
|
41
|
+
"storageProfile": {
|
42
|
+
"dataDisks": [],
|
43
|
+
"osDisk": {
|
44
|
+
"blobUri": null,
|
45
|
+
"caching": "ReadWrite",
|
46
|
+
"diskSizeGb": null,
|
47
|
+
"managedDisk": {
|
48
|
+
"id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/resourceGroups/vagrant-test/providers/Microsoft.Compute/disks/osdisk_5ZglGr7Rj4",
|
49
|
+
"resourceGroup": "vagrant"
|
50
|
+
},
|
51
|
+
"osState": "Generalized",
|
52
|
+
"osType": "Linux",
|
53
|
+
"snapshot": null
|
54
|
+
}
|
55
|
+
},
|
56
|
+
"tags": null,
|
57
|
+
"type": "Microsoft.Compute/images"
|
58
|
+
}
|
59
|
+
```
|
60
|
+
- Update the Vagrantfile in this directory with the URI of your managed image resource (`azure.vm_managed_image_id`).
|
61
|
+
- Vagrant up
|
62
|
+
```bash
|
63
|
+
vagrant up --provider=azure
|
64
|
+
```
|
65
|
+
|
66
|
+
To clean up, run `vagrant destroy`
|
data/docs/readme.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Vagrant Azure Scenario Docs
|
2
|
+
Here you can find some common scenarios for using Azure plugin for Vagrant.
|
3
|
+
|
4
|
+
## Prerequisites
|
5
|
+
Before you attempt any scenario, ensure you have followed the [getting started docs](../readme.md#getting-started).
|
6
|
+
|
7
|
+
## Scenarios
|
8
|
+
|
9
|
+
### [Basic Linux Setup](./basic_linux)
|
10
|
+
Setup a simple Ubuntu 16.04 machine
|
11
|
+
|
12
|
+
### [Basic Windows Setup](./basic_windows)
|
13
|
+
Setup a Windows SQL Server 2016 machine
|
14
|
+
|
15
|
+
### [Ubuntu Xenial Machine from VHD](./custom_vhd)
|
16
|
+
Setup an Ubuntu box from a custom VHD
|
17
|
+
|
18
|
+
### [Managed Image Reference](./managed_image)
|
19
|
+
Setup a VM from a managed image reference captured from a previously created Azure VM.
|
20
|
+
|
21
|
+
### [Data Disks (empty disk)](./data_disks)
|
22
|
+
Setup an Ubuntu box with an empty attached disk
|
23
|
+
|
24
|
+
## Azure Boxes
|
25
|
+
|
26
|
+
The vagrant-azure plugin provides the ability to use ```Azure``` boxes with Vagrant. Please see the example box
|
27
|
+
provided in [example_box](https://github.com/azure/vagrant-azure/tree/v2.0/example_box) directory and follow the
|
28
|
+
instructions there to build an `azure` box.
|
29
|
+
|
30
|
+
For general Vagrant documentation see [Vagrant Docs](http://docs.vagrantup.com/v2/).
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
3
|
# Licensed under the MIT License. See License in the project root for license information.
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
4
|
+
require "log4r"
|
5
|
+
require "json"
|
6
|
+
require "azure_mgmt_resources"
|
7
|
+
require "vagrant-azure/util/machine_id_helper"
|
8
|
+
require "vagrant-azure/util/template_renderer"
|
9
|
+
require "vagrant-azure/util/managed_image_helper"
|
10
|
+
require "vagrant-azure/util/timer"
|
11
|
+
require "haikunator"
|
11
12
|
|
12
13
|
module VagrantPlugins
|
13
14
|
module Azure
|
@@ -15,10 +16,11 @@ module VagrantPlugins
|
|
15
16
|
class RunInstance
|
16
17
|
include Vagrant::Util::Retryable
|
17
18
|
include VagrantPlugins::Azure::Util::MachineIdHelper
|
19
|
+
include VagrantPlugins::Azure::Util::ManagedImagedHelper
|
18
20
|
|
19
21
|
def initialize(app, env)
|
20
22
|
@app = app
|
21
|
-
@logger = Log4r::Logger.new(
|
23
|
+
@logger = Log4r::Logger.new("vagrant_azure::action::run_instance")
|
22
24
|
end
|
23
25
|
|
24
26
|
def call(env)
|
@@ -29,14 +31,20 @@ module VagrantPlugins
|
|
29
31
|
|
30
32
|
# Get the configs
|
31
33
|
config = machine.provider_config
|
34
|
+
|
35
|
+
config.dns_name ||= config.vm_name
|
36
|
+
config.nsg_name ||= config.vm_name
|
37
|
+
|
32
38
|
endpoint = config.endpoint
|
33
39
|
resource_group_name = config.resource_group_name
|
34
40
|
location = config.location
|
35
41
|
ssh_user_name = machine.config.ssh.username
|
36
42
|
vm_name = config.vm_name
|
37
|
-
vm_password = config.vm_password
|
38
43
|
vm_size = config.vm_size
|
39
44
|
vm_image_urn = config.vm_image_urn
|
45
|
+
vm_vhd_uri = config.vm_vhd_uri
|
46
|
+
vm_operating_system = config.vm_operating_system
|
47
|
+
vm_managed_image_id = config.vm_managed_image_id
|
40
48
|
virtual_network_name = config.virtual_network_name
|
41
49
|
subnet_name = config.subnet_name
|
42
50
|
tcp_endpoints = config.tcp_endpoints
|
@@ -45,8 +53,8 @@ module VagrantPlugins
|
|
45
53
|
admin_password = config.admin_password
|
46
54
|
winrm_port = machine.config.winrm.port
|
47
55
|
winrm_install_self_signed_cert = config.winrm_install_self_signed_cert
|
48
|
-
dns_label_prefix =
|
49
|
-
|
56
|
+
dns_label_prefix = config.dns_name
|
57
|
+
nsg_label_prefix = config.nsg_name
|
50
58
|
|
51
59
|
# Launch!
|
52
60
|
env[:ui].info(I18n.t('vagrant_azure.launching_instance'))
|
@@ -58,64 +66,79 @@ module VagrantPlugins
|
|
58
66
|
env[:ui].info(" -- Admin Username: #{admin_user_name}") if admin_user_name
|
59
67
|
env[:ui].info(" -- VM Name: #{vm_name}")
|
60
68
|
env[:ui].info(" -- VM Size: #{vm_size}")
|
61
|
-
|
69
|
+
|
70
|
+
if !vm_vhd_uri.nil?
|
71
|
+
env[:ui].info(" -- Custom VHD URI: #{vm_vhd_uri}")
|
72
|
+
env[:ui].info(" -- Custom OS: #{vm_operating_system}")
|
73
|
+
elsif !vm_managed_image_id.nil?
|
74
|
+
env[:ui].info(" -- Managed Image Id: #{vm_managed_image_id}")
|
75
|
+
else
|
76
|
+
env[:ui].info(" -- Image URN: #{vm_image_urn}")
|
77
|
+
end
|
78
|
+
|
62
79
|
env[:ui].info(" -- Virtual Network Name: #{virtual_network_name}") if virtual_network_name
|
63
80
|
env[:ui].info(" -- Subnet Name: #{subnet_name}") if subnet_name
|
64
81
|
env[:ui].info(" -- TCP Endpoints: #{tcp_endpoints}") if tcp_endpoints
|
65
82
|
env[:ui].info(" -- Availability Set Name: #{availability_set_name}") if availability_set_name
|
66
83
|
env[:ui].info(" -- DNS Label Prefix: #{dns_label_prefix}")
|
67
84
|
|
68
|
-
image_publisher, image_offer, image_sku, image_version = vm_image_urn.split(
|
85
|
+
image_publisher, image_offer, image_sku, image_version = vm_image_urn.split(":")
|
69
86
|
|
70
87
|
azure = env[:azure_arm_service]
|
71
|
-
|
72
|
-
env[:metrics]['get_image_details'] = Util::Timer.time do
|
73
|
-
image_details = get_image_details(azure, location, image_publisher, image_offer, image_sku, image_version)
|
74
|
-
end
|
75
|
-
@logger.info("Time to fetch os image details: #{env[:metrics]['get_image_details']}")
|
88
|
+
@logger.info("Time to fetch os image details: #{env[:metrics]["get_image_details"]}")
|
76
89
|
|
77
90
|
deployment_params = {
|
78
91
|
dnsLabelPrefix: dns_label_prefix,
|
92
|
+
nsgLabelPrefix: nsg_label_prefix,
|
79
93
|
vmSize: vm_size,
|
80
94
|
vmName: vm_name,
|
81
|
-
imagePublisher: image_publisher,
|
82
|
-
imageOffer: image_offer,
|
83
|
-
imageSku: image_sku,
|
84
|
-
imageVersion: image_version,
|
85
95
|
subnetName: subnet_name,
|
86
96
|
virtualNetworkName: virtual_network_name,
|
87
97
|
}
|
88
98
|
|
89
99
|
# we need to pass different parameters depending upon the OS
|
90
|
-
|
100
|
+
# if custom image, then require vm_operating_system
|
101
|
+
operating_system = if vm_vhd_uri
|
102
|
+
vm_operating_system
|
103
|
+
elsif vm_managed_image_id
|
104
|
+
get_managed_image_os(azure, vm_managed_image_id)
|
105
|
+
else
|
106
|
+
get_image_os(azure, location, image_publisher, image_offer, image_sku, image_version)
|
107
|
+
end
|
91
108
|
|
92
109
|
template_params = {
|
93
110
|
availability_set_name: availability_set_name,
|
94
|
-
operating_system: operating_system,
|
95
111
|
winrm_install_self_signed_cert: winrm_install_self_signed_cert,
|
96
112
|
winrm_port: winrm_port,
|
97
113
|
dns_label_prefix: dns_label_prefix,
|
114
|
+
nsg_label_prefix: nsg_label_prefix,
|
98
115
|
location: location,
|
99
|
-
|
116
|
+
image_publisher: image_publisher,
|
117
|
+
image_offer: image_offer,
|
118
|
+
image_sku: image_sku,
|
119
|
+
image_version: image_version,
|
120
|
+
vhd_uri: vm_vhd_uri,
|
121
|
+
operating_system: operating_system,
|
122
|
+
data_disks: config.data_disks
|
100
123
|
}
|
101
124
|
|
102
|
-
if operating_system !=
|
125
|
+
if operating_system != "Windows"
|
103
126
|
private_key_paths = machine.config.ssh.private_key_path
|
104
127
|
if private_key_paths.nil? || private_key_paths.empty?
|
105
128
|
raise I18n.t('vagrant_azure.private_key_not_specified')
|
106
129
|
end
|
107
130
|
|
108
|
-
paths_to_pub = private_key_paths.map{ |k| File.expand_path(
|
131
|
+
paths_to_pub = private_key_paths.map { |k| File.expand_path(k + ".pub") }.select { |p| File.exists?(p) }
|
109
132
|
raise I18n.t('vagrant_azure.public_key_path_private_key', private_key_paths.join(', ')) if paths_to_pub.empty?
|
110
133
|
deployment_params.merge!(adminUsername: ssh_user_name)
|
111
134
|
deployment_params.merge!(sshKeyData: File.read(paths_to_pub.first))
|
112
|
-
communicator_message =
|
135
|
+
communicator_message = "vagrant_azure.waiting_for_ssh"
|
113
136
|
else
|
114
137
|
env[:machine].config.vm.communicator = :winrm
|
115
138
|
machine.config.winrm.port = winrm_port
|
116
139
|
machine.config.winrm.username = admin_user_name
|
117
140
|
machine.config.winrm.password = admin_password
|
118
|
-
communicator_message =
|
141
|
+
communicator_message = "vagrant_azure.waiting_for_winrm"
|
119
142
|
windows_params = {
|
120
143
|
adminUsername: admin_user_name,
|
121
144
|
adminPassword: admin_password,
|
@@ -124,44 +147,28 @@ module VagrantPlugins
|
|
124
147
|
deployment_params.merge!(windows_params)
|
125
148
|
end
|
126
149
|
|
127
|
-
|
128
|
-
|
129
|
-
if tcp_endpoints.is_a?(Array)
|
130
|
-
# https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-nsg#Nsg-rules
|
131
|
-
if tcp_endpoints.length + 133 > 4096
|
132
|
-
raise I18n.t('vagrant_azure.too_many_tcp_endpoints', count: tcp_endpoints.length)
|
133
|
-
end
|
134
|
-
endpoints = tcp_endpoints
|
135
|
-
elsif tcp_endpoints.is_a?(String) || (tcp_endpoints.is_a?(Integer) && tcp_endpoints > 0)
|
136
|
-
endpoints = [tcp_endpoints]
|
137
|
-
else
|
138
|
-
raise I18n.t('vagrant_azure.unknown_type_as_tcp_endpoints', input: tcp_endpoints)
|
139
|
-
end
|
140
|
-
else
|
141
|
-
endpoints = []
|
142
|
-
end
|
143
|
-
template_params.merge!(endpoints: endpoints)
|
150
|
+
template_params.merge!(endpoints: get_endpoints(tcp_endpoints))
|
144
151
|
|
145
152
|
env[:ui].info(" -- Create or Update of Resource Group: #{resource_group_name}")
|
146
|
-
env[:metrics][
|
153
|
+
env[:metrics]["put_resource_group"] = Util::Timer.time do
|
147
154
|
put_resource_group(azure, resource_group_name, location)
|
148
155
|
end
|
149
156
|
@logger.info("Time to create resource group: #{env[:metrics]['put_resource_group']}")
|
150
157
|
|
151
|
-
deployment_params = build_deployment_params(template_params, deployment_params.reject{|_,v| v.nil?})
|
158
|
+
deployment_params = build_deployment_params(template_params, deployment_params.reject { |_, v| v.nil? })
|
152
159
|
|
153
|
-
env[:ui].info(
|
154
|
-
env[:metrics][
|
160
|
+
env[:ui].info(" -- Starting deployment")
|
161
|
+
env[:metrics]["deployment_time"] = Util::Timer.time do
|
155
162
|
put_deployment(azure, resource_group_name, deployment_params)
|
156
163
|
end
|
157
|
-
env[:ui].info(
|
164
|
+
env[:ui].info(" -- Finished deploying")
|
158
165
|
|
159
166
|
# Immediately save the ID since it is created at this point.
|
160
167
|
env[:machine].id = serialize_machine_id(resource_group_name, vm_name, location)
|
161
168
|
|
162
169
|
@logger.info("Time to deploy: #{env[:metrics]['deployment_time']}")
|
163
170
|
unless env[:interrupted]
|
164
|
-
env[:metrics][
|
171
|
+
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
|
165
172
|
# Wait for SSH/WinRM to be ready.
|
166
173
|
env[:ui].info(I18n.t(communicator_message))
|
167
174
|
network_ready_retries = 0
|
@@ -194,14 +201,42 @@ module VagrantPlugins
|
|
194
201
|
@app.call(env)
|
195
202
|
end
|
196
203
|
|
197
|
-
def
|
204
|
+
def get_endpoints(tcp_endpoints)
|
205
|
+
endpoints = [8443]
|
206
|
+
unless tcp_endpoints.nil?
|
207
|
+
if tcp_endpoints.is_a?(Array)
|
208
|
+
# https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-nsg#Nsg-rules
|
209
|
+
if tcp_endpoints.length + 133 > 4096
|
210
|
+
raise I18n.t("vagrant_azure.too_many_tcp_endpoints", count: tcp_endpoints.length)
|
211
|
+
end
|
212
|
+
endpoints = tcp_endpoints
|
213
|
+
elsif tcp_endpoints.is_a?(String) || (tcp_endpoints.is_a?(Integer) && tcp_endpoints > 0)
|
214
|
+
endpoints = [tcp_endpoints]
|
215
|
+
else
|
216
|
+
raise I18n.t("vagrant_azure.unknown_type_as_tcp_endpoints", input: tcp_endpoints)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
endpoints
|
220
|
+
end
|
221
|
+
|
222
|
+
def get_image_os(azure, location, publisher, offer, sku, version)
|
223
|
+
image_details = get_image_details(azure, location, publisher, offer, sku, version)
|
198
224
|
image_details.os_disk_image.operating_system
|
199
225
|
end
|
200
226
|
|
227
|
+
def get_managed_image_os(azure, image_id)
|
228
|
+
_, group, name = image_id_captures(image_id)
|
229
|
+
image_details = azure.compute.images.get(group, name)
|
230
|
+
image_details.storage_profile.os_disk.os_type
|
231
|
+
end
|
232
|
+
|
201
233
|
def get_image_details(azure, location, publisher, offer, sku, version)
|
202
|
-
if version ==
|
234
|
+
if version == "latest"
|
203
235
|
images = azure.compute.virtual_machine_images.list(location, publisher, offer, sku)
|
204
236
|
latest = images.sort_by(&:name).last
|
237
|
+
if latest.nil?
|
238
|
+
raise "Unrecognized location, publisher, offer, sku, version combination: #{location}, #{publisher}, #{offer}, #{sku}, latest. Run `az vm image list` to ensure the image is available."
|
239
|
+
end
|
205
240
|
azure.compute.virtual_machine_images.get(location, publisher, offer, sku, latest.name)
|
206
241
|
else
|
207
242
|
azure.compute.virtual_machine_images.get(location, publisher, offer, sku, version)
|
@@ -224,37 +259,28 @@ module VagrantPlugins
|
|
224
259
|
# This method generates the deployment template
|
225
260
|
def render_deployment_template(options)
|
226
261
|
self_signed_cert_resource = nil
|
227
|
-
if options[:operating_system] ==
|
228
|
-
setup_winrm_powershell =
|
262
|
+
if options[:operating_system] == "Windows" && options[:winrm_install_self_signed_cert]
|
263
|
+
setup_winrm_powershell = VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/setup-winrm.ps1", options)
|
229
264
|
encoded_setup_winrm_powershell = setup_winrm_powershell.
|
230
265
|
gsub("'", "', variables('singleQuote'), '").
|
231
266
|
gsub("\r\n", "\n").
|
232
267
|
gsub("\n", "; ")
|
233
|
-
self_signed_cert_resource =
|
268
|
+
self_signed_cert_resource = VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/selfsignedcert.json", options.merge({setup_winrm_powershell: encoded_setup_winrm_powershell}))
|
234
269
|
end
|
235
|
-
|
270
|
+
VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/deployment.json", options.merge({self_signed_cert_resource: self_signed_cert_resource}))
|
236
271
|
end
|
237
272
|
|
238
273
|
def build_deployment_params(template_params, deployment_params)
|
239
274
|
params = ::Azure::ARM::Resources::Models::Deployment.new
|
240
275
|
params.properties = ::Azure::ARM::Resources::Models::DeploymentProperties.new
|
241
|
-
|
242
|
-
params.properties.template = JSON.parse(render_deployment_template(template_params))
|
243
|
-
else
|
244
|
-
params.properties.template = JSON.parse(template_params[:deployment_template])
|
245
|
-
end
|
276
|
+
params.properties.template = JSON.parse(render_deployment_template(template_params))
|
246
277
|
params.properties.mode = ::Azure::ARM::Resources::Models::DeploymentMode::Incremental
|
247
278
|
params.properties.parameters = build_parameters(deployment_params)
|
248
279
|
params
|
249
280
|
end
|
250
281
|
|
251
282
|
def build_parameters(options)
|
252
|
-
Hash[*options.map{ |k, v| [k,
|
253
|
-
end
|
254
|
-
|
255
|
-
# Used to find the base location of aws-vagrant templates
|
256
|
-
def template_root
|
257
|
-
Azure.source_root.join('templates')
|
283
|
+
Hash[*options.map { |k, v| [k, { value: v } ] }.flatten]
|
258
284
|
end
|
259
285
|
|
260
286
|
def terminate(env)
|