blob: 7dc39011001902c48dd992d474792ea0f7fe7877 [file] [log] [blame]
from typing import Any, Dict, List
from .fuel_rest_api import KeystoneAuth, FuelInfo
def total_lab_info(nodes: List[Dict[str, Any]]) -> Dict[str, int]:
lab_data = {'nodes_count': len(nodes),
'total_memory': 0,
'total_disk': 0,
'processor_count': 0} # type: Dict[str, int]
for node in 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']
lab_data['total_memory'] /= (1024 ** 3)
lab_data['total_disk'] /= (1024 ** 3)
return lab_data
def collect_lab_data(url: str, cred: Dict[str, str]) -> Dict[str, Any]:
finfo = FuelInfo(KeystoneAuth(url, cred))
nodes = [] # type: List[Dict[str, str]]
result = {} # type: Dict[str, Any]
for node in finfo.get_nodes(): # type: ignore
node_info = {
'name': node['name'],
'processors': [],
'interfaces': [],
'disks': [],
'devices': [],
'memory': node['meta']['memory'].copy()
}
for processor in node['meta']['cpu']['spec']:
node_info['processors'].append(processor)
for iface in node['meta']['interfaces']:
node_info['interfaces'].append(iface)
for disk in node['meta']['disks']:
node_info['disks'].append(disk)
nodes.append(node_info)
result['nodes'] = nodes
result['fuel_version'] = finfo.get_version()
result['total_info'] = total_lab_info(nodes)
return result