summaryrefslogtreecommitdiff
path: root/rtslib/utils.py
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2013-07-18 10:07:00 -0700
committerAndy Grover <agrover@redhat.com>2013-07-18 11:18:30 -0700
commit7e7251eb5593071165188344b7f17cc1dec1897f (patch)
tree2cffd8458f05c3ff1c5af9981a23cafbbd0c645b /rtslib/utils.py
parent016550c3078e3d2a676da755dcc7d615ba789de3 (diff)
downloadrtslib-fb-7e7251eb5593071165188344b7f17cc1dec1897f.tar.gz
Add support for TPG authentication
TPGs now have auth/* just like NACLs. Refactor auth property code. TPG authentication requires demo-mode (generate_node_acl=1) to work but this commit doesn't make sure it's set. Signed-off-by: Andy Grover <agrover@redhat.com>
Diffstat (limited to 'rtslib/utils.py')
-rw-r--r--rtslib/utils.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/rtslib/utils.py b/rtslib/utils.py
index 70f119d..893c699 100644
--- a/rtslib/utils.py
+++ b/rtslib/utils.py
@@ -366,6 +366,48 @@ def ignored(*exceptions):
except exceptions:
pass
+#
+# These two functions are meant to be used with functools.partial and
+# properties.
+#
+# 'ignore=True' will silently return None if the attribute is not present.
+# This is good for attributes only present in some kernel versions.
+#
+# All curried arguments should be keyword args.
+#
+# These should only be used for attributes that follow the convention of
+# "NULL" having a special sentinel value, such as auth attributes, and
+# that return a string.
+#
+def _get_auth_attr(self, attribute, ignore=False):
+ self._check_self()
+ path = "%s/%s" % (self.path, attribute)
+ try:
+ value = fread(path)
+ except:
+ if not ignore:
+ raise
+ return None
+ if value == "NULL":
+ return ''
+ else:
+ return value
+
+# Auth params take the string "NULL" to unset the attribute
+def _set_auth_attr(self, value, attribute, ignore=False):
+ self._check_self()
+ path = "%s/%s" % (self.path, attribute)
+ value = value.strip()
+ if value == "NULL":
+ raise ValueError("'NULL' is not a permitted value")
+ if value == '':
+ value = "NULL"
+ try:
+ fwrite(path, "%s" % value)
+ except:
+ if not ignore:
+ raise
+
def set_attributes(obj, attr_dict):
for name, value in attr_dict.iteritems():
# Setting some attributes may return an error, before kernel 3.3