Class: RbVmomi::VIM
- Inherits:
-
Connection
- Object
- TrivialSoap
- Connection
- RbVmomi::VIM
- Defined in:
- lib/rbvmomi/vim.rb
Overview
A connection to one vSphere SDK endpoint.
Defined Under Namespace
Classes: ComputeResource, Datacenter, Datastore, DynamicTypeMgrAllTypeInfo, DynamicTypeMgrDataTypeInfo, DynamicTypeMgrManagedTypeInfo, EsxcliCommand, EsxcliNamespace, Folder, HostSystem, ManagedEntity, ManagedObject, ObjectContent, ObjectUpdate, OvfManager, PerfCounterInfo, PerformanceManager, PropertyCollector, ReflectManagedMethodExecuter, ResourcePool, ServiceInstance, Task, VirtualMachine
Constant Summary
Constants inherited from Connection
Instance Attribute Summary
Attributes inherited from Connection
#deserializer, #profile, #profile_summary, #profiling, #rev
Attributes inherited from TrivialSoap
#cookie, #debug, #http, #operation_id
Class Method Summary collapse
-
.connect(opts) ⇒ Object
Connect to a vSphere SDK endpoint.
Instance Method Summary collapse
- #close ⇒ Object
- #get_log_keys(host = nil) ⇒ Object
- #get_log_lines(logKey, lines = 5, start = nil, host = nil) ⇒ Object
- #instanceUuid ⇒ Object
- #pretty_print(pp) ⇒ Object
-
#propertyCollector ⇒ Object
Alias to serviceContent.propertyCollector.
- #rev=(x) ⇒ Object
-
#rootFolder ⇒ Object
(also: #root)
Alias to serviceContent.rootFolder.
-
#searchIndex ⇒ Object
Alias to serviceContent.searchIndex.
-
#serviceContent ⇒ Object
Alias to serviceInstance.RetrieveServiceContent.
-
#serviceInstance ⇒ Object
Return the ServiceInstance.
Methods inherited from Connection
add_extension_dir, #call, #emit_request, extension_dirs, #initialize, loader, #obj2xml, #parse_response, reload_extensions, #reset_profiling, type, #type
Methods inherited from TrivialSoap
#host, #initialize, on_connect, #request, #restart_http, #soap_envelope
Constructor Details
This class inherits a constructor from RbVmomi::Connection
Class Method Details
.connect(opts) ⇒ Object
Connect to a vSphere SDK endpoint
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rbvmomi/vim.rb', line 31 def self.connect opts fail unless opts.is_a? Hash fail "host option required" unless opts[:host] opts[:cookie] ||= nil opts[:user] ||= (WIN32 ? ENV['USERNAME'].dup : 'root') opts[:password] ||= '' opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"] opts[:insecure] ||= false opts[:port] ||= (opts[:ssl] ? 443 : 80) opts[:path] ||= '/sdk' opts[:ns] ||= 'urn:vim25' 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| 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 vim.serviceContent.sessionManager.LoginBySSPI :base64Token => negotiation.get_initial_token rescue RbVmomi::Fault => fault if !fault.fault.is_a?(RbVmomi::VIM::SSPIChallenge) raise else vim.serviceContent.sessionManager.LoginBySSPI :base64Token => negotiation.complete_authentication(fault.base64Token) end end else vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password] end 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 } conn end |
Instance Method Details
#close ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/rbvmomi/vim.rb', line 71 def close serviceContent.sessionManager.Logout rescue RbVmomi::Fault => e $stderr.puts(e.) if debug ensure self. = nil super end |
#get_log_keys(host = nil) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/rbvmomi/vim.rb', line 140 def get_log_keys host=nil diagMgr = self.serviceContent.diagnosticManager keys = [] diagMgr.QueryDescriptions(:host => host).each do |desc| keys << "#{desc.key}" end keys end |
#get_log_lines(logKey, lines = 5, start = nil, host = nil) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rbvmomi/vim.rb', line 124 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 |
#instanceUuid ⇒ Object
120 121 122 |
# File 'lib/rbvmomi/vim.rb', line 120 def instanceUuid serviceContent.about.instanceUuid end |
#pretty_print(pp) ⇒ Object
116 117 118 |
# File 'lib/rbvmomi/vim.rb', line 116 def pretty_print pp pp.text "VIM(#{@opts[:host]})" end |
#propertyCollector ⇒ Object
Alias to serviceContent.propertyCollector
106 107 108 |
# File 'lib/rbvmomi/vim.rb', line 106 def propertyCollector serviceContent.propertyCollector end |
#rev=(x) ⇒ Object
80 81 82 83 |
# File 'lib/rbvmomi/vim.rb', line 80 def rev= x super @serviceContent = nil end |
#rootFolder ⇒ Object Also known as: root
Alias to serviceContent.rootFolder
99 100 101 |
# File 'lib/rbvmomi/vim.rb', line 99 def rootFolder serviceContent.rootFolder end |
#searchIndex ⇒ Object
Alias to serviceContent.searchIndex
111 112 113 |
# File 'lib/rbvmomi/vim.rb', line 111 def searchIndex serviceContent.searchIndex end |
#serviceContent ⇒ Object
Alias to serviceInstance.RetrieveServiceContent
94 95 96 |
# File 'lib/rbvmomi/vim.rb', line 94 def serviceContent @serviceContent ||= serviceInstance.RetrieveServiceContent end |
#serviceInstance ⇒ Object
Return the ServiceInstance
The ServiceInstance is the root of the vSphere inventory.
89 90 91 |
# File 'lib/rbvmomi/vim.rb', line 89 def serviceInstance VIM::ServiceInstance self, 'ServiceInstance' end |