Hi,
I'm calling ImpersonateUser method on root connection and I get the userSession handle as the return value. When I print the userSession (return value) it shows the userName property of impersonated user. But, if I print currentSession from con.sc.sessionManager It shows the userName as root and the currentSession doesn't change for 5 minutes even after calling con.si.flush_cache(). If I do any operation after the ImpersonateUser call, task shows correctly as being submitted by Impersonated user both in
task.info and on vCenter.
For the ImpersonateUser call to succeed, a Connection(Client) must have been established using impersonating user/password either by this or any other session. Meaning, it should appear in sm.sessionList output. If not, ImpersonateUser call fails.
My questions are
1. Is this behavior because of caching?
1. If yes, how do I clear the cache so that sm.currentSession shows correct value?
2. Why is Connection(Client) for impersonating user mandatory? Doesn't it defeat the purpose of ImpersonateUser call? The reason we want to use ImpersonateUser is we don't have keep/manage the passwords. If I have to create the connection, I might as well do a Client connection instead of ImpersonateUser. What is the benefit the ImpersonateUser if I have to create a Client connection.
Below is the output of above description
# python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from psphere.client import Client
>>> from psphere.managedobjects import HostSystem, VirtualMachine
>>> from datetime import datetime
>>>
>>> con = Client("192.168.1.10", "root", "password")
Logging to ~/.psphere/psphere.log at WARN level
>>> sm = con.sc.sessionManager
>>>
>>> print sm.currentSession
(UserSession){
key = "52765d2e-2efe-fec1-58ea-e9ef6636ba0a"
userName = "root"
fullName = "root"
loginTime = 2013-05-22 21:03:57.842754
lastActiveTime = 2013-05-22 21:03:57.842754
locale = "en"
messageLocale = "en"
}
>>>
>>> us=sm.ImpersonateUser(userName="john")
>>> print us
(UserSession){
key = "52765d2e-2efe-fec1-58ea-e9ef6636ba0a"
userName = "john"
fullName = None
loginTime = 2013-05-22 21:04:26.700352
lastActiveTime = 2013-05-22 21:04:26.700352
locale = "en"
messageLocale = "en"
}
>>>
>>> con.si.flush_cache()
>>> sm = con.sc.sessionManager
>>>
>>> print datetime.now()
2013-05-22 14:57:29.722573
>>> print sm.currentSession
(UserSession){
key = "52765d2e-2efe-fec1-58ea-e9ef6636ba0a"
userName = "root"
fullName = "root"
loginTime = 2013-05-22 21:03:57.842754
lastActiveTime = 2013-05-22 21:03:57.842754
locale = "en"
messageLocale = "en"
}
>>>
>>> vm=VirtualMachine.all(con)[0]
>>> t=vm.PowerOnVM_Task()
>>> print t.info
(TaskInfo){
key = "task-8807"
task = <psphere.managedobjects.Task object at 0xe9532ac>
name = "PowerOnVM_Task"
descriptionId = "VirtualMachine.powerOn"
entity = <psphere.managedobjects.VirtualMachine object at 0xe95352c>
entityName = "k1"
state = "success"
cancelled = False
cancelable = False
reason =
(TaskReasonUser){
userName = "john"
}
queueTime = 2013-05-22 21:06:46.051443
startTime = 2013-05-22 21:06:46.007295
completeTime = 2013-05-22 21:06:48.131416
eventChainId = 60268
}
>>>
>>> print datetime.now()
2013-05-22 15:01:05.586585
>>> print sm.currentSession
(UserSession){
key = "52765d2e-2efe-fec1-58ea-e9ef6636ba0a"
userName = "root"
fullName = "root"
loginTime = 2013-05-22 21:03:57.842754
lastActiveTime = 2013-05-22 21:03:57.842754
locale = "en"
messageLocale = "en"
}
>>>
>>> print datetime.now()
2013-05-22 15:02:28.530583
>>> print sm.currentSession
(UserSession){
key = "52765d2e-2efe-fec1-58ea-e9ef6636ba0a"
userName = "john"
fullName = None
loginTime = 2013-05-22 21:04:26.700352
lastActiveTime = 2013-05-22 21:06:46.051168
locale = "en"
messageLocale = "en"
}
>>> Regards,
RS