From 852e2e5f3116844ea996bec6a1c9b15a463928da Mon Sep 17 00:00:00 2001 From: Vincent Hou Date: Wed, 31 Jul 2013 05:47:53 -0400 Subject: [PATCH] Check whether the security group id is integer Fixed Bug 1206847. Change-Id: I2194d6538a5c5475b876ee026b5d625be2df076f --- novaclient/utils.py | 9 +++++++++ novaclient/v1_1/shell.py | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/novaclient/utils.py b/novaclient/utils.py index 532ea976c..1bea47b6c 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -353,3 +353,12 @@ def _load_entry_point(ep_name, name=None): return ep.load() except (ImportError, pkg_resources.UnknownExtra, AttributeError): continue + + +def is_integer_like(val): + """Returns validation of a value as an integer.""" + try: + value = int(val) + return True + except (TypeError, ValueError, AttributeError): + return False diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 9b3aca5c6..c044cf49d 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -30,7 +30,6 @@ import time from novaclient import exceptions from novaclient.openstack.common import strutils from novaclient.openstack.common import timeutils -from novaclient.openstack.common import uuidutils from novaclient import utils from novaclient.v1_1 import availability_zones from novaclient.v1_1 import quotas @@ -1918,7 +1917,7 @@ def _print_secgroups(secgroups): def _get_secgroup(cs, secgroup): # Check secgroup is an ID - if uuidutils.is_uuid_like(strutils.safe_encode(secgroup)): + if utils.is_integer_like(strutils.safe_encode(secgroup)): try: return cs.security_groups.get(secgroup) except exceptions.NotFound: