blob: 3af4063856e2cc29facb0507c98407620be2711e [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
Zack Williamsc6722d52020-01-13 16:34:33 -070016from __future__ import absolute_import
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -070017
Kailash Khalasi2adbad82017-05-15 14:53:40 -070018import re
19
Zack Williamsc6722d52020-01-13 16:34:33 -070020
Kailash Khalasi2adbad82017-05-15 14:53:40 -070021def get_neutron_lists(netlist):
Zack Williamsc6722d52020-01-13 16:34:33 -070022 pairs = re.split(r"\+-*\+-*\+\n?", netlist)[2:-1]
23 ids, names, subnets = [], [], []
Kailash Khalasi2adbad82017-05-15 14:53:40 -070024 for p in pairs:
Zack Williamsc6722d52020-01-13 16:34:33 -070025 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 subnets.append(pair[3].strip())
31 nets = dict(zip(names, subnets))
Kailash Khalasi2adbad82017-05-15 14:53:40 -070032 return nets
33
Zack Williamsc6722d52020-01-13 16:34:33 -070034
35def get_nova_lists(novalist, nameWildCard=None):
36 pairs = re.split(r"\+-*\+-*\+\n?", novalist)[2:-1]
37 ids, names, status, taskState, powerState, networks = [], [], [], [], [], []
Kailash Khalasi2adbad82017-05-15 14:53:40 -070038 for p in pairs:
Zack Williamsc6722d52020-01-13 16:34:33 -070039 for l in p.split('\n'):
40 pair = l.split('|')
41 if len(pair) > 1:
42 ids.append(pair[1].strip())
43 names.append(pair[2].strip())
44 status.append(pair[3].strip())
45 taskState.append(pair[4].strip())
46 powerState.append(pair[5].strip())
47 networks.append(pair[6].strip())
48 instances = dict(zip(names, networks))
Kailash Khalasi2adbad82017-05-15 14:53:40 -070049 if nameWildCard is not None:
50 for key in instances.keys():
51 if re.match(nameWildCard, key):
52 return instances[key]
53 else:
Kailash Khalasif6de2592017-09-13 13:37:14 -070054 return instances
55
Zack Williamsc6722d52020-01-13 16:34:33 -070056
57def get_instance_status(novalist, nameWildCard=None):
58 pairs = re.split(r"\+-*\+-*\+\n?", novalist)[2:-1]
59 ids, names, status, taskState, powerState, networks = [], [], [], [], [], []
Kailash Khalasif6de2592017-09-13 13:37:14 -070060 for p in pairs:
Zack Williamsc6722d52020-01-13 16:34:33 -070061 for l in p.split('\n'):
62 pair = l.split('|')
63 if len(pair) > 1:
64 ids.append(pair[1].strip())
65 names.append(pair[2].strip())
66 status.append(pair[3].strip())
67 taskState.append(pair[4].strip())
68 powerState.append(pair[5].strip())
69 networks.append(pair[6].strip())
70 instances = dict(zip(names, status))
Kailash Khalasif6de2592017-09-13 13:37:14 -070071 if nameWildCard is not None:
72 for key in instances.keys():
73 if re.match(nameWildCard, key):
74 return instances[key]
75 else:
Zack Williamsc6722d52020-01-13 16:34:33 -070076 return instances