lib/rbvmomi/vim.rb in rbvmomi-1.9.4 vs lib/rbvmomi/vim.rb in rbvmomi-1.9.5
- old
+ new
@@ -1,6 +1,8 @@
-# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
+# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
+# SPDX-License-Identifier: MIT
+
require 'rbvmomi'
# Win32::SSPI is part of core on Windows
begin
require 'win32/sspi'
@@ -38,11 +40,11 @@
opts[:ns] ||= 'urn:vim25'
rev_given = opts[:rev] != nil
opts[:rev] = '6.0' unless rev_given
opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
- new(opts).tap do |vim|
+ conn = new(opts).tap do |vim|
unless opts[:cookie]
if WIN32 && opts[:password] == ''
# Attempt login by SSPI if no password specified on Windows
negotiation = Win32::SSPI::NegotiateAuth.new opts[:user], ENV['USERDOMAIN'].dup
begin
@@ -61,13 +63,19 @@
unless rev_given
rev = vim.serviceContent.about.apiVersion
vim.rev = [rev, '6.0'].min
end
end
+
+ at_exit { conn.close }
+ conn
end
def close
- VIM::SessionManager(self, 'SessionManager').Logout rescue RbVmomi::Fault
+ serviceContent.sessionManager.Logout
+ rescue RbVmomi::Fault => e
+ $stderr.puts(e.message) if debug
+ ensure
self.cookie = nil
super
end
def rev= x