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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +5 -6
- data/LICENSE +21 -4
- data/README.md +36 -178
- data/Rakefile +3 -5
- data/example_box/Vagrantfile +7 -8
- data/lib/vagrant-azure/action/connect_azure.rb +9 -30
- data/lib/vagrant-azure/action/is_created.rb +19 -0
- data/lib/vagrant-azure/action/is_stopped.rb +19 -0
- data/lib/vagrant-azure/action/message_already_created.rb +19 -0
- data/lib/vagrant-azure/action/message_not_created.rb +19 -0
- data/lib/vagrant-azure/action/message_will_not_destroy.rb +19 -0
- data/lib/vagrant-azure/action/read_ssh_info.rb +13 -33
- data/lib/vagrant-azure/action/read_state.rb +28 -26
- data/lib/vagrant-azure/action/restart_vm.rb +11 -11
- data/lib/vagrant-azure/action/run_instance.rb +164 -80
- data/lib/vagrant-azure/action/start_instance.rb +34 -15
- data/lib/vagrant-azure/action/stop_instance.rb +36 -21
- data/lib/vagrant-azure/action/terminate_instance.rb +18 -14
- data/lib/vagrant-azure/action/wait_for_state.rb +17 -23
- data/lib/vagrant-azure/action.rb +49 -124
- data/lib/vagrant-azure/config.rb +107 -111
- data/lib/vagrant-azure/errors.rb +9 -11
- data/lib/vagrant-azure/plugin.rb +8 -32
- data/lib/vagrant-azure/provider.rb +7 -29
- data/lib/vagrant-azure/services/azure_resource_manager.rb +80 -0
- data/lib/vagrant-azure/util/machine_id_helper.rb +20 -0
- data/lib/vagrant-azure/util/timer.rb +15 -0
- data/lib/vagrant-azure/util/vm_await.rb +36 -0
- data/lib/vagrant-azure/util/vm_status_translator.rb +59 -0
- data/lib/vagrant-azure/version.rb +5 -7
- data/lib/vagrant-azure.rb +4 -9
- data/locales/en.yml +74 -3
- data/spec/spec_helper.rb +40 -0
- data/spec/vagrant-azure/config_spec.rb +18 -0
- data/spec/vagrant-azure/services/azure_resource_manager_spec.rb +19 -0
- data/templates/arm/deployment.json.erb +264 -0
- data/vagrant-azure.gemspec +19 -14
- metadata +96 -51
- data/lib/vagrant-azure/action/os_type.rb +0 -34
- data/lib/vagrant-azure/action/powershell_run.rb +0 -28
- data/lib/vagrant-azure/action/rdp.rb +0 -63
- data/lib/vagrant-azure/action/read_winrm_info.rb +0 -57
- data/lib/vagrant-azure/action/sync_folders.rb +0 -64
- data/lib/vagrant-azure/action/vagrant_azure_service.rb +0 -44
- data/lib/vagrant-azure/capabilities/winrm.rb +0 -12
- data/lib/vagrant-azure/command/powershell.rb +0 -43
- data/lib/vagrant-azure/command/rdp.rb +0 -24
- data/lib/vagrant-azure/driver.rb +0 -48
- data/lib/vagrant-azure/monkey_patch/winrm.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5597d47adf91f7395f8b3bec4ab45ca51218f47
|
4
|
+
data.tar.gz: cb149fbf31e95c1657581e0e213e31bf65c2a63f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1429363e9a70658d9960c7ba9689e8be3fea33ae6a5d4d21731c31d84af5f8d278f7617be87ebab4cd40ec1502a7db32d120dc9b40de32fd766d92bd30376d1b
|
7
|
+
data.tar.gz: 7d32bd43eed9cedd13938d10f4fe0665330cf03b3698cadbda007c9e0e615f9953d3a1e15bb67b7250f51baa53aae464b4f8a6c3939a01b174e9983e2bd922ab
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) Microsoft
|
3
|
-
#
|
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
|
source 'https://rubygems.org'
|
8
6
|
|
@@ -12,7 +10,8 @@ group :development do
|
|
12
10
|
# We depend on Vagrant for development, but we don't add it as a
|
13
11
|
# gem dependency because we expect to be installed within the
|
14
12
|
# Vagrant environment itself using `vagrant plugin`.
|
15
|
-
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.7.
|
13
|
+
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.7.4'
|
14
|
+
gem 'dotenv'
|
16
15
|
end
|
17
16
|
|
18
17
|
group :plugins do
|
data/LICENSE
CHANGED
@@ -1,4 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Microsoft
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Install Vagrant 1.7.3 or higher - [Download Vagrant](http://www.vagrantup.com/do
|
|
12
12
|
Install the vagrant-azure plugin using the standard Vagrant 1.1+ installation methods. After installing the plugin, you can ```vagrant up``` and use ```azure``` provider. For example:
|
13
13
|
|
14
14
|
```
|
15
|
-
C:\> vagrant plugin install vagrant-azure
|
15
|
+
C:\> vagrant plugin install vagrant-azure 2.0.0.pre1
|
16
16
|
...
|
17
17
|
C:\> vagrant up --provider=azure
|
18
18
|
...
|
@@ -25,7 +25,7 @@ You'll need an ```azure``` box before you can do ```vagrant up``` though.
|
|
25
25
|
You can use the dummy box and specify all the required details manually in the ```config.vm.provider``` block in your ```Vagrantfile```. Add the dummy box with the name you want:
|
26
26
|
|
27
27
|
```
|
28
|
-
C:\> vagrant box add azure https://github.com/
|
28
|
+
C:\> vagrant box add azure https://github.com/azure/vagrant-azure/raw/v2.0/dummy.box
|
29
29
|
...
|
30
30
|
```
|
31
31
|
|
@@ -33,37 +33,22 @@ Now edit your ```Vagrantfile``` as shown below and provide all the values as exp
|
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
Vagrant.configure('2') do |config|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
azure.vm_user = 'PROVIDE A USERNAME' # defaults to 'vagrant' if not provided
|
53
|
-
azure.cloud_service_name = 'PROVIDE A NAME FOR YOUR CLOUD SERVICE' # same as vm_name. leave blank to auto-generate
|
54
|
-
azure.deployment_name = 'PROVIDE A NAME FOR YOUR DEPLOYMENT' # defaults to cloud_service_name
|
55
|
-
azure.vm_location = 'PROVIDE A LOCATION FOR VM' # e.g., West US
|
56
|
-
|
57
|
-
# Optional *Nix Settings
|
58
|
-
azure.ssh_port = 'A VALID PUBLIC PORT' # defaults to 22
|
59
|
-
azure.private_key_file = 'Path to your ssh private key file (~/.ssh/id_rsa) to use for passwordless auth. If the id_rsa file is password protected, you will be prompted for the password.'
|
60
|
-
|
61
|
-
# Optional Windows Settings
|
62
|
-
azure.winrm_transport = [ 'http', 'https' ] # this will open up winrm ports on both http (5985) and http (5986) ports
|
63
|
-
azure.winrm_https_port = 'A VALID PUBLIC PORT' # customize the winrm https port, instead of 5986
|
64
|
-
azure.winrm_http_port = 'A VALID PUBLIC PORT' # customize the winrm http port, insted of 5985
|
65
|
-
azure.tcp_endpoints = '3389:53389' # opens the Remote Desktop internal port that listens on public port 53389. Without this, you cannot RDP to a Windows VM.
|
66
|
-
end
|
36
|
+
config.vm.box = 'azure'
|
37
|
+
|
38
|
+
# use local ssh key to connect to remote vagrant box
|
39
|
+
config.ssh.private_key_path = '~/.ssh/id_rsa'
|
40
|
+
config.vm.provider :azure do |azure, override|
|
41
|
+
|
42
|
+
# use Azure Active Directory Application / Service Principal to connect to Azure
|
43
|
+
# see: https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/
|
44
|
+
|
45
|
+
# each of the below values will default to use the env vars named as below if not specified explicitly
|
46
|
+
azure.tenant_id = ENV['AZURE_TENANT_ID']
|
47
|
+
azure.client_id = ENV['AZURE_CLIENT_ID']
|
48
|
+
azure.client_secret = ENV['AZURE_CLIENT_SECRET']
|
49
|
+
azure.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
|
50
|
+
end
|
51
|
+
|
67
52
|
end
|
68
53
|
```
|
69
54
|
|
@@ -77,11 +62,11 @@ This will bring up an Azure VM as per the configuration options set above.
|
|
77
62
|
|
78
63
|
You can now either SSH (if its a *Nix VM) using ```vagrant ssh```, RDP (if its a Windows VM) using ```vagrant rdp``` or PowerShell ```vagrant powershell```.
|
79
64
|
|
80
|
-
Normally, a lot of this options, e.g., ```
|
65
|
+
Normally, a lot of this options, e.g., ```vm_image_urn```, will be embedded in a box file and you just have to provide minimal options in the ```Vagrantfile```. Since, we're using a dummy box, there are no pre-configured defaults.
|
81
66
|
|
82
67
|
## Azure Boxes
|
83
68
|
|
84
|
-
The vagrant-azure plugin provides the ability to use ```Azure``` boxes with Vagrant. Please see the example box provided in [example_box/ directory](https://github.com/
|
69
|
+
The vagrant-azure plugin provides the ability to use ```Azure``` boxes with Vagrant. Please see the example box provided in [example_box/ directory](https://github.com/azure/vagrant-azure/tree/v2.0/example_box) and follow the instructions there to build an ```azure``` box.
|
85
70
|
|
86
71
|
Please see [Vagrant Docs](http://docs.vagrantup.com/v2/) for more details.
|
87
72
|
|
@@ -91,148 +76,21 @@ The vagrant-azure provide exposes a few Azure specific configuration options:
|
|
91
76
|
|
92
77
|
### Mandatory
|
93
78
|
|
94
|
-
|
95
|
-
* `
|
96
|
-
* `
|
97
|
-
* `
|
98
|
-
* `
|
79
|
+
For instructions on how to setup an Azure Active Directory Application see: https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/
|
80
|
+
* `tenant_id`: Your Azure Active Directory Tenant Id.
|
81
|
+
* `client_id`: Your Azure Active Directory application client id.
|
82
|
+
* `client_secret`: Your Azure Active Directory application client secret.
|
83
|
+
* `subscription_id`: The Azure subscription Id you'd like to use.
|
99
84
|
|
100
85
|
### Optional
|
101
|
-
|
102
|
-
* `
|
103
|
-
* `
|
104
|
-
* `
|
105
|
-
* `vm_size
|
106
|
-
* `
|
107
|
-
* `
|
108
|
-
* `
|
109
|
-
* `
|
110
|
-
* `
|
111
|
-
* `
|
112
|
-
* `winrm_transport` - Enables or disables WinRm. Allowed values are `http` and `https`.
|
113
|
-
* `winrm_https_port` To map the internal WinRM https port 5986 to a different public port. Must be non-empty.
|
114
|
-
* `winrm_http_port` To map the internal WinRM http port 5985 to a different public port. Must be non-empty.
|
115
|
-
* `tcp_endpoints` - To open any additional ports. E.g., `80` opens port `80` and `80,3389:53389` opens port `80` and `3389`. Also maps the interal port `3389` to public port `53389`
|
116
|
-
|
117
|
-
### Certificate Generation on Windows
|
118
|
-
We will use `makecert.exe` distributed as part of the in the Windows 7 SDK. The following commands will create the required certificate and insert it into the current user’s personal store.
|
119
|
-
|
120
|
-
```
|
121
|
-
makecert.exe -r -pe -a sha1 -n "CN=AzCert" -ss My -sr CurrentUser -len 2048 -sky exchange -sp "Microsoft Enhanced RSA and AES Cryptographic Provider" -sy 24
|
122
|
-
```
|
123
|
-
|
124
|
-
(In order to have more details with images in Windows)[http://blogs.msdn.com/b/cclayton/archive/2012/03/21/windows-azure-and-x509-certificates.aspx]
|
125
|
-
|
126
|
-
### Get Started with Publish Settings
|
127
|
-
|
128
|
-
To create a pfx from the publishsettings, simply download the publishsettings file for your subscription
|
129
|
-
[https://manage.windowsazure.com/publishsettings](https://manage.windowsazure.com/publishsettings/index?client=powershell). Make sure you have the [Ruby Azure](https://rubygems.org/gems/azure/versions/0.7.0) gem installed and run `pfxer --in [path to your .publishsettings file]`. This will create a .pfx from your publish settings file which can be supplied as a cert parameter for Service Management Commands.
|
130
|
-
|
131
|
-
### Get Started with OpenSSL
|
132
|
-
|
133
|
-
* Using the following openssl commands to create a cert and upload to Azure Management
|
134
|
-
* Generate public and private `openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout cert.pem -out cert.pem`
|
135
|
-
* Generate public .cer for Azure upload `openssl x509 -inform pem -in cert.pem -outform der -out mgmt.cer`
|
136
|
-
* Upload the `mgmt.cer` to Azure Management through [https://management.azure.com](https://management.azure.com)
|
137
|
-
* Use cert.pem as your cert parameter for Service Management Commands.
|
138
|
-
|
139
|
-
### Using your .pem certificate
|
140
|
-
|
141
|
-
Vagrant-Azure expects you to use a .pem management certificate as shown below:
|
142
|
-
|
143
|
-
```ruby
|
144
|
-
Vagrant.configure('2') do |config|
|
145
|
-
config.vm.box = 'azure'
|
146
|
-
|
147
|
-
config.vm.provider :azure do |azure|
|
148
|
-
azure.mgmt_certificate = "#{file_location_of_your_dot_pem}"
|
149
|
-
```
|
150
|
-
|
151
|
-
## Create Virtual Network
|
152
|
-
|
153
|
-
In order to use vagrant-azure's `vm_virtual_network_name` support, create virtual networks using
|
154
|
-
[Azure's Command Line Interface](http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-command-line-tools/):
|
155
|
-
|
156
|
-
azure account download
|
157
|
-
azure network vnet create --vnet "vnet-name" --location "West US" --create-new-affinity-group
|
158
|
-
|
159
|
-
|
160
|
-
## New Commands for `azure` provider
|
161
|
-
|
162
|
-
The `azure` provider introduces the following new `vagrant` commands.
|
163
|
-
|
164
|
-
* `rdp` - To connect to a Windows VM using RDP. E.g.,
|
165
|
-
* `powershell` - To execute remote powershell commands on a Windows VM using WinRM.
|
166
|
-
```
|
167
|
-
> vagrant up --provider=azure
|
168
|
-
...
|
169
|
-
> vagrant rdp
|
170
|
-
...
|
171
|
-
> vagrant powershell
|
172
|
-
```
|
173
|
-
|
174
|
-
|
175
|
-
## Multi Machine
|
176
|
-
The options for multi machines are similar to Vagrant, please refer to the vagrant doc at http://docs.vagrantup.com/v2/multi-machine/index.html
|
177
|
-
|
178
|
-
Example Multi Machine Vagrantfile (for building out 3 Windows Virtual Machines)
|
179
|
-
|
180
|
-
```ruby
|
181
|
-
|
182
|
-
Vagrant.configure('2') do |config|
|
183
|
-
config.vm.boot_timeout = 1000
|
184
|
-
|
185
|
-
do_common_azure_stuff = Proc.new do |azure, override|
|
186
|
-
override.config.vm.box = 'azure'
|
187
|
-
|
188
|
-
azure.mgmt_certificate = 'YOUR AZURE MANAGEMENT CERTIFICATE'
|
189
|
-
azure.mgmt_endpoint = 'https://management.core.windows.net'
|
190
|
-
azure.subscription_id = 'YOUR AZURE SUBSCRIPTION ID'
|
191
|
-
azure.storage_acct_name = 'NAME OF YOUR STORAGE ACCOUNT' # optional. A new one will be generated if not provided.
|
192
|
-
|
193
|
-
azure.vm_image = 'NAME OF THE IMAGE TO USE'
|
194
|
-
azure.vm_user = 'PROVIDE A USERNAME' # defaults to 'vagrant' if not provided
|
195
|
-
azure.vm_password = 'PROVIDE A VALID PASSWORD' # min 8 characters. should contain a lower case letter, an uppercase letter, a number and a special character
|
196
|
-
|
197
|
-
azure.vm_name = 'PROVIDE A NAME FOR YOUR VIRTUAL MACHINE' # max 15 characters. contains letters, number and hyphens. can start with letters and can end with letters and numbers
|
198
|
-
azure.cloud_service_name = 'PROVIDE A NAME FOR YOUR CLOUD SERVICE' # same as vm_name. leave blank to auto-generate
|
199
|
-
azure.deployment_name = 'PROVIDE A NAME FOR YOUR DEPLOYMENT' # defaults to cloud_service_name
|
200
|
-
azure.vm_location = 'PROVIDE A LOCATION FOR VM' # e.g., West US
|
201
|
-
|
202
|
-
azure.winrm_transport = %w(https)
|
203
|
-
end
|
204
|
-
|
205
|
-
config.vm.define 'first' do |cfg|
|
206
|
-
cfg.vm.provider :azure do |azure, override|
|
207
|
-
do_common_azure_stuff.call azure, override
|
208
|
-
azure.vm_name = 'PROVIDE A NAME FOR YOUR VIRTUAL MACHINE'
|
209
|
-
azure.tcp_endpoints = '3389:53389' # opens the Remote Desktop internal port that listens on public port 53389. Without this, you cannot RDP to a Windows VM.
|
210
|
-
azure.winrm_https_port = 5986
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
config.vm.define 'second' do |cfg|
|
215
|
-
cfg.vm.provider :azure do |azure, override|
|
216
|
-
do_common_azure_stuff.call azure, override
|
217
|
-
azure.vm_name = 'PROVIDE A NAME FOR YOUR VIRTUAL MACHINE'
|
218
|
-
azure.tcp_endpoints = '3389:53390'
|
219
|
-
azure.winrm_https_port = 5987
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
config.vm.define 'third' do |cfg|
|
224
|
-
cfg.vm.provider :azure do |azure, override|
|
225
|
-
do_common_azure_stuff.call azure, override
|
226
|
-
azure.vm_name = 'PROVIDE A NAME FOR YOUR VIRTUAL MACHINE'
|
227
|
-
azure.tcp_endpoints = '3389:53391'
|
228
|
-
azure.winrm_https_port = 5988
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
# Executes powershell on the remote machine and returns the hostname
|
233
|
-
config.vm.provision 'shell', inline: 'hostname'
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
```
|
238
|
-
|
86
|
+
* `resource_group_name`: (Optional) Name of the resource group to use.
|
87
|
+
* `location`: (Optional) Azure location to build the VM -- defaults to 'westus'
|
88
|
+
* `vm_name`: (Optional) Name of the virtual machine
|
89
|
+
* `vm_password`: (Optional for *nix) Password for the VM -- This is not recommended for *nix deployments
|
90
|
+
* `vm_size`: (Optional) VM size to be used -- defaults to 'Standard_D1'. See: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/
|
91
|
+
* `vm_image_urn`: (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/
|
92
|
+
* `virtual_network_name`: (Optional) Name of the virtual network resource
|
93
|
+
* `subnet_name`: (Optional) Name of the virtual network subnet resource
|
94
|
+
* `instance_ready_timeout`: (Optional) The timeout to wait for an instance to become ready -- default 120 seconds.
|
95
|
+
* `instance_check_interval`: (Optional) The interval to wait for checking an instance's state -- default 2 seconds.
|
96
|
+
* `endpoint`: (Optional) The Azure Management API endpoint -- default 'https://management.azure.com' seconds -- ENV['AZURE_MANAGEMENT_ENDPOINT'].
|
data/Rakefile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) Microsoft
|
3
|
-
#
|
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
|
require 'rubygems'
|
8
6
|
require 'bundler/setup'
|
data/example_box/Vagrantfile
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
# -*- mode: ruby -*-
|
2
2
|
# vi: set ft=ruby :
|
3
3
|
|
4
|
-
#
|
5
|
-
|
4
|
+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
5
|
+
# configures the configuration version (we support older styles for
|
6
|
+
# backwards compatibility). Please don't change it unless you know what
|
7
|
+
# you're doing.
|
6
8
|
|
7
|
-
Vagrant.configure(
|
8
|
-
|
9
|
-
# options are documented and commented below. For a complete reference,
|
10
|
-
# please see the online documentation at vagrantup.com.
|
9
|
+
Vagrant.configure('2') do |config|
|
10
|
+
config.vm.box = 'azure'
|
11
11
|
|
12
|
-
config.vm.provider :azure do |azure|
|
13
|
-
azure.vm_size = 'Small'
|
12
|
+
config.vm.provider :azure do |azure, override|
|
14
13
|
end
|
15
14
|
end
|
@@ -1,44 +1,23 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) Microsoft
|
3
|
-
#
|
4
|
-
|
5
|
-
#--------------------------------------------------------------------------
|
6
|
-
require 'azure'
|
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.
|
4
|
+
require_relative '../services/azure_resource_manager'
|
7
5
|
require 'log4r'
|
8
6
|
|
9
|
-
# FIXME:
|
10
|
-
# This is a required to patch few exception handling which are not done in
|
11
|
-
# Azure Ruby SDK
|
12
|
-
require_relative "vagrant_azure_service"
|
13
|
-
|
14
7
|
module VagrantPlugins
|
15
|
-
module
|
8
|
+
module Azure
|
16
9
|
module Action
|
17
10
|
class ConnectAzure
|
18
11
|
def initialize(app, env)
|
19
12
|
@app = app
|
20
|
-
@logger = Log4r::Logger.new('vagrant_azure::action::
|
13
|
+
@logger = Log4r::Logger.new('vagrant_azure::action::connect_azure')
|
21
14
|
end
|
22
15
|
|
23
16
|
def call (env)
|
24
|
-
if env[:
|
17
|
+
if env[:azure_arm_service].nil?
|
25
18
|
config = env[:machine].provider_config
|
26
|
-
|
27
|
-
Azure.
|
28
|
-
c.subscription_id = config.subscription_id
|
29
|
-
c.management_certificate = config.mgmt_certificate
|
30
|
-
c.management_endpoint = config.mgmt_endpoint
|
31
|
-
c.storage_account_name = config.storage_acct_name
|
32
|
-
c.storage_access_key = config.storage_access_key
|
33
|
-
end
|
34
|
-
|
35
|
-
# FIXME:
|
36
|
-
# Defining a new class VagrantAzureService
|
37
|
-
# Here we call the native azure virtual machine management service method
|
38
|
-
# and add some exception handling.
|
39
|
-
# Remove this once the Azure SDK adds the exception handling for the
|
40
|
-
# methods defined in VagrantAzureService
|
41
|
-
env[:azure_vm_service] = VagrantAzureService.new(Azure::VirtualMachineManagementService.new)
|
19
|
+
provider = MsRestAzure::ApplicationTokenProvider.new(config.tenant_id, config.client_id, config.client_secret)
|
20
|
+
env[:azure_arm_service] = VagrantPlugins::Azure::Services::AzureResourceManager.new(provider, config.subscription_id)
|
42
21
|
end
|
43
22
|
|
44
23
|
@app.call(env)
|
@@ -0,0 +1,19 @@
|
|
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.
|
4
|
+
module VagrantPlugins
|
5
|
+
module Azure
|
6
|
+
module Action
|
7
|
+
class IsCreated
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:result] = env[:machine].state.id != :not_created
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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.
|
4
|
+
module VagrantPlugins
|
5
|
+
module Azure
|
6
|
+
module Action
|
7
|
+
class IsStopped
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:result] = env[:machine].state.id == :stopped
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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.
|
4
|
+
module VagrantPlugins
|
5
|
+
module Azure
|
6
|
+
module Action
|
7
|
+
class MessageAlreadyCreated
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:ui].info(I18n.t('vagrant_azure.already_status', :status => 'created'))
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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.
|
4
|
+
module VagrantPlugins
|
5
|
+
module Azure
|
6
|
+
module Action
|
7
|
+
class MessageNotCreated
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:ui].info(I18n.t('vagrant_azure.not_created'))
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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.
|
4
|
+
module VagrantPlugins
|
5
|
+
module Azure
|
6
|
+
module Action
|
7
|
+
class MessageWillNotDestroy
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:ui].info(I18n.t('vagrant_azure.will_not_destroy', name: env[:machine].name))
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) Microsoft
|
3
|
-
#
|
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'
|
5
|
+
require 'vagrant-azure/util/machine_id_helper'
|
7
6
|
|
8
7
|
module VagrantPlugins
|
9
|
-
module
|
8
|
+
module Azure
|
10
9
|
module Action
|
11
10
|
class ReadSSHInfo
|
11
|
+
include VagrantPlugins::Azure::Util::MachineIdHelper
|
12
|
+
|
12
13
|
def initialize(app, env, port = 22)
|
13
14
|
@app = app
|
14
15
|
@port = port
|
@@ -16,37 +17,16 @@ module VagrantPlugins
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def call(env)
|
19
|
-
env[:
|
20
|
-
|
21
|
-
env[:machine_ssh_info] = read_ssh_info(
|
22
|
-
env[:azure_vm_service],
|
23
|
-
env[:machine]
|
24
|
-
)
|
25
|
-
|
26
|
-
env[:ui].detail "Found port mapping #{env[:machine_ssh_info][:port]} --> #{@port}"
|
27
|
-
|
20
|
+
env[:machine_ssh_info] = read_ssh_info(env[:azure_arm_service], env)
|
28
21
|
@app.call(env)
|
29
22
|
end
|
30
23
|
|
31
|
-
def read_ssh_info(azure,
|
32
|
-
return nil if machine.id.nil?
|
33
|
-
machine.id
|
34
|
-
|
35
|
-
|
36
|
-
if vm.nil? || !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine)
|
37
|
-
# Machine cannot be found
|
38
|
-
@logger.info 'Machine not found. Assuming it was destroyed'
|
39
|
-
machine.id = nil
|
40
|
-
return nil
|
41
|
-
end
|
42
|
-
|
43
|
-
vm.tcp_endpoints.each do |endpoint|
|
44
|
-
if endpoint[:local_port] == "#{@port}"
|
45
|
-
return { :host => "#{vm.cloud_service_name}.cloudapp.net", :port => endpoint[:public_port] }
|
46
|
-
end
|
47
|
-
end
|
24
|
+
def read_ssh_info(azure, env)
|
25
|
+
return nil if env[:machine].id.nil?
|
26
|
+
parsed = parse_machine_id(env[:machine].id)
|
27
|
+
public_ip = azure.network.public_ipaddresses.get(parsed[:group], "#{parsed[:name]}-vagrantPublicIP").value!.body
|
48
28
|
|
49
|
-
|
29
|
+
{:host => public_ip.properties.dns_settings.fqdn, :port => 22}
|
50
30
|
end
|
51
31
|
end
|
52
32
|
end
|