koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 1 | from typing import Any, Dict, List |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 2 | from .fuel_rest_api import KeystoneAuth, FuelInfo |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 3 | |
| 4 | |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 5 | def 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] |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 10 | |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 11 | for node in nodes: |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 12 | lab_data['total_memory'] += node['memory']['total'] |
| 13 | lab_data['processor_count'] += len(node['processors']) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 14 | |
| 15 | for disk in node['disks']: |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 16 | lab_data['total_disk'] += disk['size'] |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 17 | |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 18 | lab_data['total_memory'] /= (1024 ** 3) |
| 19 | lab_data['total_disk'] /= (1024 ** 3) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 20 | |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 21 | return lab_data |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 22 | |
| 23 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 24 | def collect_lab_data(url: str, cred: Dict[str, str]) -> Dict[str, Any]: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 25 | finfo = FuelInfo(KeystoneAuth(url, cred)) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 26 | |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 27 | nodes = [] # type: List[Dict[str, str]] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 28 | result = {} # type: Dict[str, Any] |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 29 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 30 | for node in finfo.get_nodes(): # type: ignore |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 31 | node_info = { |
| 32 | 'name': node['name'], |
| 33 | 'processors': [], |
| 34 | 'interfaces': [], |
| 35 | 'disks': [], |
| 36 | 'devices': [], |
| 37 | 'memory': node['meta']['memory'].copy() |
| 38 | } |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 39 | |
| 40 | for processor in node['meta']['cpu']['spec']: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 41 | node_info['processors'].append(processor) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 42 | |
| 43 | for iface in node['meta']['interfaces']: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 44 | node_info['interfaces'].append(iface) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 45 | |
| 46 | for disk in node['meta']['disks']: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 47 | node_info['disks'].append(disk) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 48 | |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 49 | nodes.append(node_info) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 50 | |
| 51 | result['nodes'] = nodes |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 52 | result['fuel_version'] = finfo.get_version() |
| 53 | result['total_info'] = total_lab_info(nodes) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 54 | |
gstepanov | dae5712 | 2015-03-02 20:50:41 +0200 | [diff] [blame] | 55 | return result |