Add checking and error handling to IP:port processing
Fixes bug #1125430 Change-Id: I270cbfb57f74cd1ef7c4900e3dfa213f052b3931
This commit is contained in:
@@ -51,5 +51,8 @@ def main():
|
|||||||
print exc.details
|
print exc.details
|
||||||
except exceptions.EndpointNotFound:
|
except exceptions.EndpointNotFound:
|
||||||
return 2
|
return 2
|
||||||
|
except Exception as exc:
|
||||||
|
print exc
|
||||||
|
return 2
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import prettytable
|
import prettytable
|
||||||
import novaclient
|
import novaclient
|
||||||
|
import socket
|
||||||
|
|
||||||
from novaclient import client
|
from novaclient import client
|
||||||
|
|
||||||
@@ -123,7 +124,6 @@ class LibraAPI(object):
|
|||||||
|
|
||||||
def create_lb(self, args):
|
def create_lb(self, args):
|
||||||
data = {}
|
data = {}
|
||||||
nodes = []
|
|
||||||
data['name'] = args.name
|
data['name'] = args.name
|
||||||
if args.port is not None:
|
if args.port is not None:
|
||||||
data['port'] = args.port
|
data['port'] = args.port
|
||||||
@@ -131,10 +131,7 @@ class LibraAPI(object):
|
|||||||
data['protocol'] = args.protocol
|
data['protocol'] = args.protocol
|
||||||
if args.algorithm is not None:
|
if args.algorithm is not None:
|
||||||
data['algorithm'] = args.algorithm
|
data['algorithm'] = args.algorithm
|
||||||
for node in args.node:
|
data['nodes'] = self._parse_nodes(args.node)
|
||||||
addr = node.split(':')
|
|
||||||
nodes.append({'address': addr[0], 'port': addr[1]})
|
|
||||||
data['nodes'] = nodes
|
|
||||||
if args.vip is not None:
|
if args.vip is not None:
|
||||||
data['virtualIps'] = [{'id': args.vip}]
|
data['virtualIps'] = [{'id': args.vip}]
|
||||||
|
|
||||||
@@ -165,12 +162,8 @@ class LibraAPI(object):
|
|||||||
|
|
||||||
def node_add_lb(self, args):
|
def node_add_lb(self, args):
|
||||||
data = {}
|
data = {}
|
||||||
nodes = []
|
|
||||||
|
|
||||||
for node in args.node:
|
data['nodes'] = self._parse_nodes(args.node)
|
||||||
addr = node.split(':')
|
|
||||||
nodes.append({'address': addr[0], 'port': addr[1]})
|
|
||||||
data['nodes'] = nodes
|
|
||||||
resp, body = self._post('/loadbalancers/{0}/nodes'
|
resp, body = self._post('/loadbalancers/{0}/nodes'
|
||||||
.format(args.id), body=data)
|
.format(args.id), body=data)
|
||||||
column_names = ['ID', 'Address', 'Port', 'Condition', 'Status']
|
column_names = ['ID', 'Address', 'Port', 'Condition', 'Status']
|
||||||
@@ -225,3 +218,19 @@ class LibraAPI(object):
|
|||||||
|
|
||||||
def _delete(self, url, **kwargs):
|
def _delete(self, url, **kwargs):
|
||||||
return self.nova.delete(url, **kwargs)
|
return self.nova.delete(url, **kwargs)
|
||||||
|
|
||||||
|
def _parse_nodes(self, nodes):
|
||||||
|
out_nodes = []
|
||||||
|
try:
|
||||||
|
for node in nodes:
|
||||||
|
addr = node.split(':')
|
||||||
|
# Test IP valid
|
||||||
|
# TODO: change to pton when we want to support IPv6
|
||||||
|
socket.inet_aton(addr[0])
|
||||||
|
# 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")
|
||||||
|
return out_nodes
|
||||||
|
Reference in New Issue
Block a user