-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml_parser.py
42 lines (30 loc) · 1.01 KB
/
yaml_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""This is a helper module that allows us to parse yml into objects
"""
from yaml import Loader, load_all
from deployment import Deployment
def read_yaml(data):
"""Read the yml data (stream) and return a generator of yaml data
Args:
data (str): A stream of data to parse (could be a string)
"""
parsed_data = load_all(data, Loader=Loader)
return list(parsed_data)
def get_deployments(data):
"""
Look through the data and pull out a list of deployment objects
from it
Args:
data: the parsed yaml data (nested lists and dicts)
Returns:
A list of Deployment objects
"""
# look for elements of the list that have kind==Deployment
deployments = []
for section in data:
if section.get("kind", "") == "Deployment":
metadata = section.get("metadata", None)
if metadata:
name = metadata.get("name", None)
if name:
deployments.append(Deployment(name))
return deployments