Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #156 from devigned/update/win-support
Browse files Browse the repository at this point in the history
Update the project
  • Loading branch information
devigned authored Feb 2, 2017
2 parents 96da70c + a61a0a3 commit b4baba0
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.7.4'
gem 'dotenv'
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
gem 'bundler', '~>1.10.5'
end

group :plugins do
gem 'vagrant-azure', path: '.'
end
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ For instructions on how to setup an Azure Active Directory Application see: http
* `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_D1'. See: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/
* `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/
* `vm_size`: (Optional) VM size to be used -- defaults to 'Standard_DS2_v2'. See: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/
* `vm_image_urn`: (Optional) Name of the virtual machine image urn to use -- defaults to 'canonical:ubuntuserver:16.04-LTS:latest'. See: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/
* `virtual_network_name`: (Optional) Name of the virtual network resource
* `subnet_name`: (Optional) Name of the virtual network subnet resource
* `instance_ready_timeout`: (Optional) The timeout to wait for an instance to become ready -- default 120 seconds.
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

require 'rubygems'
require 'bundler/setup'
require 'rspec/core/rake_task'

$stdout.sync = true
$stderr.sync = true

Dir.chdir(File.expand_path('../', __FILE__))

Bundler::GemHelper.install_tasks

# Install the `spec` task so that we can run tests.
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = '--order defined'
end
# Default task is to run the unit tests
task :default => :spec
Binary file modified dummy.box
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/vagrant-azure/action/read_ssh_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def call(env)
def read_ssh_info(azure, env)
return nil if env[:machine].id.nil?
parsed = parse_machine_id(env[:machine].id)
public_ip = azure.network.public_ipaddresses.get(parsed[:group], "#{parsed[:name]}-vagrantPublicIP").value!.body
public_ip = azure.network.public_ipaddresses.get(parsed[:group], "#{parsed[:name]}-vagrantPublicIP")

{:host => public_ip.properties.dns_settings.fqdn, :port => 22}
{:host => public_ip.dns_settings.fqdn, :port => 22}
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/vagrant-azure/action/read_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def read_state(azure, machine)
parsed = parse_machine_id(machine.id)
vm = nil
begin
vm = azure.compute.virtual_machines.get(parsed[:group], parsed[:name], 'instanceView').value!.body
vm = azure.compute.virtual_machines.get(parsed[:group], parsed[:name], 'instanceView')
rescue MsRestAzure::AzureOperationError => ex
if vm.nil? || tearing_down?(vm.properties.instance_view.statuses)
if vm.nil? || tearing_down?(vm.instance_view.statuses)
# The machine can't be found
@logger.info('Machine not found or terminated, assuming it got destroyed.')
machine.id = nil
Expand All @@ -40,7 +40,7 @@ def read_state(azure, machine)
end

# Return the state
power_state(vm.properties.instance_view.statuses)
power_state(vm.instance_view.statuses)
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-azure/action/read_winrm_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def call(env)
def read_winrm_info(azure, env)
return nil if env[:machine].id.nil?
parsed = parse_machine_id(env[:machine].id)
public_ip = azure.network.public_ipaddresses.get(parsed[:group], "#{parsed[:name]}-vagrantPublicIP").value!.body
public_ip = azure.network.public_ipaddresses.get(parsed[:group], "#{parsed[:name]}-vagrantPublicIP")

{:host => public_ip.properties.dns_settings.fqdn, :port => env[:machine].config.winrm.port}
{:host => public_ip.dns_settings.fqdn, :port => env[:machine].config.winrm.port}
end
end
end
Expand Down
20 changes: 11 additions & 9 deletions lib/vagrant-azure/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def call(env)

deployment_params = build_deployment_params(template_params, deployment_params.reject{|_,v| v.nil?})

env[:ui].info('Starting deployment')
env[:ui].info(' -- Starting deployment')
env[:metrics]['deployment_time'] = Util::Timer.time do
put_deployment(azure, resource_group_name, deployment_params)
end
env[:ui].info('Finished deploying')
env[:ui].info(' -- Finished deploying')

# Immediately save the ID since it is created at this point.
env[:machine].id = serialize_machine_id(resource_group_name, vm_name, location)
Expand Down Expand Up @@ -176,32 +176,34 @@ def call(env)
end

def get_image_os(image_details)
image_details.properties.os_disk_image.operating_system
image_details.os_disk_image.operating_system
end

def get_image_details(azure, location, publisher, offer, sku, version)
if version == 'latest'
latest = azure.compute.virtual_machine_images.list(location, publisher, offer, sku).value!.body.last
azure.compute.virtual_machine_images.get(location, publisher, offer, sku, latest.name).value!.body
images = azure.compute.virtual_machine_images.list(location, publisher, offer, sku)
latest = images.sort_by(&:name).last
azure.compute.virtual_machine_images.get(location, publisher, offer, sku, latest.name)
else
azure.compute.virtual_machine_images.get(location, publisher, offer, sku, version).value!.body
azure.compute.virtual_machine_images.get(location, publisher, offer, sku, version)
end
end

def put_deployment(azure, rg_name, params)
azure.resources.deployments.create_or_update(rg_name, 'vagrant', params).value!.body
azure.resources.deployments.create_or_update(rg_name, 'vagrant', params)
end

def put_resource_group(azure, name, location)
params = ::Azure::ARM::Resources::Models::ResourceGroup.new.tap do |rg|
rg.location = location
end

azure.resources.resource_groups.create_or_update(name, params).value!.body
azure.resources.resource_groups.create_or_update(name, params)
end

# This method generates the deployment template
def render_deployment_template(options)
self_signed_cert_resource = nil
if options[:operating_system] == 'Windows' && options[:winrm_install_self_signed_cert]
setup_winrm_powershell = Vagrant::Util::TemplateRenderer.render('arm/setup-winrm.ps1', options.merge({template_root: template_root}))
encoded_setup_winrm_powershell = setup_winrm_powershell.
Expand All @@ -216,7 +218,7 @@ def render_deployment_template(options)
def build_deployment_params(template_params, deployment_params)
params = ::Azure::ARM::Resources::Models::Deployment.new
params.properties = ::Azure::ARM::Resources::Models::DeploymentProperties.new
if (template_params[:deployment_template].nil?)
if template_params[:deployment_template].nil?
params.properties.template = JSON.parse(render_deployment_template(template_params))
else
params.properties.template = JSON.parse(template_params[:deployment_template])
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-azure/action/start_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def call(env)
env[:ui].info(I18n.t('vagrant_azure.waiting_for_ready'))

task = await_true(env) do |vm|
running?(vm.properties.instance_view.statuses)
running?(vm.instance_view.statuses)
end

if task.value
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-azure/action/stop_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def call(env)
env[:ui].info(I18n.t('vagrant_azure.waiting_for_stop'))

task = await_true(env) do |vm|
stopped?(vm.properties.instance_view.statuses)
stopped?(vm.instance_view.statuses)
end

if task.value
Expand Down
6 changes: 4 additions & 2 deletions lib/vagrant-azure/action/terminate_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def call(env)
begin
env[:ui].info(I18n.t('vagrant_azure.terminating', parsed))
env[:ui].info('Deleting resource group')
env[:azure_arm_service].resources.resource_groups.delete(parsed[:group]).value!.body
env[:ui].info('Resource group deleted...')

# Call the begin_xxx_async version to kick off the delete, but don't wait for the resource group to be cleaned up
env[:azure_arm_service].resources.resource_groups.begin_delete_async(parsed[:group]).value!
env[:ui].info('Resource group is deleting... Moving on.')
rescue MsRestAzure::AzureOperationError => ex
unless ex.response.status == 404
raise ex
Expand Down
8 changes: 4 additions & 4 deletions lib/vagrant-azure/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ def finalize!
@vm_name = Haikunator.haikunate(100) if @vm_name == UNSET_VALUE
@resource_group_name = Haikunator.haikunate(100) if @resource_group_name == UNSET_VALUE
@vm_password = nil if @vm_password == UNSET_VALUE
@vm_image_urn = 'canonical:ubuntuserver:16.04.0-DAILY-LTS:latest' if @vm_image_urn == UNSET_VALUE
@vm_image_urn = 'canonical:ubuntuserver:16.04.0-LTS:latest' if @vm_image_urn == 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
@tcp_endpoints = nil if @tcp_endpoints == UNSET_VALUE
@vm_size = 'Standard_D1' if @vm_size == 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
@instance_check_interval = 2 if @instance_check_interval == UNSET_VALUE

@admin_username = ENV['AZURE_VM_ADMIN_USERNAME'] if @admin_username == UNSET_VALUE
@admin_password = ENV['AZURE_VM_ADMIN_PASSWORD'] if @admin_password == 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
@deployment_template = nil if @deployment_template == UNSET_VALUE
end
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-azure/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def initialize(machine)
# Load the driver
machine_id_changed

# turn off nfs functionality by default, so the machine will fall back to rsync by default
@machine.config.nfs.functional = false
@machine.config.winrm.password = @machine.provider_config.admin_password
@machine.config.winrm.username = @machine.provider_config.admin_username
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-azure/util/vm_await.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def await_true(env)
end

count += 1
vm = azure.compute.virtual_machines.get(parsed[:group], parsed[:name], 'instanceView').value!.body
vm = azure.compute.virtual_machines.get(parsed[:group], parsed[:name], 'instanceView')
if yield(vm)
task.shutdown
true
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-azure/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

module VagrantPlugins
module Azure
VERSION = '2.0.0.pre1'
VERSION = '2.0.0.pre2'.freeze
end
end
12 changes: 3 additions & 9 deletions templates/arm/deployment.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D1",
"defaultValue": "Standard_DS2_v2",
"metadata": {
"description": "Size of the VM"
}
Expand All @@ -59,7 +59,7 @@
},
"imageSku": {
"type": "string",
"defaultValue": "16.04.0-DAILY-LTS",
"defaultValue": "16.04-LTS",
"metadata": {
"description": "Name of the image sku"
}
Expand Down Expand Up @@ -103,7 +103,7 @@
"nicName": "[concat(parameters('vmName'), '-vagrantNIC')]",
"publicIPAddressName": "[concat(parameters('vmName'), '-vagrantPublicIP')]",
"publicIPAddressType": "Dynamic",
"storageAccountType": "Standard_LRS",
"storageAccountType": "Premium_LRS",
"networkSecurityGroupName": "[concat(parameters('vmName'), '-vagrantNSG')]",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
Expand Down Expand Up @@ -299,12 +299,6 @@
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]"
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions vagrant-azure.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require 'vagrant-azure/version'
Gem::Specification.new do |s|
s.name = 'vagrant-azure'
s.version = VagrantPlugins::Azure::VERSION
s.platform = Gem::Platform::RUBY
s.authors = %w(Azure)
s.description = 'Enable Vagrant to manage machines in Microsoft Azure.'
s.summary = 'Enable Vagrant to manage Windows and Linux machines in Microsoft Azure.'
Expand All @@ -18,15 +19,16 @@ Gem::Specification.new do |s|
s.bindir = 'bin'
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }

s.add_runtime_dependency 'azure_mgmt_resources', '~>0.2.1'
s.add_runtime_dependency 'azure_mgmt_compute', '~>0.2.1'
s.add_runtime_dependency 'azure_mgmt_network', '~>0.2.1'
s.add_runtime_dependency 'azure_mgmt_storage', '~>0.2.1'
s.add_runtime_dependency 'azure_mgmt_resources', '~>0.8.0'
s.add_runtime_dependency 'azure_mgmt_compute', '~>0.8.0'
s.add_runtime_dependency 'azure_mgmt_network', '~>0.8.0'
s.add_runtime_dependency 'azure_mgmt_storage', '~>0.8.0'
s.add_runtime_dependency 'haikunator', '~>1.1'
s.add_runtime_dependency 'highline', '~>1.7'

s.add_development_dependency 'bundler', '~>1.9'
s.add_development_dependency 'rake', '~>11.1'
s.add_development_dependency 'rspec', '~>3.4'
s.add_development_dependency 'simplecov', '~>0.11.2'
s.add_development_dependency 'simplecov', '~>0.11'
s.add_development_dependency 'coveralls', '~>0.8'
end

0 comments on commit b4baba0

Please sign in to comment.