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

Commit aeb98ec

Browse files
evanchaolijrgarcia
authored andcommitted
vim.rb: enhance the logic of vim.rev. (#139)
* 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".
1 parent 8df487b commit aeb98ec

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/rbvmomi/vim.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def self.connect opts
3939
opts[:port] ||= (opts[:ssl] ? 443 : 80)
4040
opts[:path] ||= '/sdk'
4141
opts[:ns] ||= 'urn:vim25'
42-
rev_given = opts[:rev] != nil
43-
opts[:rev] = '6.5' unless rev_given
42+
opts[:rev] = '6.5' if opts[:rev].nil?
4443
opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
4544

4645
conn = new(opts).tap do |vim|
@@ -61,10 +60,8 @@ def self.connect opts
6160
vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
6261
end
6362
end
64-
unless rev_given
65-
rev = vim.serviceContent.about.apiVersion
66-
vim.rev = [rev, '6.5'].min
67-
end
63+
rev = vim.serviceContent.about.apiVersion
64+
vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
6865
end
6966

7067
at_exit { conn.close }

0 commit comments

Comments
 (0)