Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 1 | import time |
| 2 | import json |
| 3 | import collections |
| 4 | import sys |
| 5 | import os.path |
| 6 | import re |
| 7 | |
| 8 | def get_neutron_lists(netlist): |
| 9 | pairs = re.split("\+-*\+-*\+\n?",netlist)[2:-1] |
| 10 | ids,names,subnets = [],[],[] |
| 11 | for p in pairs: |
| 12 | for l in p.split('\n'): |
| 13 | pair = l.split('|') |
| 14 | if len(pair) > 1: |
| 15 | ids.append(pair[1].strip()) |
| 16 | names.append(pair[2].strip()) |
| 17 | subnets.append(pair[3].strip()) |
| 18 | nets = dict(zip(names,subnets)) |
| 19 | return nets |
| 20 | |
| 21 | def get_nova_lists(novalist,nameWildCard=None): |
| 22 | pairs = re.split("\+-*\+-*\+\n?",novalist)[2:-1] |
| 23 | ids,names,status,taskState,powerState,networks = [],[],[],[],[],[] |
| 24 | for p in pairs: |
| 25 | for l in p.split('\n'): |
| 26 | pair = l.split('|') |
| 27 | if len(pair) > 1: |
| 28 | ids.append(pair[1].strip()) |
| 29 | names.append(pair[2].strip()) |
| 30 | status.append(pair[3].strip()) |
| 31 | taskState.append(pair[4].strip()) |
| 32 | powerState.append(pair[5].strip()) |
| 33 | networks.append(pair[6].strip()) |
| 34 | instances = dict(zip(names,networks)) |
| 35 | if nameWildCard is not None: |
| 36 | for key in instances.keys(): |
| 37 | if re.match(nameWildCard, key): |
| 38 | return instances[key] |
| 39 | else: |
| 40 | return instances |