Class: VMware::Session
- Inherits:
-
Object
- Object
- VMware::Session
- Defined in:
- lib/vmware/session.rb
Overview
A session incorporates the API specific state of the server connection.
Instance Attribute Summary collapse
-
#sic ⇒ Object
readonly
Service content object provides our root to the object hierarchy.
Instance Method Summary collapse
-
#initialize(connection) ⇒ Session
constructor
Create a new session by connecting to the server, getting the service instance and logging in.
-
#login ⇒ Object
Login to the server.
-
#managed_object_wrapper_factory(type, reference) ⇒ Object
Based on the type of a ManagedObjectReference, generate the appropriate wrapper instance.
-
#method_missing(methodSymbol, *params) ⇒ Object
Catch any function call and send it over the soap connection.
-
#root_folder ⇒ Object
Return the root folder of the inventory hierarchy.
Constructor Details
#initialize(connection) ⇒ Session
Create a new session by connecting to the server, getting the service instance and logging in.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vmware/session.rb', line 17 def initialize(connection) @connection = connection svcref = ManagedObjectReference.new("ServiceInstance") svcref.xmlattr_type = "ServiceInstance" retrieveServiceContent = RetrieveServiceContentRequestType.new(svcref) @sic = connection.retrieveServiceContent(retrieveServiceContent).returnval login end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodSymbol, *params) ⇒ Object
Catch any function call and send it over the soap connection.
64 65 66 |
# File 'lib/vmware/session.rb', line 64 def method_missing(methodSymbol, *params) @connection.send(methodSymbol, *params) end |
Instance Attribute Details
#sic ⇒ Object (readonly)
Service content object provides our root to the object hierarchy.
11 12 13 |
# File 'lib/vmware/session.rb', line 11 def sic @sic end |
Instance Method Details
#login ⇒ Object
Login to the server.
38 39 40 41 42 43 |
# File 'lib/vmware/session.rb', line 38 def login loginRequest = LoginRequestType.new(@sic.sessionManager) loginRequest.userName = @connection.username loginRequest.password = @connection.password @connection.login(loginRequest); end |
#managed_object_wrapper_factory(type, reference) ⇒ Object
Based on the type of a ManagedObjectReference, generate the appropriate wrapper instance.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vmware/session.rb', line 49 def managed_object_wrapper_factory(type, reference) # # If we know about the type try to instantiate it. # begin eval("VMware::#{type}.new(self, reference)") rescue puts "WARNING: Unknown managed object type: #{type}" VMware::ManagedEntity.new(self, reference) end end |
#root_folder ⇒ Object
Return the root folder of the inventory hierarchy.
31 32 33 |
# File 'lib/vmware/session.rb', line 31 def root_folder managed_object_wrapper_factory("Folder", @sic.rootFolder) end |