Skip to content

Commit 661da45

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add security group commands"
2 parents 9ec1cf3 + c94e262 commit 661da45

9 files changed

Lines changed: 996 additions & 2 deletions

File tree

‎openstack-common.conf‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module=cfg
55
module=iniparser
66
module=install_venv_common
77
module=openstackkeyring
8+
module=strutils
89

910
# The base module to hold the copy of openstack.common
1011
base=openstackclient

‎openstackclient/common/parseractions.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,27 @@ def __call__(self, parser, namespace, values, option_string=None):
3232
getattr(namespace, self.dest, {}).update([values.split('=', 1)])
3333
else:
3434
getattr(namespace, self.dest, {}).pop(values, None)
35+
36+
37+
class RangeAction(argparse.Action):
38+
"""A custom action to parse a single value or a range of values."""
39+
def __call__(self, parser, namespace, values, option_string=None):
40+
range = values.split(':')
41+
if len(range) == 0:
42+
# Nothing passed, return a zero default
43+
setattr(namespace, self.dest, (0, 0))
44+
elif len(range) == 1:
45+
# Only a single value is present
46+
setattr(namespace, self.dest, (int(range[0]), int(range[0])))
47+
elif len(range) == 2:
48+
# Range of two values
49+
if int(range[0]) <= int(range[1]):
50+
setattr(namespace, self.dest, (int(range[0]), int(range[1])))
51+
else:
52+
msg = "Invalid range, %s is not less than %s" % \
53+
(range[0], range[1])
54+
raise argparse.ArgumentError(self, msg)
55+
else:
56+
# Too many values
57+
msg = "Invalid range, too many values"
58+
raise argparse.ArgumentError(self, msg)

‎openstackclient/common/utils.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
"""Common client utilities"""
1717

1818
import os
19+
import six
1920
import sys
2021
import time
2122
import uuid
2223

2324
from openstackclient.common import exceptions
25+
from openstackclient.openstack.common import strutils
2426

2527

2628
def find_resource(manager, name_or_id):
@@ -84,7 +86,8 @@ def format_dict(data):
8486

8587
output = ""
8688
for s in data:
87-
output = output + s + "='" + data[s] + "', "
89+
output = output + s + "='" + \
90+
strutils.safe_encode(six.text_type(data[s])) + "', "
8891
return output[:-2]
8992

9093

0 commit comments

Comments
 (0)