Skip to content

Commit 95ea4a2

Browse files
committed
add get_flavor_from_cname
1 parent f325bed commit 95ea4a2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/python_gardenlinux_lib/cname.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,29 @@ def get_minimal_feature_set(graph):
8383
return set([node for (node, degree) in graph.in_degree() if degree == 0])
8484

8585

86+
def get_flavor_from_cname(cname: str, get_arch: bool = True) -> str:
87+
"""
88+
Extracts the flavor from a canonical name.
89+
90+
:param str cname: Canonical name of an image
91+
:param bool get_arch: Whether to include the architecture in the flavor
92+
:return: Flavor string
93+
"""
94+
95+
# cname:
96+
# azure-gardener_prod_tpm2_trustedboot-amd64-1312.2-80ffcc87
97+
# transform to flavor:
98+
# azure-gardener_prod_tpm2_trustedboot-amd64
99+
100+
platform = cname.split("-")[0]
101+
features = cname.split("-")[1:-1]
102+
arch = cname.split("-")[-1]
103+
104+
if get_arch:
105+
return f"{platform}-{features}-{arch}"
106+
else:
107+
return f"{platform}-{features}"
108+
109+
86110
if __name__ == "__main__":
87111
main()

0 commit comments

Comments
 (0)