summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Vu-Brugier <cvubrugier@fastmail.fm>2015-01-09 21:07:43 +0100
committerChristophe Vu-Brugier <cvubrugier@fastmail.fm>2015-01-09 21:21:22 +0100
commit08882e7b260cf53cbb7acf4bed70f82aad300b8c (patch)
tree12d8c5abee2141981e06102ea5c9e8036a51c225
parent3947c435cb32f8f8347b8f51f8dde967ac0d47c6 (diff)
downloadtargetcli-08882e7b260cf53cbb7acf4bed70f82aad300b8c.tar.gz
Add UI parameter type helper for "Yes" and "No" boolean values
The iSCSI RFC defines boolean values as "Yes" and "No" and the LIO iSCSI target follows this convention to store boolean iSCSI session parameters (e.g. ImmediateData=Yes). So it makes sense to have a dedicated helper to validate them in targetcli. Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
-rw-r--r--targetcli/ui_node.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/targetcli/ui_node.py b/targetcli/ui_node.py
index 5abfd7f..883fb4d 100644
--- a/targetcli/ui_node.py
+++ b/targetcli/ui_node.py
@@ -101,6 +101,29 @@ class UINode(ConfigNode):
ConfigNode.ui_setgroup_global(self, parameter, value)
self.get_root().refresh()
+ def ui_type_yesno(self, value=None, enum=False, reverse=False):
+ '''
+ UI parameter type helper for "Yes" and "No" boolean values.
+ "Yes" and "No" are used for boolean iSCSI session parameters.
+ '''
+ if reverse:
+ if value is not None:
+ return value
+ else:
+ return 'n/a'
+ type_enum = ('Yes', 'No')
+ syntax = '|'.join(type_enum)
+ if value is None:
+ if enum:
+ return enum_type
+ else:
+ return syntax
+ elif value in type_enum:
+ return value
+ else:
+ raise ValueError("Syntax error, '%s' is not %s."
+ % (value, syntax))
+
class UIRTSLibNode(UINode):
'''