зеркало из https://github.com/Azure/vagrant-azure.git
build machine from managed image works
This commit is contained in:
Родитель
627e6f3e40
Коммит
9154ae1884
|
@ -2,7 +2,7 @@ id
|
|||
.DS_Store
|
||||
Gemfile.lock
|
||||
azure.box
|
||||
Vagrantfile
|
||||
/Vagrantfile
|
||||
!example_box/Vagrantfile
|
||||
!example_box/README.md
|
||||
babu
|
||||
|
|
46
README.md
46
README.md
|
@ -121,20 +121,30 @@ Please see [Vagrant Docs](http://docs.vagrantup.com/v2/) for more details.
|
|||
|
||||
The vagrant-azure provide exposes Azure specific configuration options:
|
||||
|
||||
### Mandatory
|
||||
### Mandatory Parameters
|
||||
* `tenant_id`: Your Azure Active Directory Tenant Id.
|
||||
* `client_id`: Your Azure Active Directory application client id.
|
||||
* `client_secret`: Your Azure Active Directory application client secret.
|
||||
* `subscription_id`: The Azure subscription Id you'd like to use.
|
||||
*Note: to procure these values see: [Create an Azure Active Directory Application](#create-an-azure-active-directory-aad-application)*
|
||||
|
||||
### Optional Image Parameters
|
||||
* `vm_image_urn`: (Optional) Name of the virtual machine image urn to use -- defaults to 'canonical:ubuntuserver:16.04-LTS:latest'. See documentation for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/), [Windows](https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-cli-ps-findimage).
|
||||
* `vm_custom_image`: (Optional) URI to the custom VHD. If the VHD is not publicly accessible, provide a SAS token in the URI.
|
||||
* `vm_operating_system`: (Mandatory) Must provide the OS if using a custom image ("Linux" or "Windows")
|
||||
### Optional VM Parameters
|
||||
* `vm_name`: Name of the virtual machine
|
||||
* `vm_password`: (Optional for *nix) Password for the VM -- This is not recommended for *nix deployments
|
||||
* `vm_size`: VM size to be used -- defaults to 'Standard_DS2_v2'. See sizes for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/), [Windows](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-sizes/).
|
||||
* `admin_username`: The root/administrator username for the VM
|
||||
|
||||
### Optional Data Disk Parameters
|
||||
* `data_disks`: (Optional) Array of Data Disks to attach to the VM. For information on attaching the drive, see: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/attach-disk.
|
||||
### Optional VM Image Parameters
|
||||
`vm_image_urn`, `vm_vhd_uri`, and `vm_managed_image_id` are mutually exclusive. They should not be used in combination.
|
||||
* `vm_image_urn`: Name of the virtual machine image urn to use -- defaults to 'canonical:ubuntuserver:16.04-LTS:latest'. See documentation for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/), [Windows](https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-cli-ps-findimage).
|
||||
* `vm_vhd_uri`: URI to the custom VHD. If the VHD is not publicly accessible, provide a SAS token in the URI.
|
||||
* `vm_operating_system`: (Mandatory) Must provide the OS if using a custom image ("Linux" or "Windows")
|
||||
* `vm_vhd_storage_account_id`: (Manditory) The Storage Account Azure Resource Manager Id where the OS Image is stored
|
||||
(like: /subscriptions/{subscription id}/resourceGroups/{resource group}/providers/Microsoft.Storage/storageAccounts/{account name}).
|
||||
* `vm_managed_image_id`: Create a VM from a generalized VM that is stored as either a managed or unmanaged disk. See: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource
|
||||
|
||||
### Optional VM Data Disk Parameters
|
||||
* `data_disks`: (Optional) Array of Data Disks to attach to the VM. For information on attaching the drive, See: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/attach-disk.
|
||||
```ruby
|
||||
override.data_disks = [
|
||||
# sample of creating empty data disk
|
||||
|
@ -155,13 +165,7 @@ override.data_disks = [
|
|||
}]
|
||||
```
|
||||
|
||||
### Optional
|
||||
|
||||
* `resource_group_name`: (Optional) Name of the resource group to use.
|
||||
* `location`: (Optional) Azure location to build the VM -- defaults to `westus`
|
||||
* `vm_name`: (Optional) Name of the virtual machine
|
||||
* `vm_password`: (Optional for *nix) Password for the VM -- This is not recommended for *nix deployments
|
||||
* `vm_size`: (Optional) VM size to be used -- defaults to 'Standard_DS2_v2'. See sizes for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/), [Windows](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-sizes/).
|
||||
### Optional Networking Parameters
|
||||
* `virtual_network_name`: (Optional) Name of the virtual network resource
|
||||
* `dns_name`: (Optional) DNS Label Prefix
|
||||
* `nsg_name`: (Optional) Network Security Group Label Prefix
|
||||
|
@ -170,9 +174,17 @@ override.data_disks = [
|
|||
* an array `['8000-9000', '9100-9200']`,
|
||||
* a single interval as `'8000-9000'`,
|
||||
* a single port as `8000`.
|
||||
|
||||
### Optional Windows Parameters
|
||||
* `winrm_install_self_signed_cert`: (Optional, Windows only) Whether to install a self-signed cert automatically to enable WinRM to communicate over HTTPS (5986). Only available when a custom `deployment_template` is not supplied. Default 'true'.
|
||||
|
||||
### Optional Provisioning Parameters
|
||||
* `instance_ready_timeout`: (Optional) The timeout to wait for an instance to become ready -- default 120 seconds.
|
||||
* `instance_check_interval`: (Optional) The interval to wait for checking an instance's state -- default 2 seconds.
|
||||
* `endpoint`: (Optional) The Azure Management API endpoint -- default `ENV['AZURE_MANAGEMENT_ENDPOINT']` if exists, falls back to <https://management.azure.com>.
|
||||
* `admin_username`: (Optional) The root/administrator username for the VM
|
||||
* `winrm_install_self_signed_cert`: (Optional, Windows only) Whether to install a self-signed cert automatically to enable WinRM to communicate over HTTPS (5986). Only available when a custom `deployment_template` is not supplied. Default 'true'.
|
||||
* `wait_for_destroy`: (Optional) Wait for all resources to be deleted prior to completing Vagrant destroy -- default false.
|
||||
|
||||
### Optional Azure Parameters
|
||||
* `endpoint`: (Optional) The Azure Management API endpoint -- default `ENV['AZURE_MANAGEMENT_ENDPOINT']` if exists, falls back to <https://management.azure.com>.
|
||||
* `resource_group_name`: (Optional) Name of the resource group to use.
|
||||
* `location`: (Optional) Azure location to build the VM -- defaults to `westus`
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "azure"
|
||||
|
||||
# use local ssh key to connect to remote vagrant box
|
||||
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
||||
config.vm.provider :azure do |azure, override|
|
||||
# each of the below values will default to use the env vars named as below if not specified explicitly
|
||||
azure.tenant_id = ENV["AZURE_TENANT_ID"]
|
||||
azure.client_id = ENV["AZURE_CLIENT_ID"]
|
||||
azure.client_secret = ENV["AZURE_CLIENT_SECRET"]
|
||||
azure.subscription_id = ENV["AZURE_SUBSCRIPTION_ID"]
|
||||
azure.location = "westus"
|
||||
end
|
||||
|
||||
config.vm.provision "shell", inline: "echo Hello, World"
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "azure"
|
||||
config.vm.provider :azure do |azure, override|
|
||||
|
||||
# each of the below values will default to use the env vars named as below if not specified explicitly
|
||||
azure.tenant_id = ENV["AZURE_TENANT_ID"]
|
||||
azure.client_id = ENV["AZURE_CLIENT_ID"]
|
||||
azure.client_secret = ENV["AZURE_CLIENT_SECRET"]
|
||||
azure.subscription_id = ENV["AZURE_SUBSCRIPTION_ID"]
|
||||
|
||||
azure.vm_image_urn = "MicrosoftSQLServer:SQL2016-WS2012R2:Express:latest"
|
||||
azure.instance_ready_timeout = 600
|
||||
azure.vm_password = "TopSecretPassw0rd"
|
||||
azure.admin_username = "OctoAdmin"
|
||||
override.winrm.transport = :ssl
|
||||
override.winrm.port = 5986
|
||||
override.winrm.ssl_peer_verification = false # must be false if using a self signed cert
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "azure"
|
||||
|
||||
# use local ssh key to connect to remote vagrant box
|
||||
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
||||
config.vm.provider :azure do |azure, override|
|
||||
azure.location = "westus"
|
||||
|
||||
azure.vm_vhd_uri = "https://vagrantimages.blob.core.windows.net/vhds/sample.vhd"
|
||||
azure.vm_operating_system = "Linux"
|
||||
end
|
||||
|
||||
config.vm.provision "shell", inline: "echo Hello, World"
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "azure"
|
||||
|
||||
# use local ssh key to connect to remote vagrant box
|
||||
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
||||
config.vm.provider :azure do |azure, override|
|
||||
azure.location = "westus"
|
||||
|
||||
azure.data_disks = [
|
||||
{ name: "foo", size_gb: 30 }
|
||||
]
|
||||
end
|
||||
|
||||
config.vm.provision "shell", inline: "echo Hello, World"
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "azure"
|
||||
|
||||
# use local ssh key to connect to remote vagrant box
|
||||
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
||||
config.vm.provider :azure do |azure, override|
|
||||
azure.location = "westus"
|
||||
|
||||
azure.vm_managed_image_id = "https://vagrantimages.blob.core.windows.net/vhds/sample.vhd"
|
||||
end
|
||||
|
||||
config.vm.provision "shell", inline: "echo Hello, World"
|
||||
end
|
|
@ -0,0 +1,23 @@
|
|||
# Vagrant Azure Scenario Docs
|
||||
Here you can find some common scenarios for using Azure plugin for Vagrant.
|
||||
|
||||
## Prerequisites
|
||||
- Install Vagrant
|
||||
- Install the Azure Plugin
|
||||
|
||||
## Scenarios
|
||||
|
||||
### [Basic Linux Setup](./basic_linux)
|
||||
Setup a simple Ubuntu box
|
||||
|
||||
### [Basic Windows Setup](./basic_windows)
|
||||
Setup a Windows Server box
|
||||
|
||||
### [Custom OS Image (VHD)](./custom_vhd)
|
||||
Setup an Ubuntu box from a custom image
|
||||
|
||||
### [Managed Image Reference](./managed_image_reference)
|
||||
Setup a VM from a managed image reference captured from a previously created Azure VM.
|
||||
|
||||
### [Data Disks (empty disk)](./data_disks)
|
||||
Setup an Ubuntu box with an empty attached disk
|
|
@ -6,6 +6,7 @@ require "json"
|
|||
require "azure_mgmt_resources"
|
||||
require "vagrant-azure/util/machine_id_helper"
|
||||
require "vagrant-azure/util/template_renderer"
|
||||
require "vagrant-azure/util/managed_image_helper"
|
||||
require "vagrant-azure/util/timer"
|
||||
require "haikunator"
|
||||
|
||||
|
@ -15,6 +16,7 @@ module VagrantPlugins
|
|||
class RunInstance
|
||||
include Vagrant::Util::Retryable
|
||||
include VagrantPlugins::Azure::Util::MachineIdHelper
|
||||
include VagrantPlugins::Azure::Util::ManagedImagedHelper
|
||||
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
|
@ -40,8 +42,10 @@ module VagrantPlugins
|
|||
vm_name = config.vm_name
|
||||
vm_size = config.vm_size
|
||||
vm_image_urn = config.vm_image_urn
|
||||
vm_custom_image = config.vm_custom_image
|
||||
vm_vhd_uri = config.vm_vhd_uri
|
||||
vm_vhd_stor_acct_id = config.vm_vhd_storage_account_id
|
||||
vm_operating_system = config.vm_operating_system
|
||||
vm_managed_image_id = config.vm_managed_image_id
|
||||
virtual_network_name = config.virtual_network_name
|
||||
subnet_name = config.subnet_name
|
||||
tcp_endpoints = config.tcp_endpoints
|
||||
|
@ -63,7 +67,17 @@ module VagrantPlugins
|
|||
env[:ui].info(" -- Admin Username: #{admin_user_name}") if admin_user_name
|
||||
env[:ui].info(" -- VM Name: #{vm_name}")
|
||||
env[:ui].info(" -- VM Size: #{vm_size}")
|
||||
env[:ui].info(" -- Image URN: #{vm_image_urn}")
|
||||
|
||||
if !vm_vhd_uri.nil?
|
||||
env[:ui].info(" -- Custom VHD URI: #{vm_vhd_uri}")
|
||||
env[:ui].info(" -- Custom OS: #{vm_operating_system}")
|
||||
env[:ui].info(" -- Custom VHD Storage Account Id: #{vm_vhd_stor_acct_id}")
|
||||
elsif !vm_managed_image_id.nil?
|
||||
env[:ui].info(" -- Managed Image Id: #{vm_managed_image_id}")
|
||||
else
|
||||
env[:ui].info(" -- Image URN: #{vm_image_urn}")
|
||||
end
|
||||
|
||||
env[:ui].info(" -- Virtual Network Name: #{virtual_network_name}") if virtual_network_name
|
||||
env[:ui].info(" -- Subnet Name: #{subnet_name}") if subnet_name
|
||||
env[:ui].info(" -- TCP Endpoints: #{tcp_endpoints}") if tcp_endpoints
|
||||
|
@ -73,10 +87,6 @@ module VagrantPlugins
|
|||
image_publisher, image_offer, image_sku, image_version = vm_image_urn.split(":")
|
||||
|
||||
azure = env[:azure_arm_service]
|
||||
image_details = nil
|
||||
env[:metrics]["get_image_details"] = Util::Timer.time do
|
||||
image_details = get_image_details(azure, location, image_publisher, image_offer, image_sku, image_version)
|
||||
end
|
||||
@logger.info("Time to fetch os image details: #{env[:metrics]["get_image_details"]}")
|
||||
|
||||
deployment_params = {
|
||||
|
@ -90,15 +100,16 @@ module VagrantPlugins
|
|||
|
||||
# we need to pass different parameters depending upon the OS
|
||||
# if custom image, then require vm_operating_system
|
||||
operating_system = if vm_custom_image
|
||||
operating_system = if vm_vhd_uri
|
||||
vm_operating_system
|
||||
elsif vm_managed_image_id
|
||||
get_managed_image_os(azure, vm_managed_image_id)
|
||||
else
|
||||
get_image_os(image_details)
|
||||
get_image_os(azure, location, image_publisher, image_offer, image_sku, image_version)
|
||||
end
|
||||
|
||||
template_params = {
|
||||
availability_set_name: availability_set_name,
|
||||
operating_system: operating_system,
|
||||
winrm_install_self_signed_cert: winrm_install_self_signed_cert,
|
||||
winrm_port: winrm_port,
|
||||
dns_label_prefix: dns_label_prefix,
|
||||
|
@ -108,7 +119,9 @@ module VagrantPlugins
|
|||
image_offer: image_offer,
|
||||
image_sku: image_sku,
|
||||
image_version: image_version,
|
||||
custom_image: vm_custom_image,
|
||||
vhd_uri: vm_vhd_uri,
|
||||
vhd_stor_acct_id: vm_vhd_stor_acct_id,
|
||||
operating_system: operating_system,
|
||||
data_disks: config.data_disks
|
||||
}
|
||||
|
||||
|
@ -209,10 +222,17 @@ module VagrantPlugins
|
|||
endpoints
|
||||
end
|
||||
|
||||
def get_image_os(image_details)
|
||||
def get_image_os(azure, location, publisher, offer, sku, version)
|
||||
image_details = get_image_details(azure, location, publisher, offer, sku, version)
|
||||
image_details.os_disk_image.operating_system
|
||||
end
|
||||
|
||||
def get_managed_image_os(azure, image_id)
|
||||
_, group, name = image_id_captures(image_id)
|
||||
image_details = azure.compute.images.get(group, name)
|
||||
image_details.storage_profile.os_disk.os_type
|
||||
end
|
||||
|
||||
def get_image_details(azure, location, publisher, offer, sku, version)
|
||||
if version == "latest"
|
||||
images = azure.compute.virtual_machine_images.list(location, publisher, offer, sku)
|
||||
|
@ -243,14 +263,14 @@ module VagrantPlugins
|
|||
def render_deployment_template(options)
|
||||
self_signed_cert_resource = nil
|
||||
if options[:operating_system] == "Windows" && options[:winrm_install_self_signed_cert]
|
||||
setup_winrm_powershell = VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/setup-winrm.ps1", options.merge({template_root: template_root}))
|
||||
setup_winrm_powershell = VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/setup-winrm.ps1", options)
|
||||
encoded_setup_winrm_powershell = setup_winrm_powershell.
|
||||
gsub("'", "', variables('singleQuote'), '").
|
||||
gsub("\r\n", "\n").
|
||||
gsub("\n", "; ")
|
||||
self_signed_cert_resource = VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/selfsignedcert.json", options.merge({template_root: template_root, setup_winrm_powershell: encoded_setup_winrm_powershell}))
|
||||
self_signed_cert_resource = VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/selfsignedcert.json", options.merge({setup_winrm_powershell: encoded_setup_winrm_powershell}))
|
||||
end
|
||||
VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/deployment.json", options.merge({ template_root: template_root, self_signed_cert_resource: self_signed_cert_resource}))
|
||||
VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/deployment.json", options.merge({self_signed_cert_resource: self_signed_cert_resource}))
|
||||
end
|
||||
|
||||
def build_deployment_params(template_params, deployment_params)
|
||||
|
@ -266,11 +286,6 @@ module VagrantPlugins
|
|||
Hash[*options.map { |k, v| [k, { value: v } ] }.flatten]
|
||||
end
|
||||
|
||||
# Used to find the base location of aws-vagrant templates
|
||||
def template_root
|
||||
Azure.source_root.join("templates")
|
||||
end
|
||||
|
||||
def terminate(env)
|
||||
destroy_env = env.dup
|
||||
destroy_env.delete(:interrupted)
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
require 'vagrant'
|
||||
require 'haikunator'
|
||||
require 'vagrant-azure/util/managed_image_helper'
|
||||
|
||||
module VagrantPlugins
|
||||
module Azure
|
||||
class Config < Vagrant.plugin('2', :config)
|
||||
include VagrantPlugins::Azure::Util::ManagedImagedHelper
|
||||
|
||||
# The Azure Active Directory Tenant ID -- ENV['AZURE_TENANT_ID']
|
||||
#
|
||||
|
@ -63,7 +65,7 @@ module VagrantPlugins
|
|||
# @return [String]
|
||||
attr_accessor :vm_size
|
||||
|
||||
# (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/
|
||||
# (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/
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :vm_image_urn
|
||||
|
@ -71,7 +73,21 @@ module VagrantPlugins
|
|||
# (Optional) Custom OS Image URI (like: http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd) -- default nil.
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :vm_custom_image
|
||||
attr_accessor :vm_vhd_uri
|
||||
|
||||
# (Optional) The Storage Account Azure Resource Manager Id where the OS Image is stored
|
||||
# (like: /subscriptions/{subscription id}/resourceGroups/{resource group}/providers/Microsoft.Storage/storageAccounts/{account name}) -- default nil.
|
||||
#
|
||||
# This is required when using a vm_vhd_uri.
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :vm_vhd_storage_account_id
|
||||
|
||||
# (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.
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :vm_managed_image_id
|
||||
|
||||
# (Optional unless using custom image) OS of the custom image
|
||||
#
|
||||
|
@ -174,8 +190,11 @@ module VagrantPlugins
|
|||
@vm_name = UNSET_VALUE
|
||||
@vm_password = UNSET_VALUE
|
||||
@vm_image_urn = UNSET_VALUE
|
||||
@vm_custom_image = UNSET_VALUE
|
||||
@vm_vhd_uri = UNSET_VALUE
|
||||
@vm_vhd_storage_account_id = 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
|
||||
|
@ -200,12 +219,17 @@ module VagrantPlugins
|
|||
@client_id = ENV['AZURE_CLIENT_ID'] if @client_id == UNSET_VALUE
|
||||
@client_secret = ENV['AZURE_CLIENT_SECRET'] if @client_secret == UNSET_VALUE
|
||||
|
||||
@vm_name = Haikunator.haikunate(100) if @vm_name == 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_custom_image = nil if @vm_custom_image == UNSET_VALUE
|
||||
@vm_vhd_uri = nil if @vm_vhd_uri == UNSET_VALUE
|
||||
@vm_vhd_storage_account_id = nil if @vm_vhd_storage_account_id == 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
|
||||
|
@ -213,7 +237,6 @@ module VagrantPlugins
|
|||
@dns_name = nil if @dns_name == UNSET_VALUE
|
||||
@nsg_name = nil if @nsg_name == UNSET_VALUE
|
||||
@tcp_endpoints = nil if @tcp_endpoints == UNSET_VALUE
|
||||
@vm_size = 'Standard_DS2_v2' if @vm_size == UNSET_VALUE
|
||||
@availability_set_name = nil if @availability_set_name == UNSET_VALUE
|
||||
|
||||
@instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
|
||||
|
@ -222,16 +245,15 @@ module VagrantPlugins
|
|||
@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
|
||||
@deployment_template = nil if @deployment_template == UNSET_VALUE
|
||||
@wait_for_destroy = false if @wait_for_destroy == UNSET_VALUE
|
||||
@data_disks = [] if @data_disks == UNSET_VALUE
|
||||
end
|
||||
|
||||
def validate(machine)
|
||||
errors = _detected_errors
|
||||
|
||||
errors << t("vagrant_azure.custom_image_os_error") if !@vm_custom_image.nil? && @vm_operating_system.nil?
|
||||
|
||||
errors << I18n.t("vagrant_azure.custom_image_os_error") if !@vm_vhd_uri.nil? && (@vm_operating_system.nil? || @vm_vhd_storage_account_id.nil?)
|
||||
errors << I18n.t("vagrant_azure.vhd_and_managed_image_error") if !@vm_vhd_uri.nil? && !@vm_managed
|
||||
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?
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
|
||||
module VagrantPlugins
|
||||
module Azure
|
||||
module Util
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
|
||||
module VagrantPlugins
|
||||
module Azure
|
||||
module Util
|
||||
module ManagedImagedHelper
|
||||
ID_REGEX = /\/subscriptions\/(.+?)\/resourceGroups\/(.+?)\/providers\/Microsoft.Compute\/images\/(.+)/i
|
||||
|
||||
def image_id_matches(image_id)
|
||||
image_id.match(ID_REGEX)
|
||||
end
|
||||
|
||||
def image_id_captures(image_id)
|
||||
image_id_matches(image_id).captures
|
||||
end
|
||||
|
||||
def valid_image_id?(image_id)
|
||||
match = image_id_matches(image_id)
|
||||
match && match.captures.count == 3 && !match.captures.any?(&:nil?)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
|
||||
require "erb"
|
||||
|
||||
module VagrantPlugins
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
|
||||
module VagrantPlugins
|
||||
module Azure
|
||||
module Util
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
|
||||
module VagrantPlugins
|
||||
module Azure
|
||||
module Util
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for license information.
|
||||
|
||||
module VagrantPlugins
|
||||
module Azure
|
||||
module Util
|
||||
|
|
|
@ -114,4 +114,9 @@ en:
|
|||
Waiting for instance to become "ready"...
|
||||
waiting_for_stop: |-
|
||||
Waiting for instance to become "stopped"...
|
||||
custom_image_os_error: "If you provide a custom image, you must provide the operating system for the image (vm_operating_system)."
|
||||
custom_image_os_error:
|
||||
If you provide a custom image, you must provide the operating system for the image (vm_operating_system) and the Storage Account Azure Resource Provider Id (vm_custom_image_storage_account_id).
|
||||
vhd_and_managed_image_error:
|
||||
Specifying both vm_vhd_uri and vm_managed_image_id is not supported. Please specify one or the other.
|
||||
manage_image_id_format_error:
|
||||
The vm_managed_image_id doesn't fit the expected format, plese verify it looks like '/subscriptions/{sub_id}/resourceGroups/{group_name}/providers/Microsoft.Compute/images/{image_name}'
|
||||
|
|
|
@ -79,12 +79,9 @@
|
|||
}
|
||||
},
|
||||
"variables": {
|
||||
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'vagrant')]",
|
||||
"location": "[resourceGroup().location]",
|
||||
"osDiskName": "[concat(parameters('vmName'), 'OSDisk1')]",
|
||||
"managedOSDiskName": "[concat(parameters('vmName'), 'ManagedOSDisk')]",
|
||||
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
|
||||
"vmStorageAccountContainerName": "vagrant-vhds",
|
||||
"nicName": "[concat(parameters('vmName'), '-vagrantNIC')]",
|
||||
"publicIPAddressName": "[concat(parameters('vmName'), '-vagrantPublicIP')]",
|
||||
"publicIPAddressType": "Dynamic",
|
||||
|
@ -98,8 +95,14 @@
|
|||
"doubleQuote": "\""
|
||||
},
|
||||
"resources": [
|
||||
<% if custom_image %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/storage_account.json", self) + "," %>
|
||||
<% if vhd_uri %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/import_disk.json", {
|
||||
name: "[variables('managedOSDiskName')]",
|
||||
account_type: "[parameters('storageAccountType')]",
|
||||
os_type: "#{operating_system}",
|
||||
source_uri: "#{vhd_uri}",
|
||||
account_id: "#{vhd_stor_acct_id}"
|
||||
}) + "," %>
|
||||
<% end %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/network_security_group.json", self) + "," %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/public_ip_address.json", self) + "," %>
|
||||
|
@ -108,6 +111,32 @@
|
|||
<% if availability_set_name %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/availability_set.json", availability_set_name: availability_set_name) + "," %>
|
||||
<% end %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/virtual_machine.json", self) %>
|
||||
|
||||
<% if custom_image && operating_system == "Linux" %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/linux_reset_root_ext.json",
|
||||
{
|
||||
name: "[concat(parameters('vmName'), '/linuxResetUserExt')]",
|
||||
depends_on: ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"],
|
||||
ssh_key: "[parameters('sshKeyData')]",
|
||||
username: "[parameters('adminUserName')]"
|
||||
}) + ", "
|
||||
%>
|
||||
<% end %>
|
||||
|
||||
<%
|
||||
vm_dependencies = ["[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"]
|
||||
if availability_set_name
|
||||
vm_dependencies.push("[resourceId('Microsoft.Compute/availabilitySets', '#{availability_set_name}')")
|
||||
end
|
||||
if custom_image
|
||||
vm_dependencies.push("[resourceId('Microsoft.Compute/disks', variables('managedOSDiskName'))]")
|
||||
end
|
||||
%>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/virtual_machine.json",
|
||||
{
|
||||
depends_on: vm_dependencies,
|
||||
storage_account_type: "[parameters('storageAccountType')]"
|
||||
}.merge(self.to_h))
|
||||
%>
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
"comments": "Generalized from resource: '/subscriptions/cbbdaed0-fea9-4693-bf0c-d446ac93c030/resourceGroups/test/providers/Microsoft.Compute/disks/osdisk_sVQ7y4vYgM'.",
|
||||
"type": "Microsoft.Compute/disks",
|
||||
"name": "[variables('managedOSDiskName')]",
|
||||
"apiVersion": "2016-04-30-preview",
|
||||
"location": "[variables('location')]",
|
||||
"tags": {},
|
||||
"properties": {
|
||||
"accountType": "[parameters('storageAccountType')",
|
||||
<% if operating_system == 'Windows' %>
|
||||
"osType": "Windows",
|
||||
<% else %>
|
||||
"osType": "Linux",
|
||||
<% end %>
|
||||
"creationData": {
|
||||
"createOption": "Import",
|
||||
"imageReference": {
|
||||
"id": "/Subscriptions/cbbdaed0-fea9-4693-bf0c-d446ac93c030/Providers/Microsoft.Compute/Locations/westus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/16.04-LTS/Versions/latest"
|
||||
}
|
||||
},
|
||||
"diskSizeGB": 30
|
||||
},
|
||||
"dependsOn": []
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"type": "Microsoft.Compute/disks",
|
||||
"name": "<%= name %>",
|
||||
"apiVersion": "2016-04-30-preview",
|
||||
"location": "[variables('location')]",
|
||||
"tags": {},
|
||||
"properties": {
|
||||
"accountType": "<%= account_type %>",
|
||||
"osType": "<%= operating_system %>",
|
||||
"creationData": {
|
||||
"createOption": "Import",
|
||||
"sourceURI": "<%= source_uri %>",
|
||||
"storageAccountId": "<%= account_id %>"
|
||||
}
|
||||
},
|
||||
"dependsOn": [
|
||||
<%= (depends_on || []).map{ |resource| "\"#{resource}\"" }.join(", ") %>
|
||||
]
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"type": "Microsoft.Compute/virtualMachines/extensions",
|
||||
"name": "<%= name %>",
|
||||
"apiVersion": "2015-06-15",
|
||||
"location": "[resourceGroup().location]",
|
||||
"dependsOn": [
|
||||
<%= (depends_on || []).map{ |resource| "\"#{resource}\"" }.join(", ") %>
|
||||
],
|
||||
"properties": {
|
||||
"publisher": "Microsoft.OSTCExtensions",
|
||||
"type": "VMAccessForLinux",
|
||||
"typeHandlerVersion": "1.*",
|
||||
"autoUpgradeMinorVersion": true,
|
||||
"protectedSettings": {
|
||||
"ssh_key": "<%= ssh_key %>",
|
||||
"username": "<%= username %>",
|
||||
"reset_ssh": "True"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,13 +4,7 @@
|
|||
"name": "[parameters('vmName')]",
|
||||
"location": "[variables('location')]",
|
||||
"dependsOn": [
|
||||
<% if custom_image %>
|
||||
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
|
||||
<% end %>
|
||||
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
|
||||
<% if availability_set_name %>,
|
||||
"[resourceId('Microsoft.Compute/availabilitySets', '<%= availability_set_name %>')]"
|
||||
<% end %>
|
||||
<%= (depends_on || []).map{ |resource| "\"#{resource}\"" }.join(", ") %>
|
||||
],
|
||||
<% if operating_system == 'Windows' %>
|
||||
<%= self_signed_cert_resource %>
|
||||
|
@ -19,6 +13,7 @@
|
|||
"hardwareProfile": {
|
||||
"vmSize": "[parameters('vmSize')]"
|
||||
},
|
||||
<% if vhd_uri.nil? && vm_managed_image_id.nil? %>
|
||||
"osProfile": {
|
||||
"computerName": "[parameters('vmName')]",
|
||||
"adminUsername": "[parameters('adminUsername')]",
|
||||
|
@ -38,30 +33,44 @@
|
|||
}
|
||||
<% end %>
|
||||
},
|
||||
<% end %>
|
||||
"storageProfile": {
|
||||
<% if vhd_uri.nil? && vm_managed_image_id.nil? %>
|
||||
"imageReference": {
|
||||
"publisher": "<%= image_publisher %>",
|
||||
"offer": "<%= image_offer %>",
|
||||
"sku": "<%= image_sku %>",
|
||||
"version": "<%= image_version %>"
|
||||
},
|
||||
<% elsif vm_managed_image_id %>
|
||||
"imageReference": {
|
||||
"id": "<%= vm_managed_image_id %>"
|
||||
},
|
||||
<% end %>
|
||||
"osDisk": {
|
||||
<% if custom_image %>
|
||||
"name": "osdisk",
|
||||
"vhd": {
|
||||
"uri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/', variables('osDiskName'),'.vhd')]"
|
||||
<% if vhd_uri %>
|
||||
"osType": "<%= operating_system %>",
|
||||
"managedDisk": {
|
||||
"storageAccountType": "<%= storage_account_type %>",
|
||||
"id": "[resourceId('Microsoft.Compute/disks', variables('managedOSDiskName'))]"
|
||||
},
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "attach",
|
||||
<% elsif vm_managed_image_id %>
|
||||
"osType": "<%= operating_system %>",
|
||||
"managedDisk": {
|
||||
"storageAccountType": "<%= storage_account_type %>",
|
||||
},
|
||||
"createOption": "fromImage",
|
||||
<% else %>
|
||||
"createOption": "fromImage",
|
||||
<% end %>
|
||||
"createOption": "FromImage"
|
||||
"caching": "ReadWrite"
|
||||
},
|
||||
"dataDisks" : [
|
||||
<% data_disks.each_with_index do |disk, idx| %>
|
||||
<%= VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/data_disk.json", {lun: idx + 2}.merge(disk))%>
|
||||
<% if data_disks.count < idx + 1 %>
|
||||
,
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= data_disks.each_with_index.map { |disk, idx|
|
||||
VagrantPlugins::Azure::Util::TemplateRenderer.render("arm/resources/data_disk.json", {lun: idx + 2}.merge(disk))
|
||||
}.join(", ")
|
||||
%>
|
||||
]
|
||||
},
|
||||
"networkProfile": {
|
||||
|
|
Загрузка…
Ссылка в новой задаче