[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:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user