summaryrefslogtreecommitdiff
path: root/openstackclient/network/utils.py
diff options
context:
space:
mode:
authorSlawek Kaplonski <skaplons@redhat.com>2020-12-22 15:31:44 +0100
committerSlawek Kaplonski <skaplons@redhat.com>2021-05-26 09:29:15 +0200
commitb26b7f3440d4f756c0b7906b93751d7e83a733f7 (patch)
treee318e4700f87222b87a4e677e2f7f4dbcf518fae /openstackclient/network/utils.py
parent6bdf030953d449693c97bff8812b7ced981a2015 (diff)
downloadpython-openstackclient-b26b7f3440d4f756c0b7906b93751d7e83a733f7.tar.gz
Allow to send extra attributes in Neutron related commands
To deprecate and drop support for neutronclient CLI and use only OSC we need feature parity between OSC and neutronclient. Last missing piece here is possibility to send in POST/PUT requests unknown parameters to the Neutron server. This patch adds such possibility to the OSC. Change-Id: Iba09297c2be9fb9fa0be1b3dc65755277b79230e
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