Skip to content

Commit

Permalink
Add a mechanism for keeping our vSphere Agents alive
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Mar 30, 2014
1 parent 36e4534 commit 69f6006
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import types
import logging
import ConfigParser
from time import asctime
from time import time, asctime

import zmq
from vpoller.core import VPollerException
Expand Down Expand Up @@ -85,7 +85,10 @@ def run(self, config):
# Enter the main daemon loop from here
logging.debug('Entering main daemon loop')
while not self.time_to_die:
socks = dict(self.zpoller.poll())
# Keep our vSphere Agents alive
self.keep_agents_alive()

socks = dict(self.zpoller.poll(1000))

# Worker socket, receives client messages for processing
#
Expand Down Expand Up @@ -210,6 +213,7 @@ def spawn_vsphere_agents(self):
pwd=each_agent['pwd'],
host=each_agent['host']
)
agent.last_keep_alive_heartbeat = time()
self.agents[agent.host] = agent

def start_vsphere_agents(self):
Expand All @@ -222,6 +226,20 @@ def start_vsphere_agents(self):
for agent in self.agents:
self.agents[agent].connect()

def keep_agents_alive(self):
"""
Dummy method to keep our vSphere Agents alive
This dummy method calls CurrentTime() vSphere method
periodically (every 60 seconds) in order to keep the vSphere Agents alive
"""
for each_agent in self.agents:
if (time() - self.agents[each_agent].last_keep_alive_heartbeat) > 60.0:
logging.debug('[%s] Agent keep-alive heartbeat', self.agents[each_agent].host)
self.agents[each_agent].si.CurrentTime()
self.agents[each_agent].last_keep_alive_heartbeat = time()

def shutdown_vsphere_agents(self):
"""
Disconnects all vPoller Agents from their respective VMware vSphere hosts
Expand Down

0 comments on commit 69f6006

Please sign in to comment.