lib/rbvmomi/vim.rb in rbvmomi-1.6.0 vs lib/rbvmomi/vim.rb in rbvmomi-1.8.0

- old
+ new

@@ -11,17 +11,19 @@ # @param [Hash] opts The options hash. # @option opts [String] :host Host to connect to. # @option opts [Numeric] :port (443) Port to connect to. # @option opts [Boolean] :ssl (true) Whether to use SSL. # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors. + # @option opts [String] :cookie If set, use cookie to connect instead of user/password # @option opts [String] :user (root) Username. # @option opts [String] :password Password. # @option opts [String] :path (/sdk) SDK endpoint path. # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr. def self.connect opts fail unless opts.is_a? Hash fail "host option required" unless opts[:host] + opts[:cookie] ||= nil opts[:user] ||= 'root' opts[:password] ||= '' opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"] opts[:insecure] ||= false opts[:port] ||= (opts[:ssl] ? 443 : 80) @@ -30,24 +32,26 @@ rev_given = opts[:rev] != nil opts[:rev] = '4.0' unless rev_given opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug new(opts).tap do |vim| - vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password] + unless opts[:cookie] + vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password] + end unless rev_given rev = vim.serviceContent.about.apiVersion - vim.rev = [rev, '5.0'].min + vim.rev = [rev, '5.5'].min end end end def close VIM::SessionManager(self, 'SessionManager').Logout rescue RbVmomi::Fault self.cookie = nil super end - + def rev= x super @serviceContent = nil end @@ -82,9 +86,38 @@ end # @private def pretty_print pp pp.text "VIM(#{@opts[:host]})" + end + + def instanceUuid + serviceContent.about.instanceUuid + end + + def get_log_lines logKey, lines=5, start=nil, host=nil + diagMgr = self.serviceContent.diagnosticManager + if !start + log = diagMgr.BrowseDiagnosticLog(host: host, key: logKey, start: 999999999) + lineEnd = log.lineEnd + start = lineEnd - lines + end + start = start < 0 ? 0 : start + log = diagMgr.BrowseDiagnosticLog(host: host, key: logKey, start: start) + if log.lineText.size > 0 + [log.lineText.slice(-lines, log.lineText.size), log.lineEnd] + else + [log.lineText, log.lineEnd] + end + end + + def get_log_keys host=nil + diagMgr = self.serviceContent.diagnosticManager + keys = [] + diagMgr.QueryDescriptions(host: host).each do |desc| + keys << "#{desc.key}" + end + keys end add_extension_dir File.join(File.dirname(__FILE__), "vim") (ENV['RBVMOMI_VIM_EXTENSION_PATH']||'').split(':').each { |dir| add_extension_dir dir }