blob: 127612bf16f7d490913613bc70b7e28b0cc7d787 [file] [log] [blame]
gstepanovff25b5c2015-03-02 20:48:17 +02001from urlparse import urlparse
2from keystone import KeystoneAuth
3
4
5def total_lab_info(data):
gstepanov1fbb71d2015-04-14 19:56:23 +03006 lab_data = {}
7 lab_data['nodes_count'] = len(data['nodes'])
8 lab_data['total_memory'] = 0
9 lab_data['total_disk'] = 0
10 lab_data['processor_count'] = 0
gstepanovff25b5c2015-03-02 20:48:17 +020011
12 for node in data['nodes']:
gstepanov1fbb71d2015-04-14 19:56:23 +030013 lab_data['total_memory'] += node['memory']['total']
14 lab_data['processor_count'] += len(node['processors'])
gstepanovff25b5c2015-03-02 20:48:17 +020015
16 for disk in node['disks']:
gstepanov1fbb71d2015-04-14 19:56:23 +030017 lab_data['total_disk'] += disk['size']
gstepanovff25b5c2015-03-02 20:48:17 +020018
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030019 def to_gb(x):
20 return x / (1024 ** 3)
21
gstepanov1fbb71d2015-04-14 19:56:23 +030022 lab_data['total_memory'] = format(to_gb(lab_data['total_memory']), ',d')
23 lab_data['total_disk'] = format(to_gb(lab_data['total_disk']), ',d')
24 return lab_data
gstepanovff25b5c2015-03-02 20:48:17 +020025
26
27def collect_lab_data(url, cred):
28 u = urlparse(url)
29 keystone = KeystoneAuth(root_url=url, creds=cred, admin_node_ip=u.hostname)
30 lab_info = keystone.do(method='get', path="/api/nodes")
31 fuel_version = keystone.do(method='get', path="/api/version/")
32
33 nodes = []
34 result = {}
35
36 for node in lab_info:
37 # <koder>: give p,i,d,... vars meaningful names
38 d = {}
39 d['name'] = node['name']
40 p = []
41 i = []
42 disks = []
43 devices = []
44
45 for processor in node['meta']['cpu']['spec']:
gstepanovdae57122015-03-02 20:50:41 +020046 p.append(processor)
gstepanovff25b5c2015-03-02 20:48:17 +020047
48 for iface in node['meta']['interfaces']:
49 i.append(iface)
50
51 m = node['meta']['memory'].copy()
52
53 for disk in node['meta']['disks']:
54 disks.append(disk)
55
56 d['memory'] = m
57 d['disks'] = disks
58 d['devices'] = devices
59 d['interfaces'] = i
60 d['processors'] = p
61
62 nodes.append(d)
63
64 result['nodes'] = nodes
65 # result['name'] = 'Perf-1 Env'
66 result['fuel_version'] = fuel_version['release']
67
gstepanovdae57122015-03-02 20:50:41 +020068 return result