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): |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 6 | 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 |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 11 | |
| 12 | for node in data['nodes']: |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 13 | lab_data['total_memory'] += node['memory']['total'] |
| 14 | lab_data['processor_count'] += len(node['processors']) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 15 | |
| 16 | for disk in node['disks']: |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 17 | lab_data['total_disk'] += disk['size'] |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 18 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 19 | def to_gb(x): |
| 20 | return x / (1024 ** 3) |
| 21 | |
gstepanov | 1fbb71d | 2015-04-14 19:56:23 +0300 | [diff] [blame] | 22 | 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 |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def 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']: |
gstepanov | dae5712 | 2015-03-02 20:50:41 +0200 | [diff] [blame] | 46 | p.append(processor) |
gstepanov | ff25b5c | 2015-03-02 20:48:17 +0200 | [diff] [blame] | 47 | |
| 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 | |
gstepanov | dae5712 | 2015-03-02 20:50:41 +0200 | [diff] [blame] | 68 | return result |