Improve limit handling
This commit is contained in:
parent
615169cd69
commit
7daed1b0d8
|
@ -217,16 +217,28 @@ def get_info(zk_conn, network, long_output):
|
|||
def get_list(zk_conn, limit):
|
||||
net_list = []
|
||||
full_net_list = zk_conn.get_children('/networks')
|
||||
|
||||
for net in full_net_list:
|
||||
description = zkhandler.readdata(zk_conn, '/networks/{}'.format(net))
|
||||
if limit != None:
|
||||
try:
|
||||
if not re.match(limit, net) or not re.match(limit, description):
|
||||
continue
|
||||
# Implcitly assume fuzzy limits
|
||||
if re.match('\^.*', limit) == None:
|
||||
limit = '.*' + limit
|
||||
if re.match('.*\$', limit) == None:
|
||||
limit = limit + '.*'
|
||||
|
||||
if re.match(limit, net) != None:
|
||||
net_list.append(net)
|
||||
if re.match(limit, description) != None:
|
||||
net_list.append(net)
|
||||
except Exception as e:
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
else:
|
||||
net_list.append(net)
|
||||
|
||||
print(net_list)
|
||||
|
||||
net_list_output = []
|
||||
description = {}
|
||||
ip_network = {}
|
||||
|
|
|
@ -169,10 +169,17 @@ def get_list(zk_conn, limit):
|
|||
for node in full_node_list:
|
||||
if limit != None:
|
||||
try:
|
||||
if re.match(limit, node) == None:
|
||||
continue
|
||||
# Implcitly assume fuzzy limits
|
||||
if re.match('\^.*', limit) == None:
|
||||
limit = '.*' + limit
|
||||
if re.match('.*\$', limit) == None:
|
||||
limit = limit + '.*'
|
||||
|
||||
if re.match(limit, node) != None:
|
||||
node_list.append(node)
|
||||
except Exception as e:
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
else:
|
||||
node_list.append(node)
|
||||
|
||||
node_list_output = []
|
||||
|
|
|
@ -121,11 +121,17 @@ def get_list(zk_conn, limit):
|
|||
for router in full_router_list:
|
||||
if limit != None:
|
||||
try:
|
||||
if re.match(limit, router) == None:
|
||||
continue
|
||||
# Implcitly assume fuzzy limits
|
||||
if re.match('\^.*', limit) == None:
|
||||
limit = '.*' + limit
|
||||
if re.match('.*\$', limit) == None:
|
||||
limit = limit + '.*'
|
||||
|
||||
if re.match(limit, router) != None:
|
||||
router_list.append(router)
|
||||
except Exception as e:
|
||||
common.stopZKConnection(zk_conn)
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
else:
|
||||
router_list.append(router)
|
||||
|
||||
router_list_output = []
|
||||
|
|
|
@ -35,6 +35,7 @@ import configparser
|
|||
import kazoo.client
|
||||
|
||||
import client_lib.ansiiprint as ansiiprint
|
||||
import client_lib.zkhandler as zkhandler
|
||||
import client_lib.common as common
|
||||
|
||||
#
|
||||
|
@ -466,7 +467,7 @@ def get_list(zk_conn, hypervisor, limit):
|
|||
# Verify node is valid
|
||||
common.verifyNode(zk_conn, hypervisor)
|
||||
|
||||
vm_list_raw = zk_conn.get_children('/domains')
|
||||
full_vm_list = zk_conn.get_children('/domains')
|
||||
vm_list = []
|
||||
vm_list_output = []
|
||||
|
||||
|
@ -480,18 +481,36 @@ def get_list(zk_conn, hypervisor, limit):
|
|||
vm_vcpu = {}
|
||||
|
||||
# If we're limited, remove other nodes' VMs
|
||||
for vm in vm_list_raw:
|
||||
for vm in full_vm_list:
|
||||
|
||||
# Check we don't match the limit
|
||||
name = zk_conn.get('/domains/{}'.format(vm))[0].decode('ascii')
|
||||
name = zkhandler.readdata(zk_conn, '/domains/{}'.format(vm))
|
||||
vm_hypervisor[vm] = zkhandler.readdata(zk_conn, '/domains/{}/hypervisor'.format(vm))
|
||||
if limit != None:
|
||||
try:
|
||||
if re.match(limit, name) == None:
|
||||
continue
|
||||
# Implcitly assume fuzzy limits
|
||||
if re.match('\^.*', limit) == None:
|
||||
limit = '.*' + limit
|
||||
if re.match('.*\$', limit) == None:
|
||||
limit = limit + '.*'
|
||||
|
||||
if re.match(limit, vm) != None:
|
||||
if hypervisor == None:
|
||||
vm_list.append(vm)
|
||||
else:
|
||||
if vm_hypervisor[vm] == hypervisor:
|
||||
vm_list.append(vm)
|
||||
|
||||
if re.match(limit, name) != None:
|
||||
if hypervisor == None:
|
||||
vm_list.append(vm)
|
||||
else:
|
||||
if vm_hypervisor[vm] == hypervisor:
|
||||
vm_list.append(vm)
|
||||
except Exception as e:
|
||||
click.echo('Regex Error: {}'.format(e))
|
||||
exit(1)
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
else:
|
||||
# Check hypervisor to avoid unneeded ZK calls
|
||||
vm_hypervisor[vm] = zk_conn.get('/domains/{}/hypervisor'.format(vm))[0].decode('ascii')
|
||||
if hypervisor == None:
|
||||
vm_list.append(vm)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue