Added node weight support

Note that weight can be specified using the node-modify only but will
be displayed in load balancer status, node-list, node-status, node-add,
and node-modify. To support the setting of weight with load balancer
create or node-add, it would require a bigger change because with those,
multiple nodes can be specified with --node.  Perhaps a syntax of
ip:port:weight would make sense if that was supported.

Also note that the API interface only returns weight when the value is
not the default (1).  Therefore, the weight column also only displays
a weight value when it is not 1.

Change-Id: I34ea3e4a144aeb47af661c161f5f3ee4946cbe7e
This commit is contained in:
marcrp
2013-09-27 14:52:37 -04:00
parent 9915ff82e0
commit 536b5234c2
2 changed files with 13 additions and 8 deletions

View File

@@ -190,7 +190,9 @@ class ClientOptions(object):
sp.add_argument('--id', help='load balancer ID', required=True)
sp.add_argument('--nodeid', help='node ID to modify', required=True)
sp.add_argument('--condition', help='the new state for the node',
choices=['ENABLED', 'DISABLED'], required=True)
choices=['ENABLED', 'DISABLED'])
sp.add_argument('--weight', type=int, default=1, metavar='COUNT',
help='node weight ratio as compared to other nodes')
sp = subparsers.add_parser(
'node-status', help='get status of a node in a load balancer'

View File

@@ -171,8 +171,9 @@ class LibraAPI(object):
def node_list_lb(self, args):
resp, body = self._get('/loadbalancers/{0}/nodes'.format(args.id))
column_names = ['ID', 'Address', 'Port', 'Condition', 'Status']
columns = ['id', 'address', 'port', 'condition', 'status']
column_names = ['ID', 'Address', 'Port', 'Condition', 'Weight',
'Status']
columns = ['id', 'address', 'port', 'condition', 'weight', 'status']
self._render_list(column_names, columns, body['nodes'])
def node_delete_lb(self, args):
@@ -185,20 +186,22 @@ class LibraAPI(object):
data['nodes'] = self._parse_nodes(args.node)
resp, body = self._post('/loadbalancers/{0}/nodes'
.format(args.id), body=data)
column_names = ['ID', 'Address', 'Port', 'Condition', 'Status']
columns = ['id', 'address', 'port', 'condition', 'status']
column_names = ['ID', 'Address', 'Port', 'Condition', 'Weight',
'Status']
columns = ['id', 'address', 'port', 'condition', 'weight', 'status']
self._render_list(column_names, columns, body['nodes'])
def node_modify_lb(self, args):
data = {'condition': args.condition}
data = {'condition': args.condition, 'weight': args.weight}
self._put('/loadbalancers/{0}/nodes/{1}'
.format(args.id, args.nodeid), body=data)
def node_status_lb(self, args):
resp, body = self._get('/loadbalancers/{0}/nodes/{1}'
.format(args.id, args.nodeid))
column_names = ['ID', 'Address', 'Port', 'Condition', 'Status']
columns = ['id', 'address', 'port', 'condition', 'status']
column_names = ['ID', 'Address', 'Port', 'Condition',
'Weight', 'Status']
columns = ['id', 'address', 'port', 'condition', 'weight', 'status']
self._render_dict(column_names, columns, body)
def logs_lb(self, args):