Add support for key=value node options
This changes allows additional node options to be defined after the ip:port portion. Format will be: IP:PORT:key=value:key=value:... First two node options supported are 'weight' and 'backup'. Also fixes a minor bug where 'raise' was being called without defining what type of exception to raise. This works ok to re-raise an existing exception, but raising a new exception requires a type. Change-Id: I9b9883d100983a242002c95378bdbb672937ed90
This commit is contained in:
parent
536b5234c2
commit
6690e8a5ef
@ -99,9 +99,10 @@ Create a load balancer
|
||||
The Galera option adds support for deadlock avoidance in Galera clusters,
|
||||
see `Serveral Nine's Blog <http://www.severalnines.com/blog/avoiding-deadlocks-galera-set-haproxy-single-node-writes-and-multi-node-reads>`_ on this.
|
||||
|
||||
.. option:: --node <ip:port>
|
||||
.. option:: --node <ip:port:option=value:...>
|
||||
|
||||
The IP and port for a load balancer node (can be used multiple times to add multiple nodes)
|
||||
The IP and port for a load balancer node (can be used multiple times to add multiple nodes).
|
||||
Additional node options may be specified after the ip:port portion in a option=value format.
|
||||
|
||||
.. option:: --vip <vip>
|
||||
|
||||
@ -226,9 +227,10 @@ Add a node to a load balancer
|
||||
|
||||
The ID of the load balancer
|
||||
|
||||
.. option:: --node <ip:port>
|
||||
.. option:: --node <ip:port:option=value:...>
|
||||
|
||||
The node address in ip:port format (can be used multiple times to add multiple nodes)
|
||||
The node address in ip:port format (can be used multiple times to add multiple nodes).
|
||||
Additional node options may be specified after the ip:port portion in a option=value format.
|
||||
|
||||
.. program:: libra_client node-delete
|
||||
|
||||
|
@ -28,6 +28,20 @@ Client will then return a table similar to the below:
|
||||
| [{u'ipVersion': u'IPV_4', u'type': u'PUBLIC', u'id': u'52', u'address': u'15.185.224.62'}] | [{u'status': u'ONLINE', u'id': u'2311', u'port': u'80', u'condition': u'ENABLED', u'address': u'192.168.1.1'}, {u'status': u'ONLINE', u'id': u'2312', u'port': u'80', u'condition': u'ENABLED', u'address': u'192.168.1.2'}] |
|
||||
+--------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
Create a Load Balancer with Node Options
|
||||
----------------------------------------
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
libra_client --os_auth_url=https://company.com/openstack/auth/url \
|
||||
--os_username=username --os_password=pasword --os_tenant_name=tenant \
|
||||
--os_region_name=region create --name=my_load_balancer \
|
||||
--node 192.168.1.1:80:weight=1 --node 192.168.1.2:80:weight=2
|
||||
|
||||
Nearly identical to the above example, this creates a new load balancer
|
||||
with two nodes, but one is more heavily weighted than the other, causing
|
||||
it to accept more traffic.
|
||||
|
||||
Create a Shared Load Balancer
|
||||
-----------------------------
|
||||
|
||||
|
@ -283,14 +283,37 @@ class LibraAPI(object):
|
||||
out_nodes = []
|
||||
try:
|
||||
for node in nodes:
|
||||
addr = node.split(':')
|
||||
nodeopts = node.split(':')
|
||||
ipaddr = nodeopts[0]
|
||||
port = nodeopts[1]
|
||||
weight, backup = None, None
|
||||
|
||||
# Test IP valid
|
||||
# TODO: change to pton when we want to support IPv6
|
||||
socket.inet_aton(addr[0])
|
||||
socket.inet_aton(ipaddr)
|
||||
# Test port valid
|
||||
if int(addr[1]) < 0 or int(addr[1]) > 65535:
|
||||
raise
|
||||
out_nodes.append({'address': addr[0], 'port': addr[1]})
|
||||
except:
|
||||
raise Exception("Invalid IP:port specified for --node")
|
||||
if int(port) < 0 or int(port) > 65535:
|
||||
raise Exception('Port out of range')
|
||||
|
||||
# Process the rest of the node options as key=value
|
||||
for kv in nodeopts[2:]:
|
||||
key, value = kv.split('=')
|
||||
key = key.lower()
|
||||
value = value.upper()
|
||||
if key == 'weight':
|
||||
weight = int(value)
|
||||
elif key == 'backup':
|
||||
backup = value # 'TRUE' or 'FALSE'
|
||||
else:
|
||||
raise Exception("Unknown node option '%s'" % key)
|
||||
|
||||
node_def = {'address': ipaddr, 'port': port}
|
||||
if weight:
|
||||
node_def['weight'] = weight
|
||||
if backup:
|
||||
node_def['backup'] = backup
|
||||
|
||||
out_nodes.append(node_def)
|
||||
except Exception as e:
|
||||
raise Exception("Invalid value specified for --node: %s" % e)
|
||||
return out_nodes
|
||||
|
Loading…
x
Reference in New Issue
Block a user