From ed828c9b47390e14e368a1486b63926ac1d1f138 Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Wed, 28 May 2014 17:56:17 +0200 Subject: [PATCH 01/12] Removed provider rsync code, leveraging vagrant core functionalities for folder sync from now on. --- lib/vagrant-vcenter/action.rb | 6 +- lib/vagrant-vcenter/action/sync_folders.rb | 135 --------------------- locales/en.yml | 6 - 3 files changed, 2 insertions(+), 145 deletions(-) delete mode 100644 lib/vagrant-vcenter/action/sync_folders.rb diff --git a/lib/vagrant-vcenter/action.rb b/lib/vagrant-vcenter/action.rb index 7950a5d..8209441 100644 --- a/lib/vagrant-vcenter/action.rb +++ b/lib/vagrant-vcenter/action.rb @@ -14,7 +14,7 @@ def self.action_boot Vagrant::Action::Builder.new.tap do |b| b.use PowerOn b.use Provision - b.use SyncFolders + b.use SyncedFolders end end @@ -114,7 +114,7 @@ def self.action_provision next end b2.use Provision - b2.use SyncFolders + b2.use SyncedFolders end end end @@ -224,8 +224,6 @@ def self.action_up action_root.join('resume') autoload :Suspend, action_root.join('suspend') - autoload :SyncFolders, - action_root.join('sync_folders') end end end diff --git a/lib/vagrant-vcenter/action/sync_folders.rb b/lib/vagrant-vcenter/action/sync_folders.rb deleted file mode 100644 index 190230e..0000000 --- a/lib/vagrant-vcenter/action/sync_folders.rb +++ /dev/null @@ -1,135 +0,0 @@ -# The MIT License (MIT) -# Copyright (c) 2013 Mitchell Hashimoto - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. - -require 'log4r' -require 'vagrant/util/subprocess' -require 'vagrant/util/scoped_hash_override' -require 'vagrant/util/which' - -module VagrantPlugins - module VCenter - module Action - # This class syncs Vagrant folders using RSYNC, this code has been ported - # from vagrant-aws (https://github.com/mitchellh/vagrant-aws) - class SyncFolders - include Vagrant::Util::ScopedHashOverride - - def initialize(app, env) - @app = app - @logger = Log4r::Logger.new('vagrant_vcenter::action::sync_folders') - end - - def call(env) - @app.call(env) - - ssh_info = env[:machine].ssh_info - - unless Vagrant::Util::Which.which('rsync') - env[:ui].warn(I18n.t('vagrant_vcenter.sync.rsync_not_found_warning', - :side => 'host')) - return - end - - if env[:machine].communicate.execute('which rsync', - :error_check => false) != 0 - env[:ui].warn(I18n.t('vagrant_vcenter.sync.rsync_not_found_warning', - :side => 'guest')) - return - end - - env[:machine].config.vm.synced_folders.each do |id, data| - data = scoped_hash_override(data, :vCenter) - - # Ignore disabled shared folders - next if data[:disabled] - - hostpath = File.expand_path(data[:hostpath], env[:root_path]) - guestpath = data[:guestpath] - - # Make sure there is a trailing slash on the host path to - # avoid creating an additional directory with rsync - hostpath = "#{hostpath}/" if hostpath !~ /\/$/ - - # on windows rsync.exe requires cygdrive-style paths - if Vagrant::Util::Platform.windows? - hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/\1" } - end - - env[:ui].info(I18n.t('vagrant_vcenter.sync.rsync_folder', - :hostpath => hostpath, - :guestpath => guestpath)) - - # Create the host path if it doesn't exist and option flag is set - if data[:create] - begin - FileUtils.mkdir_p(hostpath) - rescue => err - raise Errors::MkdirError, - :hostpath => hostpath, - :err => err - end - end - - # Create the guest path - env[:machine].communicate.sudo("mkdir -p '#{guestpath}'") - env[:machine].communicate.sudo( - "chown -R #{ssh_info[:username]} '#{guestpath}'") - - # collect rsync excludes specified :rsync_excludes=>['path1',...] - # in synced_folder options - excludes = ['.vagrant/', 'Vagrantfile', - *Array(data[:rsync_excludes])].uniq - - # Rsync over to the guest path using the SSH info - command = [ - 'rsync', '--verbose', '--archive', '-z', - *excludes.map { |e|['--exclude', e] }.flatten, - '-e', "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no " + - "#{ssh_key_options(ssh_info)}", hostpath, - "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"] - - # we need to fix permissions when using rsync.exe on windows, see - # http://stackoverflow.com/questions/5798807/rsync-permission- - # denied-created-directories-have-no-permissions - if Vagrant::Util::Platform.windows? - command.insert(1, '--chmod', 'ugo=rwX') - end - - r = Vagrant::Util::Subprocess.execute(*command) - if r.exit_code != 0 - fail Errors::RsyncError, - :guestpath => guestpath, - :hostpath => hostpath, - :stderr => r.stderr - end - end - end - - private - - def ssh_key_options(ssh_info) - # Ensure that `private_key_path` is an Array (for Vagrant < 1.4) - Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join - end - end - end - end -end diff --git a/locales/en.yml b/locales/en.yml index d05efdb..a7a76ba 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -9,12 +9,6 @@ en: VM is already running vm_halted_cannot_suspend: |- VM is not running or already suspended, cannot suspend it. - sync: - rsync_not_found_warning: |- - Warning! Folder sync disabled because the rsync binary is missing. - Make sure rsync is installed and the binary can be found in the PATH. - rsync_folder: |- - Rsyncing folder: %{hostpath} => %{guestpath} config: hostname: |- Configuration must specify a vCenter hostname From c8c9e536439a6f21d3f67182c7d6f0d26766704e Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Tue, 3 Jun 2014 13:18:41 -0700 Subject: [PATCH 02/12] If you delete a vm and hope to have vagrant recreate it. it wont. Check for it really existing in the inventory and not just in the box file --- lib/vagrant-vcenter/action/is_created.rb | 10 ++++++++++ lib/vagrant-vcenter/action/read_state.rb | 14 +++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-vcenter/action/is_created.rb b/lib/vagrant-vcenter/action/is_created.rb index 8f128ec..3b9e86b 100644 --- a/lib/vagrant-vcenter/action/is_created.rb +++ b/lib/vagrant-vcenter/action/is_created.rb @@ -10,7 +10,17 @@ def initialize(app, env) def call(env) vm_id = env[:machine].id + config = env[:machine].provider_config if vm_id + dc = config.vcenter_cnx.serviceInstance.find_datacenter( + config.datacenter_name) or abort 'datacenter not found' + root_vm_folder = dc.vmFolder + vm = root_vm_folder.findByUuid(env[:machine].id) + if not vm + @logger.warn('VM has not been created') + env[:result] = false + end + @logger.info("VM has been created and ID is: [#{vm_id}]") env[:result] = true else diff --git a/lib/vagrant-vcenter/action/read_state.rb b/lib/vagrant-vcenter/action/read_state.rb index 57ea2f9..4abf150 100644 --- a/lib/vagrant-vcenter/action/read_state.rb +++ b/lib/vagrant-vcenter/action/read_state.rb @@ -18,6 +18,12 @@ def call(env) def read_state(env) # FIXME: this part needs some cleanup config = env[:machine].provider_config + vm_name = env[:machine].name + + if env[:machine].id.nil? + @logger.info("VM [#{vm_name}] is not created yet") + return :not_created + end # FIXME: Raise a correct exception dc = config.vcenter_cnx.serviceInstance.find_datacenter( @@ -26,15 +32,13 @@ def read_state(env) root_vm_folder = dc.vmFolder vm = root_vm_folder.findByUuid(env[:machine].id) - - @logger.debug("Current power state: #{vm.runtime.powerState}") - vm_name = env[:machine].name - - if env[:machine].id.nil? + if not vm @logger.info("VM [#{vm_name}] is not created yet") return :not_created end + @logger.debug("Current power state: #{vm.runtime.powerState}") + if vm.runtime.powerState == 'poweredOff' @logger.info("VM [#{vm_name}] is stopped") return :stopped From 98f4d3f6e7c21c1b297a5a269e5e1ca642f03732 Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Tue, 3 Jun 2014 14:36:08 -0700 Subject: [PATCH 03/12] make sure we are connected during the first test if the vm is created during up action. also only test if the vm actually exists if we are connected to handle the rest of the actions --- lib/vagrant-vcenter/action.rb | 2 +- lib/vagrant-vcenter/action/is_created.rb | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/vagrant-vcenter/action.rb b/lib/vagrant-vcenter/action.rb index 7950a5d..0cd34f7 100644 --- a/lib/vagrant-vcenter/action.rb +++ b/lib/vagrant-vcenter/action.rb @@ -170,10 +170,10 @@ def self.action_ssh_run def self.action_up Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate + b.use ConnectvCenter b.use Call, IsCreated do |env, b2| b2.use HandleBox unless env[:result] end - b.use ConnectvCenter b.use InventoryCheck b.use Call, IsCreated do |env, b2| b2.use BuildVM unless env[:result] diff --git a/lib/vagrant-vcenter/action/is_created.rb b/lib/vagrant-vcenter/action/is_created.rb index 3b9e86b..3c83758 100644 --- a/lib/vagrant-vcenter/action/is_created.rb +++ b/lib/vagrant-vcenter/action/is_created.rb @@ -12,15 +12,16 @@ def call(env) vm_id = env[:machine].id config = env[:machine].provider_config if vm_id - dc = config.vcenter_cnx.serviceInstance.find_datacenter( - config.datacenter_name) or abort 'datacenter not found' - root_vm_folder = dc.vmFolder - vm = root_vm_folder.findByUuid(env[:machine].id) - if not vm - @logger.warn('VM has not been created') - env[:result] = false + if config.vcenter_cnx + dc = config.vcenter_cnx.serviceInstance.find_datacenter( + config.datacenter_name) or abort 'datacenter not found' + root_vm_folder = dc.vmFolder + vm = root_vm_folder.findByUuid(env[:machine].id) + if not vm + @logger.warn('VM has not been created') + env[:result] = false + end end - @logger.info("VM has been created and ID is: [#{vm_id}]") env[:result] = true else From 5115a0f45de24d582448be83ee2fa73c339c462e Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Tue, 3 Jun 2014 14:37:40 -0700 Subject: [PATCH 04/12] Add a provider option to disable naming vms with extra info --- lib/vagrant-vcenter/action/build_vm.rb | 12 +++++++++--- lib/vagrant-vcenter/config.rb | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-vcenter/action/build_vm.rb b/lib/vagrant-vcenter/action/build_vm.rb index 5cf5d01..aee9f9e 100644 --- a/lib/vagrant-vcenter/action/build_vm.rb +++ b/lib/vagrant-vcenter/action/build_vm.rb @@ -96,9 +96,15 @@ def call(env) @logger.debug("Spec: #{spec.pretty_inspect}") - vm_target = "Vagrant-#{Etc.getlogin}-" + - "#{vm_name}-#{Socket.gethostname.downcase}-" + - "#{SecureRandom.hex(4)}" + @logger.debug("disable_auto_vm_name: #{config.disable_auto_vm_name}") + + if config.disable_auto_vm_name or config.disable_auto_vm_name == 'true' + vm_target = vm_name.to_s + else + vm_target = "Vagrant-#{Etc.getlogin}-" + + "#{vm_name}-#{Socket.gethostname.downcase}-" + + "#{SecureRandom.hex(4)}" + end @logger.debug("VM name: #{vm_target}") diff --git a/lib/vagrant-vcenter/config.rb b/lib/vagrant-vcenter/config.rb index f5e5aea..fcfb6b5 100644 --- a/lib/vagrant-vcenter/config.rb +++ b/lib/vagrant-vcenter/config.rb @@ -58,6 +58,11 @@ class Config < Vagrant.plugin('2', :config) # @return [Bool] attr_accessor :linked_clones + # Disable automatic safe vm name generation + # + # @return [Bool] + attr_accessor :disable_auto_vm_name + ## ## vCenter config runtime values ## From d6ca8c6867a08f6e017b93e871a5997c9c7c8e69 Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Tue, 3 Jun 2014 18:04:53 -0700 Subject: [PATCH 05/12] checkpoint for adding new options to clone a vm with static ip config --- Gemfile | 4 ++ lib/vagrant-vcenter/action/build_vm.rb | 31 +++++++++++++ lib/vagrant-vcenter/config.rb | 60 ++++++++++++++++++++++++++ locales/en.yml | 8 ++++ 4 files changed, 103 insertions(+) diff --git a/Gemfile b/Gemfile index e9c9b79..2fbd2ae 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,7 @@ gemspec group :development do gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git' end + +group :plugins do + gem "vagrant-vcenter", path: "." +end diff --git a/lib/vagrant-vcenter/action/build_vm.rb b/lib/vagrant-vcenter/action/build_vm.rb index aee9f9e..3aded0d 100644 --- a/lib/vagrant-vcenter/action/build_vm.rb +++ b/lib/vagrant-vcenter/action/build_vm.rb @@ -94,6 +94,37 @@ def call(env) :powerOn => false, :template => false) + if config.enable_vm_customization or config.enable_vm_customization == 'true' + gIPSettings = RbVmomi::VIM.CustomizationGlobalIPSettings + if not config.dns_server_list.empty? + gIPSettings[ :dnsServerList ] = config.dns_server_list + end + if not config.dns_suffix_list.empty? + gIPSettings[ :dnsSuffixList ] = config.dns_suffix_list + end + + prep = RbVmomi::VIM.CustomizationLinuxPrep( + :domain => env[:machine].name, + :hostName => RbVmomi::VIM.CustomizationFixedName( + :name => env[:machine].name)) + + adapter = RbVmomi::VIM.CustomizationIPSettings( + :gateway => [config.gateway], + :ip => RbVmomi::VIM.CustomizationFixedIp( + :ipAddress => config.ipaddress), + :subnetMask => config.netmask) + + nic_map = [RbVmomi::VIM.CustomizationAdapterMapping( + :adapter => adapter)] + + cust_spec = RbVmomi::VIM.CustomizationSpec( + :globalIPSettings => gIPSettings, + :identity => prep, + :nicSettingMap => nic_map) + + spec.customization = cust_spec + end + @logger.debug("Spec: #{spec.pretty_inspect}") @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 fcfb6b5..aab1295 100644 --- a/lib/vagrant-vcenter/config.rb +++ b/lib/vagrant-vcenter/config.rb @@ -63,6 +63,47 @@ class Config < Vagrant.plugin('2', :config) # @return [Bool] attr_accessor :disable_auto_vm_name + # 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 + + # Dns server list + # + # @return [Array] + attr_accessor :dns_server_list + + # Dns suffix list + # + # @return [Array] + attr_accessor :dns_suffix_list + + # network gateway + # + # @return [String] + attr_accessor :gateway + + # subnet mask + # + # @return [String] + attr_accessor :netmask + + # ip address + # + # @return [String] + attr_accessor :ipaddress + + + ## ## vCenter config runtime values ## @@ -71,6 +112,14 @@ class Config < Vagrant.plugin('2', :config) attr_accessor :vcenter_cnx attr_accessor :template_id + def initialize() + @enable_vm_customization = false + @prep_type = 'linux' + @enable_vm_customization = false + @dns_server_list = [] + @dns_suffix_list = [] + end + def validate(machine) errors = _detected_errors @@ -90,6 +139,17 @@ def validate(machine) 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 != 'linux' + errors << + I18n.t('vagrant_vcenter.config.gateway') if gateway.empty? + errors << + I18n.t('vagrant_vcenter.config.ipaddress') if ipaddress.empty? + errors << + I18n.t('vagrant_vcenter.config.netmask') if netmask.empty? + end + { 'vCenter Provider' => errors } end end diff --git a/locales/en.yml b/locales/en.yml index d05efdb..31b78d7 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -32,6 +32,14 @@ en: Configuration must specify a resource pool name resourcepool_name: |- Configuration must specify a resource pool name + no_prep_type: |- + The only supported prep type is linux. hack away. + ipaddress: |- + Configuration must specify a ipaddress + gateway: |- + Configuration must specify a gateway + netmask: |- + Configuration must specify a netmask states: not_created: |- The environment has not yet been created. Run `vagrant up` to From 44b0e9996153d1aabc0ba1ce6d6651bc9e028f28 Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Wed, 4 Jun 2014 15:37:42 -0700 Subject: [PATCH 06/12] simpler way of specifying dns options --- lib/vagrant-vcenter/action/build_vm.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/vagrant-vcenter/action/build_vm.rb b/lib/vagrant-vcenter/action/build_vm.rb index 3aded0d..72106a2 100644 --- a/lib/vagrant-vcenter/action/build_vm.rb +++ b/lib/vagrant-vcenter/action/build_vm.rb @@ -95,13 +95,9 @@ def call(env) :template => false) if config.enable_vm_customization or config.enable_vm_customization == 'true' - gIPSettings = RbVmomi::VIM.CustomizationGlobalIPSettings - if not config.dns_server_list.empty? - gIPSettings[ :dnsServerList ] = config.dns_server_list - end - if not config.dns_suffix_list.empty? - gIPSettings[ :dnsSuffixList ] = config.dns_suffix_list - end + gIPSettings = RbVmomi::VIM.CustomizationGlobalIPSettings( + :dnsServerList => config.dns_server_list, + :dnsSuffixList => config.dns_suffix_list) prep = RbVmomi::VIM.CustomizationLinuxPrep( :domain => env[:machine].name, From efbaf91973c92b2284734250e3f2d8978429e86a Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Wed, 4 Jun 2014 15:40:09 -0700 Subject: [PATCH 07/12] return nil if we find the vm but it doesn't have an ip yet. this will cause read_ssh_info to be retried instead of just the ssh connnection. --- lib/vagrant-vcenter/action/read_ssh_info.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-vcenter/action/read_ssh_info.rb b/lib/vagrant-vcenter/action/read_ssh_info.rb index 8a8aec6..3373b52 100644 --- a/lib/vagrant-vcenter/action/read_ssh_info.rb +++ b/lib/vagrant-vcenter/action/read_ssh_info.rb @@ -27,9 +27,19 @@ def read_ssh_info(env) root_vm_folder = dc.vmFolder vm = root_vm_folder.findByUuid(env[:machine].id) - @logger.debug("IP Address: #{vm.guest.ipAddress}") + address = vm.guest.ipAddress + if not address or address == '' + address = vm.guest_ip + end - { :host => vm.guest.ipAddress, :port => 22 } + if not address or address == '' + # if we can't find it right away just return nil. it will retry + # till the vmware tools supplies the ip address back to vcenter + @logger.debug('could not find booted guest ipaddress') + return nil + end + + { :host => address, :port => 22 } end end end From b54944252ea16a5b3110c9d61dc18c1d344d489a Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Wed, 4 Jun 2014 19:25:44 -0700 Subject: [PATCH 08/12] make the poweron setting slightly more tollerable trying to connect. its slow to bring up vms --- lib/vagrant-vcenter/action/power_on.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-vcenter/action/power_on.rb b/lib/vagrant-vcenter/action/power_on.rb index 7c810e0..13d91bd 100644 --- a/lib/vagrant-vcenter/action/power_on.rb +++ b/lib/vagrant-vcenter/action/power_on.rb @@ -21,7 +21,7 @@ def call(env) # Poweron VM env[:ui].info('Powering on VM...') vm.PowerOnVM_Task.wait_for_completion - sleep(3) until env[:machine].communicate.ready? + sleep(20) until env[:machine].communicate.ready? @app.call env end end From 8a0503e572c41c9c6dde1ccf4d6e039eba10988c Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Mon, 9 Jun 2014 14:21:26 -0700 Subject: [PATCH 09/12] Add a way to specify the network adapter type --- lib/vagrant-vcenter/action/build_vm.rb | 28 ++++++++++++++++++++++++++ lib/vagrant-vcenter/config.rb | 22 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/vagrant-vcenter/action/build_vm.rb b/lib/vagrant-vcenter/action/build_vm.rb index 72106a2..f5ea14d 100644 --- a/lib/vagrant-vcenter/action/build_vm.rb +++ b/lib/vagrant-vcenter/action/build_vm.rb @@ -93,6 +93,34 @@ def call(env) :location => relocate_spec, :powerOn => false, :template => false) + + if config.vm_network_name or config.num_cpu or config.memory + config_spec = RbVmomi::VIM.VirtualMachineConfigSpec + config_spec.numCPUs = config.num_cpu if config.num_cpu + config_spec.memoryMB = config.memory if config.memory + + if config.vm_network_name + # First we must find the specified network + network = dc.network.find { |f| f.name == config.vm_network_name } or + abort "Could not find network with name #{config.vm_network_name} to join vm to" + card = template.config.hardware.device.grep( + RbVmomi::VIM::VirtualEthernetCard).first or + abort "could not find network card to customize" + if config.vm_network_type == "DistributedVirtualSwitchPort" + switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection( + :switchUuid => network.config.distributedVirtualSwitch.uuid, + :portgroupKey => network.key) + card.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo( + :port => switch_port) + else + abort "vm network type of #{config.vm_network_type} is unknown" + end + dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(:device => card, :operation => "edit") + config_spec.deviceChange = [dev_spec] + end + + spec.config = config_spec + end if config.enable_vm_customization or config.enable_vm_customization == 'true' gIPSettings = RbVmomi::VIM.CustomizationGlobalIPSettings( diff --git a/lib/vagrant-vcenter/config.rb b/lib/vagrant-vcenter/config.rb index aab1295..8daa5b2 100644 --- a/lib/vagrant-vcenter/config.rb +++ b/lib/vagrant-vcenter/config.rb @@ -102,6 +102,28 @@ class Config < Vagrant.plugin('2', :config) # @return [String] attr_accessor :ipaddress + # vm network name + # + # @return [String] + attr_accessor :vm_network_name + + # vm network type + # only supported network type + # DistributedVirtualSwitchPort + # + # @return [String] + attr_accessor :vm_network_type + + # num cpu + # + # @return [Fixnum] + attr_accessor :num_cpu + + # memory in MB + # + # @return [Fixnum] + attr_accessor :memory + ## From e8c695c7fc0a8ad619ba0bd6eed74dbce924ba31 Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Thu, 12 Jun 2014 10:30:11 -0700 Subject: [PATCH 10/12] Revert "If you delete a vm and hope to have vagrant recreate it. it wont. Check for it really existing in the inventory and not just in the box file" This reverts commit cc391043fe3b1f877753e00b510bc7232929ef51. Conflicts: lib/vagrant-vcenter/action/is_created.rb --- lib/vagrant-vcenter/action/is_created.rb | 11 ----------- lib/vagrant-vcenter/action/read_state.rb | 14 +++++--------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/vagrant-vcenter/action/is_created.rb b/lib/vagrant-vcenter/action/is_created.rb index 3c83758..8f128ec 100644 --- a/lib/vagrant-vcenter/action/is_created.rb +++ b/lib/vagrant-vcenter/action/is_created.rb @@ -10,18 +10,7 @@ def initialize(app, env) def call(env) vm_id = env[:machine].id - config = env[:machine].provider_config if vm_id - if config.vcenter_cnx - dc = config.vcenter_cnx.serviceInstance.find_datacenter( - config.datacenter_name) or abort 'datacenter not found' - root_vm_folder = dc.vmFolder - vm = root_vm_folder.findByUuid(env[:machine].id) - if not vm - @logger.warn('VM has not been created') - env[:result] = false - end - end @logger.info("VM has been created and ID is: [#{vm_id}]") env[:result] = true else diff --git a/lib/vagrant-vcenter/action/read_state.rb b/lib/vagrant-vcenter/action/read_state.rb index 4abf150..57ea2f9 100644 --- a/lib/vagrant-vcenter/action/read_state.rb +++ b/lib/vagrant-vcenter/action/read_state.rb @@ -18,12 +18,6 @@ def call(env) def read_state(env) # FIXME: this part needs some cleanup config = env[:machine].provider_config - vm_name = env[:machine].name - - if env[:machine].id.nil? - @logger.info("VM [#{vm_name}] is not created yet") - return :not_created - end # FIXME: Raise a correct exception dc = config.vcenter_cnx.serviceInstance.find_datacenter( @@ -32,13 +26,15 @@ def read_state(env) root_vm_folder = dc.vmFolder vm = root_vm_folder.findByUuid(env[:machine].id) - if not vm + + @logger.debug("Current power state: #{vm.runtime.powerState}") + vm_name = env[:machine].name + + if env[:machine].id.nil? @logger.info("VM [#{vm_name}] is not created yet") return :not_created end - @logger.debug("Current power state: #{vm.runtime.powerState}") - if vm.runtime.powerState == 'poweredOff' @logger.info("VM [#{vm_name}] is stopped") return :stopped From 173b0c43ebdc8bc1dbd447b4d74a63d43f32c8e9 Mon Sep 17 00:00:00 2001 From: Karl Pietri Date: Thu, 12 Jun 2014 10:57:04 -0700 Subject: [PATCH 11/12] Revert "make sure we are connected during the first test if the vm is created during up action. also only test if the vm actually exists if we are connected to handle the rest of the actions" This reverts commit 6e8d064c2072bc7d582748dad2321779dd52c5f9. Conflicts: lib/vagrant-vcenter/action/is_created.rb --- lib/vagrant-vcenter/action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-vcenter/action.rb b/lib/vagrant-vcenter/action.rb index 0cd34f7..7950a5d 100644 --- a/lib/vagrant-vcenter/action.rb +++ b/lib/vagrant-vcenter/action.rb @@ -170,10 +170,10 @@ def self.action_ssh_run def self.action_up Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate - b.use ConnectvCenter b.use Call, IsCreated do |env, b2| b2.use HandleBox unless env[:result] end + b.use ConnectvCenter b.use InventoryCheck b.use Call, IsCreated do |env, b2| b2.use BuildVM unless env[:result] From 283fb403ff2237151e7eba1fa6751818051a3eae Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Mon, 16 Jun 2014 11:08:06 +0900 Subject: [PATCH 12/12] Version bump --- README.md | 19 ++++++++++++++++++- lib/vagrant-vcenter/version.rb | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 03fa370..c4567a1 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,30 @@ [Vagrant](http://www.vagrantup.com) provider for VMware vCenter® ============= -[Version 0.1.1](../../releases/tag/v0.1.1) has been released! +[Version 0.2.0](../../releases/tag/v0.2.0) has been released! ------------- Please note that this software is still Alpha/Beta quality and is not recommended for production usage. Right now a [Precise32](http://vagrant.gosddc.com/boxes/precise32-vcenter.box) is available for use, or you can roll your own as you please, make sure to install VMware tools in it. +Changes in [version 0.2.0](../../releases/tag/v0.2.0) include: + +New Features + +- Add option to set the actual vm name +- Set some options in the vm via linux prep +- Static networking +- Hostname +- Add option to set vmnetwork name and backing +- Vagrant now uses builtin ```SyncedFolders``` helper to synchronize folders + +Fixes + +- Fix the read_ssh_info if the vm doesn't have a network yet at first try the later ssh's wont forever fail + +Many thanks to @BarnacleBob for submitting PR #4 with all these new features! + Changes in [version 0.1.1](../../releases/tag/v0.1.1) include: - Support for ```vagrant share``` [Fixes [#2](../../issues/2)] diff --git a/lib/vagrant-vcenter/version.rb b/lib/vagrant-vcenter/version.rb index 1a93ea8..b612640 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.1.1' + VERSION = '0.2.0' end end