From 3c5081cd3f89d2635e7074c62b7ee48ef871dfac Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Thu, 7 Nov 2013 16:21:19 -0500 Subject: [PATCH] [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 --- libra/worker/controller.py | 20 ++++++++++--------- libra/worker/drivers/base.py | 4 ++-- libra/worker/drivers/haproxy/driver.py | 4 ++-- .../worker/drivers/haproxy/ubuntu_services.py | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libra/worker/controller.py b/libra/worker/controller.py index 355db006..70d0c11b 100644 --- a/libra/worker/controller.py +++ b/libra/worker/controller.py @@ -69,7 +69,10 @@ class LBaaSController(object): elif action == 'ARCHIVE': return self._action_archive() 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': return self._action_diagnostic() else: @@ -438,29 +441,28 @@ class LBaaSController(object): self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS 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 - 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. """ try: - # TODO: Do something with the returned statistics - stats = self.driver.get_stats() + stats = self.driver.get_status() except NotImplementedError: - error = "Selected driver does not support STATS action." + error = "Selected driver does not support PING action." self.logger.error(error) self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = error 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[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE 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.ERROR_FIELD] = str(e) else: diff --git a/libra/worker/drivers/base.py b/libra/worker/drivers/base.py index b13c0d1e..003997ac 100644 --- a/libra/worker/drivers/base.py +++ b/libra/worker/drivers/base.py @@ -96,8 +96,8 @@ class LoadBalancerDriver(object): """ Delete a load balancer. """ raise NotImplementedError() - def get_stats(self, protocol): - """ Get load balancer statistics for specified protocol. """ + def get_status(self, protocol): + """ Get load balancer status for specified protocol. """ raise NotImplementedError() def archive(self, method, params): diff --git a/libra/worker/drivers/haproxy/driver.py b/libra/worker/drivers/haproxy/driver.py index 1fccf574..a5be917b 100644 --- a/libra/worker/drivers/haproxy/driver.py +++ b/libra/worker/drivers/haproxy/driver.py @@ -393,8 +393,8 @@ class HAProxyDriver(LoadBalancerDriver): # restart, otherwise the log file will be kept open and not reappear. self.ossvc.syslog_restart() - def get_stats(self, protocol=None): - return self.ossvc.get_stats(protocol) + def get_status(self, protocol=None): + return self.ossvc.get_status(protocol) def archive(self, method, params): """ diff --git a/libra/worker/drivers/haproxy/ubuntu_services.py b/libra/worker/drivers/haproxy/ubuntu_services.py index ff009b74..8e9b9bab 100644 --- a/libra/worker/drivers/haproxy/ubuntu_services.py +++ b/libra/worker/drivers/haproxy/ubuntu_services.py @@ -146,9 +146,9 @@ class UbuntuServices(ServicesBase): self.sudo_rm(self._config_file) 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 One of the supported protocol names (http or tcp).