gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 1 | from urlparse import urlparse |
| 2 | from keystone import KeystoneAuth |
| 3 | |
| 4 | |
| 5 | def total_lab_info(data): |
| 6 | # <koder>: give 'd' meaningful name |
| 7 | d = {} |
| 8 | d['nodes_count'] = len(data['nodes']) |
| 9 | d['total_memory'] = 0 |
| 10 | d['total_disk'] = 0 |
| 11 | d['processor_count'] = 0 |
| 12 | |
| 13 | for node in data['nodes']: |
| 14 | d['total_memory'] += node['memory']['total'] |
| 15 | d['processor_count'] += len(node['processors']) |
| 16 | |
| 17 | for disk in node['disks']: |
| 18 | d['total_disk'] += disk['size'] |
| 19 | |
| 20 | to_gb = lambda x: x / (1024 ** 3) |
| 21 | d['total_memory'] = format(to_gb(d['total_memory']), ',d') |
| 22 | d['total_disk'] = format(to_gb(d['total_disk']), ',d') |
| 23 | return d |
| 24 | |
| 25 | |
| 26 | def collect_lab_data(url, cred): |
| 27 | u = urlparse(url) |
| 28 | keystone = KeystoneAuth(root_url=url, creds=cred, admin_node_ip=u.hostname) |
| 29 | lab_info = keystone.do(method='get', path="/api/nodes") |
| 30 | fuel_version = keystone.do(method='get', path="/api/version/") |
| 31 | |
| 32 | nodes = [] |
| 33 | result = {} |
| 34 | |
| 35 | for node in lab_info: |
| 36 | # <koder>: give p,i,d,... vars meaningful names |
| 37 | d = {} |
| 38 | d['name'] = node['name'] |
| 39 | p = [] |
| 40 | i = [] |
| 41 | disks = [] |
| 42 | devices = [] |
| 43 | |
| 44 | for processor in node['meta']['cpu']['spec']: |
gstepanov | dae5712 | 2015-03-02 20:50:41 +0200 | [diff] [blame] | 45 | p.append(processor) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 46 | |
| 47 | for iface in node['meta']['interfaces']: |
| 48 | i.append(iface) |
| 49 | |
| 50 | m = node['meta']['memory'].copy() |
| 51 | |
| 52 | for disk in node['meta']['disks']: |
| 53 | disks.append(disk) |
| 54 | |
| 55 | d['memory'] = m |
| 56 | d['disks'] = disks |
| 57 | d['devices'] = devices |
| 58 | d['interfaces'] = i |
| 59 | d['processors'] = p |
| 60 | |
| 61 | nodes.append(d) |
| 62 | |
| 63 | result['nodes'] = nodes |
| 64 | # result['name'] = 'Perf-1 Env' |
| 65 | result['fuel_version'] = fuel_version['release'] |
| 66 | |
gstepanov | dae5712 | 2015-03-02 20:50:41 +0200 | [diff] [blame] | 67 | return result |