blob: 3de33cb5a72398d094142d0c48e537c691c19340 [file] [log] [blame]
from typing import Any, Dict
from urllib.parse import urlparse
from .keystone import KeystoneAuth
def total_lab_info(data: Dict[str, Any]) -> Dict[str, Any]:
lab_data = {}
lab_data['nodes_count'] = len(data['nodes'])
lab_data['total_memory'] = 0
lab_data['total_disk'] = 0
lab_data['processor_count'] = 0
for node in data['nodes']:
lab_data['total_memory'] += node['memory']['total']
lab_data['processor_count'] += len(node['processors'])
for disk in node['disks']:
lab_data['total_disk'] += disk['size']
def to_gb(x):
return x / (1024 ** 3)
lab_data['total_memory'] = to_gb(lab_data['total_memory'])
lab_data['total_disk'] = to_gb(lab_data['total_disk'])
return lab_data
def collect_lab_data(url: str, cred: Dict[str, str]) -> Dict[str, Any]:
u = urlparse(url)
keystone = KeystoneAuth(root_url=url, creds=cred, admin_node_ip=u.hostname)
lab_info = keystone.do(method='get', path="/api/nodes")
fuel_version = keystone.do(method='get', path="/api/version/")
nodes = []
result = {}
for node in lab_info:
# TODO(koder): give p,i,d,... vars meaningful names
d = {}
d['name'] = node['name']
p = []
i = []
disks = []
devices = []
for processor in node['meta']['cpu']['spec']:
p.append(processor)
for iface in node['meta']['interfaces']:
i.append(iface)
m = node['meta']['memory'].copy()
for disk in node['meta']['disks']:
disks.append(disk)
d['memory'] = m
d['disks'] = disks
d['devices'] = devices
d['interfaces'] = i
d['processors'] = p
nodes.append(d)
result['nodes'] = nodes
result['fuel_version'] = fuel_version['release']
return result