blob: 3de33cb5a72398d094142d0c48e537c691c19340 [file] [log] [blame]
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +03001from typing import Any, Dict
2from urllib.parse import urlparse
koder aka kdanilov22d134e2016-11-08 11:33:19 +02003
4
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +03005from .keystone import KeystoneAuth
gstepanovff25b5c2015-03-02 20:48:17 +02006
7
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +03008def total_lab_info(data: Dict[str, Any]) -> Dict[str, Any]:
gstepanov1fbb71d2015-04-14 19:56:23 +03009 lab_data = {}
10 lab_data['nodes_count'] = len(data['nodes'])
11 lab_data['total_memory'] = 0
12 lab_data['total_disk'] = 0
13 lab_data['processor_count'] = 0
gstepanovff25b5c2015-03-02 20:48:17 +020014
15 for node in data['nodes']:
gstepanov1fbb71d2015-04-14 19:56:23 +030016 lab_data['total_memory'] += node['memory']['total']
17 lab_data['processor_count'] += len(node['processors'])
gstepanovff25b5c2015-03-02 20:48:17 +020018
19 for disk in node['disks']:
gstepanov1fbb71d2015-04-14 19:56:23 +030020 lab_data['total_disk'] += disk['size']
gstepanovff25b5c2015-03-02 20:48:17 +020021
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030022 def to_gb(x):
23 return x / (1024 ** 3)
24
koder aka kdanilova047e1b2015-04-21 23:16:59 +030025 lab_data['total_memory'] = to_gb(lab_data['total_memory'])
26 lab_data['total_disk'] = to_gb(lab_data['total_disk'])
gstepanov1fbb71d2015-04-14 19:56:23 +030027 return lab_data
gstepanovff25b5c2015-03-02 20:48:17 +020028
29
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030030def collect_lab_data(url: str, cred: Dict[str, str]) -> Dict[str, Any]:
gstepanovff25b5c2015-03-02 20:48:17 +020031 u = urlparse(url)
32 keystone = KeystoneAuth(root_url=url, creds=cred, admin_node_ip=u.hostname)
33 lab_info = keystone.do(method='get', path="/api/nodes")
34 fuel_version = keystone.do(method='get', path="/api/version/")
35
36 nodes = []
37 result = {}
38
39 for node in lab_info:
koder aka kdanilov22d134e2016-11-08 11:33:19 +020040 # TODO(koder): give p,i,d,... vars meaningful names
gstepanovff25b5c2015-03-02 20:48:17 +020041 d = {}
42 d['name'] = node['name']
43 p = []
44 i = []
45 disks = []
46 devices = []
47
48 for processor in node['meta']['cpu']['spec']:
gstepanovdae57122015-03-02 20:50:41 +020049 p.append(processor)
gstepanovff25b5c2015-03-02 20:48:17 +020050
51 for iface in node['meta']['interfaces']:
52 i.append(iface)
53
54 m = node['meta']['memory'].copy()
55
56 for disk in node['meta']['disks']:
57 disks.append(disk)
58
59 d['memory'] = m
60 d['disks'] = disks
61 d['devices'] = devices
62 d['interfaces'] = i
63 d['processors'] = p
64
65 nodes.append(d)
66
67 result['nodes'] = nodes
gstepanovff25b5c2015-03-02 20:48:17 +020068 result['fuel_version'] = fuel_version['release']
69
gstepanovdae57122015-03-02 20:50:41 +020070 return result