Skip to content

Commit

Permalink
The VMPoller daemon reads it's endpoints from the a config file
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Aug 21, 2013
1 parent 126d7cf commit eb89226
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/vmpollerd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,29 @@ class VMPollerDaemon(Daemon):
run() method
"""
def run(self, config_dir="/etc/vm-poller"):
def run(self, config_file):
"""
The main daemon loop.
The 'config_dir' argument should point to a directory containing all *.conf files
for the different vCenters we are connecting our VMPollerAgents to.
Args:
config_dir (str): A directory containing configuration files for the Agents
config_file (str): Configuration file for the VMPoller daemon
Raises:
VMPollerException
"""
if not os.path.exists(config_file):
raise VMPoller, "Configuration file %s does not exists: %s" % (config_file, e)

config = ConfigParser.ConfigParser()
config.read(config_file)

self.proxy_endpoint = config.get('Default', 'proxy_endpoint')
self.mgmt_endpoint = config.get('Default', 'mgmt_endpoint')
self.vcenter_configs = config.get('Default', 'vcenter_configs')

# Get the configuration files for our vCenters
confFiles = self.get_configs(config_dir)
confFiles = self.get_vcenter_configs(self.vcenter_configs)

# Our Agents and ZeroMQ context
self.agents = dict()
Expand All @@ -90,20 +97,19 @@ def run(self, config_dir="/etc/vm-poller"):
self.start_agents()

# Connect to our ZeroMQ proxy as a worker
# TODO: The endpoint we bind should be configurable
syslog.syslog("Connecting to the VMPoller Proxy server")
self.worker = self.zcontext.socket(zmq.REP)

try:
self.worker.connect("tcp://localhost:11556")
self.worker.connect(self.proxy_endpoint)
except zmq.ZMQError as e:
raise VMPollerException, "Cannot connect worker to proxy: %s" % e

# A management socket, used to control the VMPoller daemon
self.mgmt = self.zcontext.socket(zmq.REP)

try:
self.mgmt.bind("tcp://127.0.0.1:11560")
self.mgmt.bind(self.mgmt_endpoint)
except zmq.ZMQError as e:
raise VMPollerException, "Cannot bind management socket: %s" % e

Expand All @@ -128,13 +134,14 @@ def run(self, config_dir="/etc/vm-poller"):
self.mgmt.send_json(result)

# TODO: Proper shutdown and zmq context termination
# This should be done in the shutdown/stop command
# This should be done in the shutdown/stop sequence, e.g. through the mgmt interface
self.shutdown_agents()
self.worker.close()
self.mgmt.close()
self.zcontext.term()
self.stop()

def get_configs(self, config_dir):
def get_vcenter_configs(self, config_dir):
"""
Gets the configuration files for the vCenters
Expand Down

0 comments on commit eb89226

Please sign in to comment.