Skip to content

CP-50091: Moved inventory.py from scripts/examples/python/ to python3/packages directory #5750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ install:
$(IPROG) -d $(DESTDIR)$(PLUGINDIR)


$(IDATA) packages/inventory.py $(DESTDIR)$(SITE3_DIR)/
$(IDATA) packages/observer.py $(DESTDIR)$(SITE3_DIR)/

$(IPROG) libexec/host-display $(DESTDIR)$(LIBEXECDIR)
Expand Down
37 changes: 37 additions & 0 deletions python3/packages/inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

"""
inventory.py

This module defines functions to read and parse constants from the xensource-inventory file.
"""
import sys

INVENTORY = "@INVENTORY@"
INSTALLATION_UUID = "INSTALLATION_UUID"


def read_kvpairs(filename):
"""Read in a file of key-value pairs in the format used by the inventory file"""
all_entries = {}
with open(filename, 'r', encoding='utf-8') as f:
for line in f:
equals = line.index("=")
key = line[:equals]
value = line[equals+1:].strip().strip("'")
all_entries[key] = value
return all_entries


def parse():
"""Return the contents of the xensource inventory file as a dictionary"""
try:
return read_kvpairs(INVENTORY)
except FileNotFoundError as e:
print("Error: File '{}' not found. {}".format(INVENTORY, e), file=sys.stderr)
return {}


def get_localhost_uuid():
"""Return the UUID of the local host"""
return parse()[INSTALLATION_UUID]
2 changes: 0 additions & 2 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ install:
ifneq ($(BUILD_PY2), NO)
$(IDATA) examples/python/XenAPIPlugin.py $(DESTDIR)$(SITE_DIR)/
$(IDATA) examples/python/XenAPI/XenAPI.py $(DESTDIR)$(SITE_DIR)/
$(IDATA) examples/python/inventory.py $(DESTDIR)$(SITE_DIR)/
endif
$(IDATA) examples/python/XenAPIPlugin.py $(DESTDIR)$(SITE3_DIR)/
sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/' $(DESTDIR)$(SITE3_DIR)/XenAPIPlugin.py
$(IDATA) examples/python/XenAPI/XenAPI.py $(DESTDIR)$(SITE3_DIR)/
$(IDATA) examples/python/inventory.py $(DESTDIR)$(SITE3_DIR)/
$(IPROG) examples/python/shell.py $(DESTDIR)$(LIBEXECDIR)/shell.py
# YUM plugins
$(IPROG) yum-plugins/accesstoken.py $(DESTDIR)$(YUMPLUGINDIR)
Expand Down
32 changes: 0 additions & 32 deletions scripts/examples/python/inventory.py

This file was deleted.

Loading