@@ -90,3 +90,92 @@ def getNewestCatalogTag(arch="amd64") -> str | None:
9090 return None
9191 else :
9292 return catalogs [- 1 ]
93+
94+
95+ def getOCPLifecycleData () -> dict | None :
96+ """
97+ Load OpenShift Container Platform lifecycle data.
98+
99+ This function reads the OCP lifecycle YAML file containing General Availability dates,
100+ Standard Support end dates, and Extended Update Support (EUS) end dates for various
101+ OCP versions.
102+
103+ Returns:
104+ dict: The OCP lifecycle data dictionary with version information.
105+ Returns None if the ocp.yaml file doesn't exist.
106+
107+ Example:
108+ >>> data = getOCPLifecycleData()
109+ >>> if data:
110+ ... versions = data.get('ocp_versions', {})
111+ ... ocp_416 = versions.get('4.16', {})
112+ ... print(ocp_416.get('ga_date'))
113+ 'June 27, 2024'
114+ """
115+ moduleFile = path .abspath (__file__ )
116+ modulePath = path .dirname (moduleFile )
117+ ocpFileName = "ocp.yaml"
118+
119+ pathToOCP = path .join (modulePath , ocpFileName )
120+ if not path .exists (pathToOCP ):
121+ return None
122+
123+ with open (pathToOCP ) as stream :
124+ return yaml .safe_load (stream )
125+
126+
127+ def getOCPVersion (version : str ) -> dict | None :
128+ """
129+ Get lifecycle information for a specific OCP version.
130+
131+ This function retrieves the General Availability date, Standard Support end date,
132+ and Extended Update Support (EUS) end date for a specific OpenShift version.
133+
134+ Args:
135+ version (str): The OCP version (e.g., "4.16", "4.17").
136+
137+ Returns:
138+ dict: Dictionary containing 'ga_date', 'standard_support', and 'extended_support'.
139+ Returns None if the version is not found or OCP data doesn't exist.
140+
141+ Example:
142+ >>> version_info = getOCPVersion("4.16")
143+ >>> if version_info:
144+ ... print(f"GA: {version_info['ga_date']}")
145+ ... print(f"Standard Support: {version_info['standard_support']}")
146+ ... print(f"Extended Support: {version_info['extended_support']}")
147+ GA: June 27, 2024
148+ Standard Support: December 27, 2025
149+ Extended Support: June 27, 2027
150+ """
151+ ocp_data = getOCPLifecycleData ()
152+ if not ocp_data :
153+ return None
154+
155+ ocp_versions = ocp_data .get ("ocp_versions" , {})
156+ return ocp_versions .get (version )
157+
158+
159+ def listOCPVersions () -> list :
160+ """
161+ List all OCP versions with lifecycle data available.
162+
163+ This function returns a sorted list of all OpenShift Container Platform versions
164+ that have lifecycle information defined.
165+
166+ Returns:
167+ list: Sorted list of OCP version strings (e.g., ["4.12", "4.13", "4.14", ...]).
168+ Returns empty list if OCP data doesn't exist.
169+
170+ Example:
171+ >>> versions = listOCPVersions()
172+ >>> print(versions)
173+ ['4.12', '4.13', '4.14', '4.15', '4.16', '4.17', '4.18', '4.19']
174+ """
175+ ocp_data = getOCPLifecycleData ()
176+ if not ocp_data :
177+ return []
178+
179+ ocp_versions = ocp_data .get ("ocp_versions" , {})
180+ # Sort versions numerically (4.12, 4.13, etc.)
181+ return sorted (ocp_versions .keys (), key = lambda v : [int (x ) for x in v .split ("." )])
0 commit comments