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

Commit

Permalink
vim.rb: enhance the logic of vim.rev. (#139)
Browse files Browse the repository at this point in the history
* vim.rb: enhance the logic of vim.rev.

1. No matter if rev is specified when calls RbVmomi.connect, vim.rev
   should be real version that effects current VIM connection.

   Without this fix, say, vSphere is 6.5, and we give 7.0 to
   RbVmomi.connect, then returned vim.rev will be 7.0. Even if we
   give 100.0, obviously 100.0 is not a reasonable vSphere version,
   returned vim.rev will be 100.0.

   With this fix, returned vim.rev will be min value of vSphere
   version and specified rev.

2. Enhanced version comparison.

   Without this fix, version comparison is done by string comparison,
   as a result "100.0" is smaller than "6.0". vSphere version has
   reached to 8.x, once it reaches to "10.0", this bug will be
   triggered.

   With this fix, a version number is split into parts by ".", then
   compare each part from left to right, so that "10.0" is bigger
   than "6.0".

* Revert "vim.rb: enhance the logic of vim.rev."

This reverts commit 4efb0be.

* vim.rb: enhance the logic of vim.rev.

1. No matter if rev is specified when calls RbVmomi.connect, vim.rev
   should be real version that effects current VIM connection.

   Without this fix, say, vSphere is 6.5, and we give 7.0 to
   RbVmomi.connect, then returned vim.rev will be 7.0. Even if we
   give 100.0, obviously 100.0 is not a reasonable vSphere version,
   returned vim.rev will be 100.0.

   With this fix, returned vim.rev will be min value of vSphere
   version and specified rev.

2. Enhanced version comparison.

   Without this fix, version comparison is done by string comparison,
   as a result "100.0" is smaller than "6.0". vSphere version has
   reached to 8.x, once it reaches to "10.0", this bug will be
   triggered.

   With this fix, a version number is split into parts by ".", then
   compare each part from left to right, so that "10.0" is bigger
   than "6.0".
  • Loading branch information
evanchaoli authored and jrgarcia committed Jun 12, 2018
1 parent 8df487b commit aeb98ec
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/rbvmomi/vim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def self.connect opts
opts[:port] ||= (opts[:ssl] ? 443 : 80)
opts[:path] ||= '/sdk'
opts[:ns] ||= 'urn:vim25'
rev_given = opts[:rev] != nil
opts[:rev] = '6.5' unless rev_given
opts[:rev] = '6.5' if opts[:rev].nil?
opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug

conn = new(opts).tap do |vim|
Expand All @@ -61,10 +60,8 @@ def self.connect opts
vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
end
end
unless rev_given
rev = vim.serviceContent.about.apiVersion
vim.rev = [rev, '6.5'].min
end
rev = vim.serviceContent.about.apiVersion
vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
end

at_exit { conn.close }
Expand Down

0 comments on commit aeb98ec

Please sign in to comment.