blob: 33e1fbfb1aa6ce8c88de1097feb9605b0d676ca3 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
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 Khalasi2adbad82017-05-15 14:53:40 -070017import time
18import json
19import collections
20import sys
21import os.path
22import re
23
24def 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
37def 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 Khalasif6de2592017-09-13 13:37:14 -070056 return instances
57
58def 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 Khalasi2adbad82017-05-15 14:53:40 -070077 return instances