Skip to content

Commit

Permalink
Implement 'session.get' vPoller method for getting the established se…
Browse files Browse the repository at this point in the history
…ssions
  • Loading branch information
dnaeon committed Sep 24, 2014
1 parent b2b8741 commit f9795a8
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def __init__(self, user, pwd, host):
'method': self.event_latest,
'required': ['hostname'],
},
'session.get': {
'method': self.session_get,
'required': ['hostname'],
},
'net.discover': {
'method': self.net_discover,
'required': ['hostname'],
Expand Down Expand Up @@ -513,6 +517,63 @@ def about(self, msg):

return result

def session_get(self, msg):
"""
Get the established vSphere sessions
Example client message would be:
{
"method": "session.get",
"hostname": "vc01.example.org",
}
Returns:
The established vSphere sessions in JSON format
"""
logging.info('[%s] Retrieving established sessions', self.host)

try:
sm = self.si.content.sessionManager
session_list = sm.sessionList
except pyVmomi.vim.NoPermission:
return {
'msg': 'No permissions to view established sessions',
'success': 1
}

# Session properties to be collected
props = [
'key',
'userName',
'fullName',
'loginTime',
'lastActiveTime',
'ipAddress',
'userAgent',
'callCount'
]

sessions = []
for session in session_list:
s = {k: str(getattr(session, k)) for k in props}
sessions.append(s)

result = {
'msg': 'Successfully retrieved sessions',
'success': 0,
'result': sessions,
}

logging.debug(
'[%s] Returning result from operation: %s',
self.host,
result
)

return result

def net_discover(self, msg):
"""
Discover all pyVmomi.vim.Network managed objects
Expand Down

0 comments on commit f9795a8

Please sign in to comment.