Skip to content

Commit 7c1fa01

Browse files
committed
adds detecction of missing os tools to report os-release #495
1 parent bb61e32 commit 7c1fa01

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
id: meta_dhub
7272
uses: docker/metadata-action@v5
7373
with:
74-
images: docker.io/bbricardo/${{ steps.docker_image.outputs.lowercase }}
74+
images: docker.io/bbricardo/netbox-sync:${{ github.ref.name }}
7575
tags: |
7676
type=semver,pattern={{version}}
7777
type=ref,event=branch

module/sources/vmware/connection.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,22 +2186,30 @@ def add_virtual_machine(self, obj):
21862186

21872187
# first try 'guestInfo.detailed.data' and then 'guestOS.detailed.data'
21882188
detailed_data = extra_config.get("guestInfo.detailed.data") or extra_config.get("guestOS.detailed.data")
2189+
2190+
# if guestOS tools ar installed but are not able to determine the os-release
2191+
# then check against this pattern to guess if a correct os string has been returned
2192+
invalid_patterns = ["Usage:", "Error:", "command not found", "No such file"]
2193+
21892194
if isinstance(detailed_data, str):
21902195
detailed_data_dict = dict()
2196+
pretty_name = None
21912197
for detailed_data_item in quoted_split(detailed_data.replace("' ", "', ")):
21922198
if "=" not in detailed_data_item:
21932199
continue
21942200

21952201
detailed_data_key, detailed_data_value = detailed_data_item.split("=")
21962202
detailed_data_dict[detailed_data_key] = detailed_data_value.strip("'")
21972203
if len(detailed_data_dict.get("prettyName", "")) > 0:
2198-
platform = detailed_data_dict.get("prettyName")
2199-
2200-
distro_version = detailed_data_dict.get("distroVersion")
2201-
if detailed_data_dict.get("familyName", "").lower() == "linux" and \
2202-
distro_version is not None and \
2203-
distro_version not in platform:
2204-
platform = f'{platform} {distro_version}'
2204+
pretty_name = detailed_data_dict.get("prettyName")
2205+
2206+
if pretty_name and not any(pretty_name.startswith(p) for p in invalid_patterns):
2207+
platform = pretty_name
2208+
distro_version = detailed_data_dict.get("distroVersion")
2209+
if detailed_data_dict.get("familyName", "").lower() == "linux" and \
2210+
distro_version is not None and \
2211+
distro_version not in platform:
2212+
platform = f'{platform} {distro_version}'
22052213

22062214
if platform is not None:
22072215
platform = self.get_object_relation(platform, "vm_platform_relation", fallback=platform)

0 commit comments

Comments
 (0)