diff --git a/libra/worker/controller.py b/libra/worker/controller.py index 20072ef1..94a3073a 100644 --- a/libra/worker/controller.py +++ b/libra/worker/controller.py @@ -163,7 +163,7 @@ class LBaaSController(object): return self.msg for lb_node in current_lb['nodes']: - port, address = None, None + port, address, weight = None, None, None if 'port' in lb_node: port = lb_node['port'] @@ -175,10 +175,14 @@ class LBaaSController(object): else: return BadRequest("Missing 'address' element.").to_json() + if 'weight' in lb_node: + weight = lb_node['weight'] + try: self.driver.add_server(current_lb['protocol'], address, - port) + port, + weight) except NotImplementedError: self.logger.error( "Selected driver does not support adding a server." diff --git a/libra/worker/drivers/haproxy/driver.py b/libra/worker/drivers/haproxy/driver.py index 876989d1..cd219fad 100644 --- a/libra/worker/drivers/haproxy/driver.py +++ b/libra/worker/drivers/haproxy/driver.py @@ -125,6 +125,8 @@ class HAProxyDriver(LoadBalancerDriver): def add_server(self, protocol, host, port, weight=1): proto = protocol.lower() + if weight is None: + weight = 1 try: weight = int(weight)