Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 17 | import time |
| 18 | import json |
| 19 | import collections |
| 20 | import sys |
| 21 | import os.path |
| 22 | import re |
| 23 | |
| 24 | def get_neutron_lists(netlist): |
| 25 | pairs = re.split("\+-*\+-*\+\n?",netlist)[2:-1] |
| 26 | ids,names,subnets = [],[],[] |
| 27 | for p in pairs: |
| 28 | for l in p.split('\n'): |
| 29 | pair = l.split('|') |
| 30 | if len(pair) > 1: |
| 31 | ids.append(pair[1].strip()) |
| 32 | names.append(pair[2].strip()) |
| 33 | subnets.append(pair[3].strip()) |
| 34 | nets = dict(zip(names,subnets)) |
| 35 | return nets |
| 36 | |
| 37 | def get_nova_lists(novalist,nameWildCard=None): |
| 38 | pairs = re.split("\+-*\+-*\+\n?",novalist)[2:-1] |
| 39 | ids,names,status,taskState,powerState,networks = [],[],[],[],[],[] |
| 40 | for p in pairs: |
| 41 | for l in p.split('\n'): |
| 42 | pair = l.split('|') |
| 43 | if len(pair) > 1: |
| 44 | ids.append(pair[1].strip()) |
| 45 | names.append(pair[2].strip()) |
| 46 | status.append(pair[3].strip()) |
| 47 | taskState.append(pair[4].strip()) |
| 48 | powerState.append(pair[5].strip()) |
| 49 | networks.append(pair[6].strip()) |
| 50 | instances = dict(zip(names,networks)) |
| 51 | if nameWildCard is not None: |
| 52 | for key in instances.keys(): |
| 53 | if re.match(nameWildCard, key): |
| 54 | return instances[key] |
| 55 | else: |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame] | 56 | return instances |
| 57 | |
| 58 | def get_instance_status(novalist,nameWildCard=None): |
| 59 | pairs = re.split("\+-*\+-*\+\n?",novalist)[2:-1] |
| 60 | ids,names,status,taskState,powerState,networks = [],[],[],[],[],[] |
| 61 | for p in pairs: |
| 62 | for l in p.split('\n'): |
| 63 | pair = l.split('|') |
| 64 | if len(pair) > 1: |
| 65 | ids.append(pair[1].strip()) |
| 66 | names.append(pair[2].strip()) |
| 67 | status.append(pair[3].strip()) |
| 68 | taskState.append(pair[4].strip()) |
| 69 | powerState.append(pair[5].strip()) |
| 70 | networks.append(pair[6].strip()) |
| 71 | instances = dict(zip(names,status)) |
| 72 | if nameWildCard is not None: |
| 73 | for key in instances.keys(): |
| 74 | if re.match(nameWildCard, key): |
| 75 | return instances[key] |
| 76 | else: |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 77 | return instances |