Skip to content

Commit

Permalink
From now on the VPollerWorker uses VConnector instances instead of VS…
Browse files Browse the repository at this point in the history
…phereAgent ones
  • Loading branch information
dnaeon committed Jan 28, 2015
1 parent 7b06f05 commit b84fdb2
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
vPoller Worker module for the VMware vSphere Poller
vPoller Worker module
"""

Expand All @@ -41,12 +41,14 @@
import zmq

from vpoller import __version__
from vpoller.agent import VSphereAgent
from vpoller.exceptions import VPollerException
from vpoller.log import logger
from vpoller.registry import registry
from vpoller.exceptions import VPollerException
from vpoller.task.registry import registry
from vconnector.core import VConnector
from vconnector.core import VConnectorDatabase

__all__ = ['VPollerWorkerManager', 'VPollerWorker']


class VPollerWorkerManager(object):
"""
Expand Down Expand Up @@ -528,7 +530,7 @@ def create_agents(self):
)

for agent in agents:
a = VSphereAgent(
a = VConnector(
user=agent['user'],
pwd=agent['pwd'],
host=agent['host']
Expand All @@ -553,6 +555,9 @@ def process_client_msg(self, msg):
The message is passed to the VSphereAgent object of the
respective vSphere host in order to do the actual polling.
Args:
msg (dict): Client message for processing
An example message for discovering the hosts could be:
{
Expand All @@ -569,43 +574,29 @@ def process_client_msg(self, msg):
"property": "summary.capacity"
}
Args:
msg (dict): Client message for processing
"""
logger.debug('Processing client message: %s', msg)

# Check whether the client message is a valid one
if not isinstance(msg, dict):
return {
'success': 1,
'msg': 'Expected a JSON message, received %s' % msg.__class__
'msg': 'Expected a JSON message, received {}'.format(msg.__class__)
}

if 'method' not in msg:
return {'success': 1, 'msg': 'Missing method name'}
task = registry.get(msg.get('method'))
agent = self.agents.get(msg.get('hostname'))

# Get the vSphere Agent object for handling this request
requested_method = msg.get('method')
requested_agent = msg.get('hostname')
agent = self.agents.get(requested_agent)
if not task:
return {'success': 1, 'msg': 'Unknown or missing task/method name'}

if not agent:
return {
'success': 1,
'msg': 'Unknown or missing vSphere Agent requested'
}

agent_method = agent.agent_methods.get(requested_method)

if not agent_method:
return {'success': 1, 'msg': 'Unknown method name requested'}
return {'success': 1, 'msg': 'Unknown or missing agent name'}

# Validate client message for required message attributes and type
required = agent.agent_methods.get(requested_method)['required']
if not agent._validate_client_msg(msg, required):
return {'success': 1, 'msg': 'Incorrect task request received'}

result = agent_method['method'](msg)
#
#if not _validate_client_msg(msg, task.required):
# return {'success': 1, 'msg': 'Incorrect task request received'}
#

result = task.function(agent, msg)

return result

0 comments on commit b84fdb2

Please sign in to comment.