summaryrefslogtreecommitdiffstats
path: root/src/python/openlmi/common/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/openlmi/common/__init__.py')
-rw-r--r--src/python/openlmi/common/__init__.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/python/openlmi/common/__init__.py b/src/python/openlmi/common/__init__.py
index 2d19515..baebcdb 100644
--- a/src/python/openlmi/common/__init__.py
+++ b/src/python/openlmi/common/__init__.py
@@ -22,3 +22,21 @@
"""
Common utilities for OpenLMI python providers.
"""
+def parse_instance_id(instance_id, classname=None):
+ """
+ Parse InstanceID, check it has LMI:<classname>:<ID> format and return
+ the ID. Return None if the format is bad.
+ :param instance_id: (``string``) String to parse.
+ :param classname: (``string``) Name of class, whose InstanceID we parse.
+ If the classname is None, it won't be checked.
+ :returns: ``string`` with the ID.
+ """
+ parts = instance_id.split(":", 2)
+ if len(parts) != 3:
+ return None
+ if parts[0] != "LMI":
+ return None
+ real_classname = parts[1]
+ if classname and real_classname.lower() != classname.lower():
+ return None
+ return parts[2]