Improve limit handling
This commit is contained in:
parent
615169cd69
commit
7daed1b0d8
|
@ -217,15 +217,27 @@ 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)
|
||||
net_list.append(net)
|
||||
else:
|
||||
net_list.append(net)
|
||||
|
||||
print(net_list)
|
||||
|
||||
net_list_output = []
|
||||
description = {}
|
||||
|
|
|
@ -169,11 +169,18 @@ 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)
|
||||
node_list.append(node)
|
||||
else:
|
||||
node_list.append(node)
|
||||
|
||||
node_list_output = []
|
||||
node_daemon_state = {}
|
||||
|
|
|
@ -121,12 +121,18 @@ 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)
|
||||
router_list.append(router)
|
||||
else:
|
||||
router_list.append(router)
|
||||
|
||||
router_list_output = []
|
||||
router_daemon_state = {}
|
||||
|
|
|
@ -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,23 +481,41 @@ 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)
|
||||
# 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)
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
else:
|
||||
if vm_hypervisor[vm] == hypervisor:
|
||||
# Check hypervisor to avoid unneeded ZK calls
|
||||
if hypervisor == None:
|
||||
vm_list.append(vm)
|
||||
else:
|
||||
if vm_hypervisor[vm] == hypervisor:
|
||||
vm_list.append(vm)
|
||||
|
||||
# Gather information for printing
|
||||
for vm in vm_list:
|
||||
|
|
Loading…
Reference in New Issue