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):
|
def get_list(zk_conn, limit):
|
||||||
net_list = []
|
net_list = []
|
||||||
full_net_list = zk_conn.get_children('/networks')
|
full_net_list = zk_conn.get_children('/networks')
|
||||||
|
|
||||||
for net in full_net_list:
|
for net in full_net_list:
|
||||||
description = zkhandler.readdata(zk_conn, '/networks/{}'.format(net))
|
description = zkhandler.readdata(zk_conn, '/networks/{}'.format(net))
|
||||||
if limit != None:
|
if limit != None:
|
||||||
try:
|
try:
|
||||||
if not re.match(limit, net) or not re.match(limit, description):
|
# Implcitly assume fuzzy limits
|
||||||
continue
|
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:
|
except Exception as e:
|
||||||
return False, 'Regex Error: {}'.format(e)
|
return False, 'Regex Error: {}'.format(e)
|
||||||
net_list.append(net)
|
else:
|
||||||
|
net_list.append(net)
|
||||||
|
|
||||||
|
print(net_list)
|
||||||
|
|
||||||
net_list_output = []
|
net_list_output = []
|
||||||
description = {}
|
description = {}
|
||||||
|
|
|
@ -169,11 +169,18 @@ def get_list(zk_conn, limit):
|
||||||
for node in full_node_list:
|
for node in full_node_list:
|
||||||
if limit != None:
|
if limit != None:
|
||||||
try:
|
try:
|
||||||
if re.match(limit, node) == None:
|
# Implcitly assume fuzzy limits
|
||||||
continue
|
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:
|
except Exception as e:
|
||||||
return False, 'Regex Error: {}'.format(e)
|
return False, 'Regex Error: {}'.format(e)
|
||||||
node_list.append(node)
|
else:
|
||||||
|
node_list.append(node)
|
||||||
|
|
||||||
node_list_output = []
|
node_list_output = []
|
||||||
node_daemon_state = {}
|
node_daemon_state = {}
|
||||||
|
|
|
@ -121,12 +121,18 @@ def get_list(zk_conn, limit):
|
||||||
for router in full_router_list:
|
for router in full_router_list:
|
||||||
if limit != None:
|
if limit != None:
|
||||||
try:
|
try:
|
||||||
if re.match(limit, router) == None:
|
# Implcitly assume fuzzy limits
|
||||||
continue
|
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:
|
except Exception as e:
|
||||||
common.stopZKConnection(zk_conn)
|
|
||||||
return False, 'Regex Error: {}'.format(e)
|
return False, 'Regex Error: {}'.format(e)
|
||||||
router_list.append(router)
|
else:
|
||||||
|
router_list.append(router)
|
||||||
|
|
||||||
router_list_output = []
|
router_list_output = []
|
||||||
router_daemon_state = {}
|
router_daemon_state = {}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import configparser
|
||||||
import kazoo.client
|
import kazoo.client
|
||||||
|
|
||||||
import client_lib.ansiiprint as ansiiprint
|
import client_lib.ansiiprint as ansiiprint
|
||||||
|
import client_lib.zkhandler as zkhandler
|
||||||
import client_lib.common as common
|
import client_lib.common as common
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -466,7 +467,7 @@ def get_list(zk_conn, hypervisor, limit):
|
||||||
# Verify node is valid
|
# Verify node is valid
|
||||||
common.verifyNode(zk_conn, hypervisor)
|
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 = []
|
||||||
vm_list_output = []
|
vm_list_output = []
|
||||||
|
|
||||||
|
@ -480,23 +481,41 @@ def get_list(zk_conn, hypervisor, limit):
|
||||||
vm_vcpu = {}
|
vm_vcpu = {}
|
||||||
|
|
||||||
# If we're limited, remove other nodes' VMs
|
# 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
|
# 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:
|
if limit != None:
|
||||||
try:
|
try:
|
||||||
if re.match(limit, name) == None:
|
# Implcitly assume fuzzy limits
|
||||||
continue
|
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:
|
except Exception as e:
|
||||||
click.echo('Regex Error: {}'.format(e))
|
return False, '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)
|
|
||||||
else:
|
else:
|
||||||
if vm_hypervisor[vm] == hypervisor:
|
# Check hypervisor to avoid unneeded ZK calls
|
||||||
|
if hypervisor == None:
|
||||||
vm_list.append(vm)
|
vm_list.append(vm)
|
||||||
|
else:
|
||||||
|
if vm_hypervisor[vm] == hypervisor:
|
||||||
|
vm_list.append(vm)
|
||||||
|
|
||||||
# Gather information for printing
|
# Gather information for printing
|
||||||
for vm in vm_list:
|
for vm in vm_list:
|
||||||
|
|
Loading…
Reference in New Issue