Add support for SUSPEND/ENABLE to HAProxy driver.

SUSPEND just stops HAProxy, and ENABLE starts it. Added code to
catch exceptions if either of these actions fail.
This commit is contained in:
David Shrewsbury 2012-10-08 16:53:52 -04:00
parent 754af827f9
commit 983eb4a06b
2 changed files with 34 additions and 2 deletions

View File

@ -98,8 +98,7 @@ class LBaaSController(object):
lb_node['condition'] = self.NODE_ERR
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
except Exception as e:
self.logger.error("Failure activating changes: %s, %s" %
(e.__class__, e))
self.logger.error("CREATE failed: %s, %s" % (e.__class__, e))
for lb_node in self.msg['nodes']:
lb_node['condition'] = self.NODE_ERR
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
@ -125,6 +124,9 @@ class LBaaSController(object):
"Selected driver does not support SUSPEND action."
)
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
except Exception as e:
self.logger.error("SUSPEND failed: %s, %s" % (e.__class__, e))
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
else:
self.msg['hpcs_response'] = self.RESPONSE_SUCCESS
return self.msg
@ -138,6 +140,9 @@ class LBaaSController(object):
"Selected driver does not support ENABLE action."
)
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
except Exception as e:
self.logger.error("ENABLE failed: %s, %s" % (e.__class__, e))
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
else:
self.msg['hpcs_response'] = self.RESPONSE_SUCCESS
return self.msg
@ -151,6 +156,9 @@ class LBaaSController(object):
"Selected driver does not support DELETE action."
)
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
except Exception as e:
self.logger.error("DELETE failed: %s, %s" % (e.__class__, e))
self.msg['hpcs_response'] = self.RESPONSE_FAILURE
else:
self.msg['hpcs_response'] = self.RESPONSE_SUCCESS
return self.msg

View File

@ -103,6 +103,24 @@ class HAProxyDriver(LoadBalancerDriver):
raise Exception("Failed to restart HAProxy service: %s" %
e.output.rstrip('\n'))
def _stop(self):
""" Stop the HAProxy service on the local machine. """
cmd = '/usr/bin/sudo /usr/sbin/service haproxy stop'
try:
subprocess.check_output(cmd.split())
except subprocess.CalledProcessError as e:
raise Exception("Failed to stop HAProxy service: %s" %
e.output.rstrip('\n'))
def _start(self):
""" Start the HAProxy service on the local machine. """
cmd = '/usr/bin/sudo /usr/sbin/service haproxy start'
try:
subprocess.check_output(cmd.split())
except subprocess.CalledProcessError as e:
raise Exception("Failed to start HAProxy service: %s" %
e.output.rstrip('\n'))
####################
# Driver API Methods
####################
@ -119,3 +137,9 @@ class HAProxyDriver(LoadBalancerDriver):
def create(self):
self._write_config()
self._restart()
def suspend(self):
self._stop()
def enable(self):
self._start()