blob: 7dc39011001902c48dd992d474792ea0f7fe7877 [file] [log] [blame]
koder aka kdanilov70227062016-11-26 23:23:21 +02001from typing import Any, Dict, List
koder aka kdanilov73084622016-11-16 21:51:08 +02002from .fuel_rest_api import KeystoneAuth, FuelInfo
koder aka kdanilov22d134e2016-11-08 11:33:19 +02003
4
koder aka kdanilov73084622016-11-16 21:51:08 +02005def total_lab_info(nodes: List[Dict[str, Any]]) -> Dict[str, int]:
6 lab_data = {'nodes_count': len(nodes),
7 'total_memory': 0,
8 'total_disk': 0,
9 'processor_count': 0} # type: Dict[str, int]
gstepanovff25b5c2015-03-02 20:48:17 +020010
koder aka kdanilov73084622016-11-16 21:51:08 +020011 for node in nodes:
gstepanov1fbb71d2015-04-14 19:56:23 +030012 lab_data['total_memory'] += node['memory']['total']
13 lab_data['processor_count'] += len(node['processors'])
gstepanovff25b5c2015-03-02 20:48:17 +020014
15 for disk in node['disks']:
gstepanov1fbb71d2015-04-14 19:56:23 +030016 lab_data['total_disk'] += disk['size']
gstepanovff25b5c2015-03-02 20:48:17 +020017
koder aka kdanilov73084622016-11-16 21:51:08 +020018 lab_data['total_memory'] /= (1024 ** 3)
19 lab_data['total_disk'] /= (1024 ** 3)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030020
gstepanov1fbb71d2015-04-14 19:56:23 +030021 return lab_data
gstepanovff25b5c2015-03-02 20:48:17 +020022
23
koder aka kdanilov70227062016-11-26 23:23:21 +020024def collect_lab_data(url: str, cred: Dict[str, str]) -> Dict[str, Any]:
koder aka kdanilov73084622016-11-16 21:51:08 +020025 finfo = FuelInfo(KeystoneAuth(url, cred))
gstepanovff25b5c2015-03-02 20:48:17 +020026
koder aka kdanilov73084622016-11-16 21:51:08 +020027 nodes = [] # type: List[Dict[str, str]]
koder aka kdanilov70227062016-11-26 23:23:21 +020028 result = {} # type: Dict[str, Any]
gstepanovff25b5c2015-03-02 20:48:17 +020029
koder aka kdanilov70227062016-11-26 23:23:21 +020030 for node in finfo.get_nodes(): # type: ignore
koder aka kdanilov73084622016-11-16 21:51:08 +020031 node_info = {
32 'name': node['name'],
33 'processors': [],
34 'interfaces': [],
35 'disks': [],
36 'devices': [],
37 'memory': node['meta']['memory'].copy()
38 }
gstepanovff25b5c2015-03-02 20:48:17 +020039
40 for processor in node['meta']['cpu']['spec']:
koder aka kdanilov73084622016-11-16 21:51:08 +020041 node_info['processors'].append(processor)
gstepanovff25b5c2015-03-02 20:48:17 +020042
43 for iface in node['meta']['interfaces']:
koder aka kdanilov73084622016-11-16 21:51:08 +020044 node_info['interfaces'].append(iface)
gstepanovff25b5c2015-03-02 20:48:17 +020045
46 for disk in node['meta']['disks']:
koder aka kdanilov73084622016-11-16 21:51:08 +020047 node_info['disks'].append(disk)
gstepanovff25b5c2015-03-02 20:48:17 +020048
koder aka kdanilov73084622016-11-16 21:51:08 +020049 nodes.append(node_info)
gstepanovff25b5c2015-03-02 20:48:17 +020050
51 result['nodes'] = nodes
koder aka kdanilov73084622016-11-16 21:51:08 +020052 result['fuel_version'] = finfo.get_version()
53 result['total_info'] = total_lab_info(nodes)
koder aka kdanilov70227062016-11-26 23:23:21 +020054
gstepanovdae57122015-03-02 20:50:41 +020055 return result