Rebuild API using Flask-RESTful and Swagger docs
This commit is contained in:
@ -728,13 +728,10 @@ def get_list_pool(zk_conn, limit, is_fuzzy=True):
|
||||
pool_list = []
|
||||
full_pool_list = zkhandler.listchildren(zk_conn, '/ceph/pools')
|
||||
|
||||
if is_fuzzy and limit:
|
||||
# Implicitly assume fuzzy limits
|
||||
if not re.match('\^.*', limit):
|
||||
limit = '.*' + limit
|
||||
if not re.match('.*\$', limit):
|
||||
limit = limit + '.*'
|
||||
|
||||
if limit:
|
||||
if not is_fuzzy:
|
||||
limit = '^' + limit + '$'
|
||||
|
||||
for pool in full_pool_list:
|
||||
if limit:
|
||||
try:
|
||||
@ -1121,23 +1118,26 @@ def remove_volume(zk_conn, pool, name):
|
||||
|
||||
def get_list_volume(zk_conn, pool, limit, is_fuzzy=True):
|
||||
volume_list = []
|
||||
if pool and not verifyPool(zk_conn, name):
|
||||
if pool and not verifyPool(zk_conn, pool):
|
||||
return False, 'ERROR: No pool with name "{}" is present in the cluster.'.format(name)
|
||||
|
||||
full_volume_list = getCephVolumes(zk_conn, pool)
|
||||
|
||||
if is_fuzzy and limit:
|
||||
# Implicitly assume fuzzy limits
|
||||
if not re.match('\^.*', limit):
|
||||
limit = '.*' + limit
|
||||
if not re.match('.*\$', limit):
|
||||
limit = limit + '.*'
|
||||
if limit:
|
||||
if not is_fuzzy:
|
||||
limit = '^' + limit + '$'
|
||||
else:
|
||||
# Implicitly assume fuzzy limits
|
||||
if not re.match('\^.*', limit):
|
||||
limit = '.*' + limit
|
||||
if not re.match('.*\$', limit):
|
||||
limit = limit + '.*'
|
||||
|
||||
for volume in full_volume_list:
|
||||
pool_name, volume_name = volume.split('/')
|
||||
if limit:
|
||||
try:
|
||||
if re.match(limit, volume):
|
||||
if re.match(limit, volume_name):
|
||||
volume_list.append(getVolumeInformation(zk_conn, pool_name, volume_name))
|
||||
except Exception as e:
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
@ -1387,12 +1387,12 @@ def get_list_snapshot(zk_conn, pool, volume, limit, is_fuzzy=True):
|
||||
pool_name, volume_name = volume.split('/')
|
||||
if limit:
|
||||
try:
|
||||
if re.match(limit, snapshot):
|
||||
snapshot_list.append(snapshot)
|
||||
if re.match(limit, snapshot_name):
|
||||
snapshot_list.append({'pool': pool_name, 'volume': volume_name, 'snapshot': snapshot_name})
|
||||
except Exception as e:
|
||||
return False, 'Regex Error: {}'.format(e)
|
||||
else:
|
||||
snapshot_list.append(snapshot)
|
||||
snapshot_list.append({'pool': pool_name, 'volume': volume_name, 'snapshot': snapshot_name})
|
||||
|
||||
return True, snapshot_list
|
||||
|
||||
|
@ -25,6 +25,8 @@ import lxml
|
||||
import math
|
||||
import kazoo.client
|
||||
|
||||
from distutils.util import strtobool
|
||||
|
||||
import client_lib.zkhandler as zkhandler
|
||||
|
||||
###############################################################################
|
||||
@ -216,11 +218,11 @@ def getInformationFromXML(zk_conn, uuid):
|
||||
'failed_reason': domain_failedreason,
|
||||
'node_limit': domain_node_limit,
|
||||
'node_selector': domain_node_selector,
|
||||
'node_autostart': domain_node_autostart,
|
||||
'node_autostart': bool(strtobool(domain_node_autostart)),
|
||||
'description': domain_description,
|
||||
'profile': domain_profile,
|
||||
'memory': domain_memory,
|
||||
'vcpu': domain_vcpu,
|
||||
'memory': int(domain_memory),
|
||||
'vcpu': int(domain_vcpu),
|
||||
'vcpu_topology': domain_vcputopo,
|
||||
'networks': domain_networks,
|
||||
'type': domain_type,
|
||||
|
@ -47,17 +47,17 @@ def getNodeInformation(zk_conn, node_name):
|
||||
node_coordinator_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node_name))
|
||||
node_domain_state = zkhandler.readdata(zk_conn, '/nodes/{}/domainstate'.format(node_name))
|
||||
node_static_data = zkhandler.readdata(zk_conn, '/nodes/{}/staticdata'.format(node_name)).split()
|
||||
node_cpu_count = node_static_data[0]
|
||||
node_cpu_count = int(node_static_data[0])
|
||||
node_kernel = node_static_data[1]
|
||||
node_os = node_static_data[2]
|
||||
node_arch = node_static_data[3]
|
||||
node_vcpu_allocated = zkhandler.readdata(zk_conn, 'nodes/{}/vcpualloc'.format(node_name))
|
||||
node_vcpu_allocated = int(zkhandler.readdata(zk_conn, 'nodes/{}/vcpualloc'.format(node_name)))
|
||||
node_mem_total = int(zkhandler.readdata(zk_conn, '/nodes/{}/memtotal'.format(node_name)))
|
||||
node_mem_allocated = int(zkhandler.readdata(zk_conn, '/nodes/{}/memalloc'.format(node_name)))
|
||||
node_mem_used = int(zkhandler.readdata(zk_conn, '/nodes/{}/memused'.format(node_name)))
|
||||
node_mem_free = int(zkhandler.readdata(zk_conn, '/nodes/{}/memfree'.format(node_name)))
|
||||
node_load = zkhandler.readdata(zk_conn, '/nodes/{}/cpuload'.format(node_name))
|
||||
node_domains_count = zkhandler.readdata(zk_conn, '/nodes/{}/domainscount'.format(node_name))
|
||||
node_load = float(zkhandler.readdata(zk_conn, '/nodes/{}/cpuload'.format(node_name)))
|
||||
node_domains_count = int(zkhandler.readdata(zk_conn, '/nodes/{}/domainscount'.format(node_name)))
|
||||
node_running_domains = zkhandler.readdata(zk_conn, '/nodes/{}/runningdomains'.format(node_name)).split()
|
||||
|
||||
# Construct a data structure to represent the data
|
||||
@ -200,12 +200,8 @@ def get_list(zk_conn, limit, is_fuzzy=True):
|
||||
for node in full_node_list:
|
||||
if limit:
|
||||
try:
|
||||
if is_fuzzy:
|
||||
# Implcitly assume fuzzy limits
|
||||
if not re.match('\^.*', limit):
|
||||
limit = '.*' + limit
|
||||
if not re.match('.*\$', limit):
|
||||
limit = limit + '.*'
|
||||
if not is_fuzzy:
|
||||
limit = '^' + limit + '$'
|
||||
|
||||
if re.match(limit, node):
|
||||
node_list.append(getNodeInformation(zk_conn, node))
|
||||
|
Reference in New Issue
Block a user