summaryrefslogtreecommitdiff
path: root/openstackclient/network/utils.py
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-05-26 19:29:11 +0000
committerGerrit Code Review <review@openstack.org>2021-05-26 19:29:11 +0000
commit443c311fc288eefe1b9223b6b51a94121ab9d301 (patch)
tree801155f8e1346c03fb80b4b51917b17eb62e47f0 /openstackclient/network/utils.py
parent84a606be675902d75a60efaf46305f670f26548f (diff)
parentb26b7f3440d4f756c0b7906b93751d7e83a733f7 (diff)
downloadpython-openstackclient-443c311fc288eefe1b9223b6b51a94121ab9d301.tar.gz
Merge "Allow to send extra attributes in Neutron related commands"
Diffstat (limited to 'openstackclient/network/utils.py')
-rw-r--r--openstackclient/network/utils.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/openstackclient/network/utils.py b/openstackclient/network/utils.py
index 287f0271..4d4d18e4 100644
--- a/openstackclient/network/utils.py
+++ b/openstackclient/network/utils.py
@@ -11,6 +11,10 @@
# under the License.
#
+from osc_lib import exceptions
+
+from openstackclient.i18n import _
+
# Transform compute security group rule for display.
def transform_compute_security_group_rule(sg_rule):
@@ -39,3 +43,41 @@ def transform_compute_security_group_rule(sg_rule):
else:
info['remote_security_group'] = ''
return info
+
+
+def str2bool(strbool):
+ if strbool is None:
+ return None
+ return strbool.lower() == 'true'
+
+
+def str2list(strlist):
+ result = []
+ if strlist:
+ result = strlist.split(';')
+ return result
+
+
+def str2dict(strdict):
+ """Convert key1:value1;key2:value2;... string into dictionary.
+
+ :param strdict: string in the form of key1:value1;key2:value2
+ """
+ result = {}
+ if not strdict:
+ return result
+ i = 0
+ kvlist = []
+ for kv in strdict.split(';'):
+ if ':' in kv:
+ kvlist.append(kv)
+ i += 1
+ elif i == 0:
+ msg = _("missing value for key '%s'")
+ raise exceptions.CommandError(msg % kv)
+ else:
+ kvlist[i - 1] = "%s;%s" % (kvlist[i - 1], kv)
+ for kv in kvlist:
+ key, sep, value = kv.partition(':')
+ result[key] = value
+ return result