From 81a972d65a6ddde6ccd5f37c5098c355bbd2074e Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Wed, 15 Oct 2014 11:30:58 +0200 Subject: [PATCH 1/5] example_box cleanup --- example_box/README.md | 14 ++------------ example_box/Vagrantfile | 6 ------ example_box/metadata.json | 1 - 3 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 example_box/Vagrantfile delete mode 100644 example_box/metadata.json diff --git a/example_box/README.md b/example_box/README.md index c7015b1..f1b9480 100644 --- a/example_box/README.md +++ b/example_box/README.md @@ -1,13 +1,3 @@ -# vagrant-vcenter box specifications [WIP] +# vagrant-vcenter box specifications -*Note that vagrant-vcenter currently supports only single VM vApp boxes* - -BOX package should contain: - -- `metadata.json` -- Vagrant metadata file -- `.ovf` -- OVF descriptor of the vApp. -- `.mf` -- OVF manifest file containing file hashes. -- `-disk-<#>.vmdk` -- Associated VMDK files. -- `Vagrantfile`-- vagrant-vcenter default Vagrantfile - -A [task is open](https://github.com/frapposelli/vagrant-vcenter/issues/12) for creating a veewee plugin to facilitate Box creation \ No newline at end of file +[See this Wiki page for more information](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf/wiki/vmware_ovf-Box-Format). \ No newline at end of file diff --git a/example_box/Vagrantfile b/example_box/Vagrantfile deleted file mode 100644 index 4937ecb..0000000 --- a/example_box/Vagrantfile +++ /dev/null @@ -1,6 +0,0 @@ -Vagrant::Config.run do |config| - config.vm.base_mac = "" -end - -include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__) -load include_vagrantfile if File.exist?(include_vagrantfile) diff --git a/example_box/metadata.json b/example_box/metadata.json deleted file mode 100644 index eb7aef2..0000000 --- a/example_box/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"provider": "vagrant-vcenter"} From 07cccd2e0519ddb8f1c0bee5471bf68c087b70f1 Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Wed, 15 Oct 2014 11:34:29 +0200 Subject: [PATCH 2/5] Fix for a longstanding botched if, Fixes #14 --- lib/vagrant-vcenter/action/inventory_check.rb | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/lib/vagrant-vcenter/action/inventory_check.rb b/lib/vagrant-vcenter/action/inventory_check.rb index 924a487..c5c0785 100644 --- a/lib/vagrant-vcenter/action/inventory_check.rb +++ b/lib/vagrant-vcenter/action/inventory_check.rb @@ -37,9 +37,6 @@ def vcenter_upload_box(env) box_ovf = "file://#{box_dir}/#{box_file}.ovf" - # Still relying on ruby-progressbar because report_progress basically - # sucks. - @logger.debug("OVF File: #{box_ovf}") env[:ui].info("Adding [#{box_name}]") @@ -51,12 +48,11 @@ def vcenter_upload_box(env) root_vm_folder = dc.vmFolder vm_folder = root_vm_folder if config.template_folder_name.nil? - vm_folder = root_vm_folder.traverse(config.template_folder_name, - RbVmomi::VIM::Folder) + template_folder = root_vm_folder + else + template_folder = root_vm_folder.traverse!( + config.template_folder_name, RbVmomi::VIM::Folder) end - template_folder = root_vm_folder.traverse!( - config.template_folder_name, - RbVmomi::VIM::Folder) template_name = box_name @@ -109,8 +105,7 @@ def vcenter_check_inventory(env) if config.template_folder_name.nil? box_to_search = box_name else - box_to_search = config.template_folder_name + - '/' + box_name + box_to_search = config.template_folder_name + '/' + box_name end @logger.debug("This is the box we're looking for: #{box_to_search}") @@ -118,25 +113,13 @@ def vcenter_check_inventory(env) config.template_id = dc.find_vm(box_to_search) if config.template_id.nil? - env[:ui].warn("Template [#{box_name}] " + - 'does not exist!') - - user_input = env[:ui].ask( - "Would you like to upload the [#{box_name}]" + - " box?\nChoice (yes/no): " - ) - - if user_input.downcase == 'yes' || user_input.downcase == 'y' - env[:ui].info("Uploading [#{box_name}]...") - vcenter_upload_box(env) - else - env[:ui].error('Template not uploaded, exiting...') - - # FIXME: wrong error message - fail VagrantPlugins::VCenter::Errors::VCenterError, - :message => 'Catalog not available, exiting...' + # Roll a dice to get a winner in the race. + sleep_time = rand * (3 - 1) + 1 + @logger.debug("Sleeping #{sleep_time} to avoid race conditions.") + sleep(sleep_time) - end + env[:ui].info("Uploading [#{box_name}]...") + vcenter_upload_box(env) else @logger.debug("Template found at #{box_to_search}") end From ca34daf2a46dfdb1cea533b60a73e78c0e2d7291 Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Wed, 15 Oct 2014 16:07:28 +0200 Subject: [PATCH 3/5] Better customization handling, windows support still need to be checked thoroughly - Fixes #19 --- lib/vagrant-vcenter/action/build_vm.rb | 132 ++++++++++++++++--------- lib/vagrant-vcenter/config.rb | 24 ++++- lib/vagrant-vcenter/plugin.rb | 2 +- locales/en.yml | 2 +- 4 files changed, 113 insertions(+), 47 deletions(-) diff --git a/lib/vagrant-vcenter/action/build_vm.rb b/lib/vagrant-vcenter/action/build_vm.rb index 969be0e..580c125 100644 --- a/lib/vagrant-vcenter/action/build_vm.rb +++ b/lib/vagrant-vcenter/action/build_vm.rb @@ -120,61 +120,105 @@ def call(env) spec.config = config_spec end - public_networks = env[:machine].config.vm.networks.select { - |n| n[0].eql? :public_network - } - - network_spec = public_networks.first[1] - - @logger.debug("This is our network #{public_networks.inspect}") - - if network_spec - - # Check for sanity and validation of network parameters. - - # Specify ip but no netmask - if network_spec[:ip] && !network_spec[:netmask] - fail Errors::WrongNetworkSpec + if config.enable_vm_customization + public_networks = env[:machine].config.vm.networks.select { + |n| n[0].eql? :public_network + } + + network_spec = public_networks.first[1] unless public_networks.empty? + + @logger.debug("This is our network #{public_networks.inspect}") + + if network_spec + + # Check for sanity and validation of network parameters. + + # Specify ip but no netmask + if network_spec[:ip] && !network_spec[:netmask] + fail Errors::WrongNetworkSpec + end + + # specify netmask but no ip + if !network_spec[:ip] && network_spec[:netmask] + fail Errors::WrongNetworkSpec + end + + global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings( + :dnsServerList => network_spec[:dns_server_list], + :dnsSuffixList => network_spec[:dns_suffix_list]) + + # if no ip and no netmask, let's default to dhcp + if !network_spec[:ip] && !network_spec[:netmask] + adapter = RbVmomi::VIM.CustomizationIPSettings( + :ip => RbVmomi::VIM.CustomizationDhcpIpGenerator()) + else + adapter = RbVmomi::VIM.CustomizationIPSettings( + :gateway => [network_spec[:gateway]], + :ip => RbVmomi::VIM.CustomizationFixedIp( + :ipAddress => network_spec[:ip]), + :subnetMask => network_spec[:netmask]) + end + + nic_map = [RbVmomi::VIM.CustomizationAdapterMapping( + :adapter => adapter)] end - # specify netmask but no ip - if !network_spec[:ip] && network_spec[:netmask] - fail Errors::WrongNetworkSpec + if config.prep_type.downcase == 'linux' + prep = RbVmomi::VIM.CustomizationLinuxPrep( + :domain => env[:machine].name.to_s.sub(/^[^.]+\./, ''), + :hostName => RbVmomi::VIM.CustomizationFixedName( + :name => env[:machine].name.to_s.split('.')[0])) + elsif config.prep_type.downcase == 'windows' + prep = RbVmomi::VIM.CustomizationSysprep( + :guiUnattended => RbVmomi::VIM.CustomizationGuiUnattended( + :autoLogon => false, + :autoLogonCount => 0, + :timeZone => 004 + ), + :identification => RbVmomi::VIM.CustomizationIdentification(), + :userData => RbVmomi::VIM.CustomizationUserData( + :computerName => RbVmomi::VIM.CustomizationFixedName( + :name => env[:machine].name.to_s.split('.')[0]), + :fullName => 'Vagrant', + :orgName => 'Vagrant', + :productId => 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' + ) + ) + else + fail "specification type #{config.prep_type} not supported" end - global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings( - :dnsServerList => network_spec[:dns_server_list], - :dnsSuffixList => network_spec[:dns_suffix_list]) + if prep && network_spec + # If prep and network specification are present, let's do a full config + cust_spec = RbVmomi::VIM.CustomizationSpec( + :globalIPSettings => global_ip_settings, + :identity => prep, + :nicSettingMap => nic_map) - prep = RbVmomi::VIM.CustomizationLinuxPrep( - :domain => env[:machine].name.to_s.sub(/^[^.]+\./, ''), - :hostName => RbVmomi::VIM.CustomizationFixedName( - :name => env[:machine].name.to_s.split('.')[0])) + spec.customization = cust_spec + + elsif prep && !network_spec + # If no network specifications, default to dhcp + global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings( + :dnsServerList => [], + :dnsSuffixList => []) - # if no ip and no netmask, let's default to dhcp - if !network_spec[:ip] && !network_spec[:netmask] - adapter = RbVmomi::VIM.CustomizationIPSettings( - :ip => RbVmomi::VIM.CustomizationDhcpIpGenerator()) - else adapter = RbVmomi::VIM.CustomizationIPSettings( - :gateway => [network_spec[:gateway]], - :ip => RbVmomi::VIM.CustomizationFixedIp( - :ipAddress => network_spec[:ip]), - :subnetMask => network_spec[:netmask]) - end + :ip => RbVmomi::VIM.CustomizationDhcpIpGenerator()) - nic_map = [RbVmomi::VIM.CustomizationAdapterMapping( - :adapter => adapter)] + nic_map = [RbVmomi::VIM.CustomizationAdapterMapping( + :adapter => adapter)] - cust_spec = RbVmomi::VIM.CustomizationSpec( - :globalIPSettings => global_ip_settings, - :identity => prep, - :nicSettingMap => nic_map) + cust_spec = RbVmomi::VIM.CustomizationSpec( + :globalIPSettings => global_ip_settings, + :identity => prep, + :nicSettingMap => nic_map) - spec.customization = cust_spec - end + spec.customization = cust_spec + end - @logger.debug("Spec: #{spec.pretty_inspect}") + @logger.debug("Spec: #{spec.pretty_inspect}") + end @logger.debug("disable_auto_vm_name: #{config.disable_auto_vm_name}") diff --git a/lib/vagrant-vcenter/config.rb b/lib/vagrant-vcenter/config.rb index 5360f17..dfa0fdf 100644 --- a/lib/vagrant-vcenter/config.rb +++ b/lib/vagrant-vcenter/config.rb @@ -75,6 +75,20 @@ class Config < Vagrant.plugin('2', :config) # @return [String] attr_accessor :vm_network_type + # Use prep and customization api in the building + # of the vm in vcenter + # + # Mostly this allows the static ip configuration + # of a vm + # + # @return [Bool] + attr_accessor :enable_vm_customization + + # Type of the machine prep to use + # + # @return [String] + attr_accessor :prep_type + # num cpu # # @return [Fixnum] @@ -93,6 +107,11 @@ class Config < Vagrant.plugin('2', :config) attr_accessor :vcenter_cnx attr_accessor :template_id + def initialize + @prep_type = 'linux' + @enable_vm_customization = true + end + def validate(machine) errors = _detected_errors @@ -111,7 +130,10 @@ def validate(machine) I18n.t('vagrant_vcenter.config.computer_name') if computer_name.nil? errors << I18n.t('vagrant_vcenter.config.network_name') if network_name.nil? - + if enable_vm_customization + errors << + I18n.t('vagrant_vcenter.config.no_prep_type') if prep_type.downcase != 'linux' && prep_type.downcase != 'windows' + end { 'vCenter Provider' => errors } end end diff --git a/lib/vagrant-vcenter/plugin.rb b/lib/vagrant-vcenter/plugin.rb index 062aaa4..394ff6c 100644 --- a/lib/vagrant-vcenter/plugin.rb +++ b/lib/vagrant-vcenter/plugin.rb @@ -37,7 +37,7 @@ class Plugin < Vagrant.plugin('2') Cap::PublicAddress end - provider_capability(:vcenter, :winrm_info) do + provider_capability(:vcenter, :read_winrm_info) do require_relative 'cap/winrm_info' Cap::WinRM end diff --git a/locales/en.yml b/locales/en.yml index ea42783..468436f 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -27,7 +27,7 @@ en: resourcepool_name: |- Configuration must specify a resource pool name no_prep_type: |- - The only supported prep type is linux. hack away. + The only supported prep types are windows and linux. ipaddress: |- Configuration must specify a ipaddress gateway: |- From 1b824dcd6797f275a4aeb21384ba2bbfb2c2a0da Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Wed, 15 Oct 2014 16:20:37 +0200 Subject: [PATCH 4/5] Added resource pool selection, only works with top-level resource pool under the compute resource. - Fixes 20 --- lib/vagrant-vcenter/action/build_vm.rb | 9 ++++++++- lib/vagrant-vcenter/config.rb | 5 +++++ lib/vagrant-vcenter/version.rb | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-vcenter/action/build_vm.rb b/lib/vagrant-vcenter/action/build_vm.rb index 580c125..5e1cc62 100644 --- a/lib/vagrant-vcenter/action/build_vm.rb +++ b/lib/vagrant-vcenter/action/build_vm.rb @@ -40,7 +40,14 @@ def call(env) # FIXME: Raise a correct exception computer = dc.find_compute_resource( config.computer_name) or fail 'Host not found' - rp = computer.resourcePool + + if config.resourcepool_name + rp = computer.resourcePool.resourcePool.find { + |f| f.name == config.resourcepool_name + } + else + rp = computer.resourcePool + end # FIXME: Raise a correct exception template = dc.find_vm( diff --git a/lib/vagrant-vcenter/config.rb b/lib/vagrant-vcenter/config.rb index dfa0fdf..16cd4d3 100644 --- a/lib/vagrant-vcenter/config.rb +++ b/lib/vagrant-vcenter/config.rb @@ -28,6 +28,11 @@ class Config < Vagrant.plugin('2', :config) # @return [String] attr_accessor :folder_name + # Resource Pool Name where the item will live + # + # @return [String] + attr_accessor :resourcepool_name + # Catalog Name where the item resides # # @return [String] diff --git a/lib/vagrant-vcenter/version.rb b/lib/vagrant-vcenter/version.rb index f2c518e..2cee69c 100644 --- a/lib/vagrant-vcenter/version.rb +++ b/lib/vagrant-vcenter/version.rb @@ -1,6 +1,6 @@ module VagrantPlugins # Set version for vagrant-vcenter gem. module VCenter - VERSION = '0.3.0' + VERSION = '0.3.1' end end From 3a30fd5f3c4d5a20ec72438fd4d92e1ac32f59c1 Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Wed, 15 Oct 2014 16:30:14 +0200 Subject: [PATCH 5/5] Version Bump and README update --- README.md | 13 ++----------- lib/vagrant-vcenter/version.rb | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2d0c109..768b30f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [Vagrant](http://www.vagrantup.com) provider for VMware vCenter® ============= -[Version 0.3.0](../../releases/tag/v0.3.0) has been released! +[Version 0.3.2](../../releases/tag/v0.3.2) has been released! ------------- Please note that this software is still Alpha/Beta quality and is not recommended for production usage. @@ -10,16 +10,6 @@ We have a wide array of boxes available at [Vagrant Cloud](https://vagrantcloud. This plugin supports the universal [```vmware_ovf``` box format](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf/wiki/vmware_ovf-Box-Format), that is 100% portable between [vagrant-vcloud](https://github.com/frapposelli/vagrant-vcloud), [vagrant-vcenter](https://github.com/gosddc/vagrant-vcenter) and [vagrant-vcloudair](https://github.com/gosddc/vagrant-vcloudair), no more double boxes!. -Changes in [version 0.3.0](../../releases/tag/v0.3.0) include: - -Fixes - -- ```vmware_ovf``` support! -- You can now specify network using the ```public_network``` notation of Vagrant. -- Plugin is now operating in parallel, MOAR SPEED! -- Create the VM folder if it doesn't exist. -- Several bug fixes. - Install ------------- @@ -104,6 +94,7 @@ Vagrant.configure('2') do |config| override.folder_name = 'Vagrant/centos' when /precise/ override.folder_name = 'Vagrant/ubuntu/precise' + override.enable_vm_customization = false end end node_config.nfs.functional = false diff --git a/lib/vagrant-vcenter/version.rb b/lib/vagrant-vcenter/version.rb index 2cee69c..4c1f0fb 100644 --- a/lib/vagrant-vcenter/version.rb +++ b/lib/vagrant-vcenter/version.rb @@ -1,6 +1,6 @@ module VagrantPlugins # Set version for vagrant-vcenter gem. module VCenter - VERSION = '0.3.1' + VERSION = '0.3.2' end end