[WORKER] Support PING message

This change prepares the code to support a separation of the ping
functionality and a new statistics gathering call. This change will
see either the STATS action or the PING action as the same, so both
will be supported for the time being. Eventually, the STATS action
will have a different meaning and return info like bytes output.

Change-Id: Ib86893725818ce0e6fa57c0bb01ec6df56e4d48a
This commit is contained in:
David Shrewsbury
2013-11-07 16:21:19 -05:00
parent 91a9d4b836
commit 3c5081cd3f
4 changed files with 17 additions and 15 deletions

View File

@@ -69,7 +69,10 @@ class LBaaSController(object):
elif action == 'ARCHIVE': elif action == 'ARCHIVE':
return self._action_archive() return self._action_archive()
elif action == 'STATS': elif action == 'STATS':
return self._action_stats() # TODO: Implement new STATS function
return self._action_ping()
elif action == 'PING':
return self._action_ping()
elif action == 'DIAGNOSTICS': elif action == 'DIAGNOSTICS':
return self._action_diagnostic() return self._action_diagnostic()
else: else:
@@ -438,29 +441,28 @@ class LBaaSController(object):
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
return self.msg return self.msg
def _action_stats(self): def _action_ping(self):
""" """
Get load balancer statistics. Get load balancer and node status.
We push responsibility for knowing what state a load balancer We push responsibility for knowing what state a load balancer
current is in to the driver. Trying to get statistics for a LB that current is in to the driver. Trying to get status for a LB that
has been deleted is an error. has been deleted is an error.
""" """
try: try:
# TODO: Do something with the returned statistics stats = self.driver.get_status()
stats = self.driver.get_stats()
except NotImplementedError: except NotImplementedError:
error = "Selected driver does not support STATS action." error = "Selected driver does not support PING action."
self.logger.error(error) self.logger.error(error)
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
self.msg[self.ERROR_FIELD] = error self.msg[self.ERROR_FIELD] = error
except DeletedStateError: except DeletedStateError:
self.logger.info("Invalid operation STATS on a deleted LB") self.logger.info("Invalid operation PING on a deleted LB")
self.msg['status'] = 'DELETED' self.msg['status'] = 'DELETED'
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
except Exception as e: except Exception as e:
self.logger.error("STATS failed: %s, %s" % (e.__class__, e)) self.logger.error("PING failed: %s, %s" % (e.__class__, e))
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
self.msg[self.ERROR_FIELD] = str(e) self.msg[self.ERROR_FIELD] = str(e)
else: else:

View File

@@ -96,8 +96,8 @@ class LoadBalancerDriver(object):
""" Delete a load balancer. """ """ Delete a load balancer. """
raise NotImplementedError() raise NotImplementedError()
def get_stats(self, protocol): def get_status(self, protocol):
""" Get load balancer statistics for specified protocol. """ """ Get load balancer status for specified protocol. """
raise NotImplementedError() raise NotImplementedError()
def archive(self, method, params): def archive(self, method, params):

View File

@@ -393,8 +393,8 @@ class HAProxyDriver(LoadBalancerDriver):
# restart, otherwise the log file will be kept open and not reappear. # restart, otherwise the log file will be kept open and not reappear.
self.ossvc.syslog_restart() self.ossvc.syslog_restart()
def get_stats(self, protocol=None): def get_status(self, protocol=None):
return self.ossvc.get_stats(protocol) return self.ossvc.get_status(protocol)
def archive(self, method, params): def archive(self, method, params):
""" """

View File

@@ -146,9 +146,9 @@ class UbuntuServices(ServicesBase):
self.sudo_rm(self._config_file) self.sudo_rm(self._config_file)
self.sudo_rm(self._backup_config) self.sudo_rm(self._backup_config)
def get_stats(self, protocol=None): def get_status(self, protocol=None):
""" """
Query HAProxy socket for stats on the given protocol. Query HAProxy socket for node status on the given protocol.
protocol protocol
One of the supported protocol names (http or tcp). One of the supported protocol names (http or tcp).