Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit c8115d8

Browse files
authored
safe access for AlphaVersion (#797)
Signed-off-by: ltimothy7 <66969084+ltimothy7@users.noreply.github.com>
1 parent d72c615 commit c8115d8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pyvcloud/vcd/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
SIZE_1MB = 1024 * 1024
4444
SYSTEM_ORG_NAME = 'system'
45+
ALPHA_API_SUBSTRING = "alpha"
4546

4647
NSMAP = {
4748
'ns10':
@@ -955,11 +956,17 @@ def get_supported_versions_list(self, include_alpha_versions: bool = False): #
955956
if not hasattr(version, 'deprecated') or \
956957
version.get('deprecated').lower() == 'false':
957958
active_versions.append(str(version.Version.text))
958-
if include_alpha_versions:
959+
if include_alpha_versions and hasattr(versions, "AlphaVersion"):
959960
for version in versions.AlphaVersion:
960961
if not hasattr(version, 'deprecated') or \
961962
version.get('deprecated') == 'false':
962-
active_versions.append(str(version.Version.text))
963+
# alpha version may be of the form `3X.0.0-alpha-12345`
964+
# so we remove the portion after "alpha"
965+
alpha_version = str(version.Version.text)
966+
start_alpha_ind = alpha_version.find(ALPHA_API_SUBSTRING) # noqa: E501
967+
if start_alpha_ind != -1:
968+
alpha_version = alpha_version[:start_alpha_ind + len(ALPHA_API_SUBSTRING)] # noqa: E501
969+
active_versions.append(alpha_version)
963970
active_versions.sort(key=VCDApiVersion)
964971
return active_versions
965972

0 commit comments

Comments
 (0)