Permalink
Browse files

Merge "Add support for all-tenants search opt to secgroup-list"

  • Loading branch information...
2 parents 5cdc584 + fc2d622 commit eb20c5ad6e8499ce137b20713166e854a70367f8 Jenkins committed with openstack-gerrit Sep 14, 2012
Showing with 42 additions and 6 deletions.
  1. +11 −2 novaclient/v1_1/security_groups.py
  2. +16 −1 novaclient/v1_1/shell.py
  3. +15 −3 tests/v1_1/test_security_groups.py
@@ -17,6 +17,8 @@
Security group interface (1.1 extension).
"""
+import urllib
+
from novaclient import base
@@ -61,10 +63,17 @@ def get(self, group_id):
return self._get('/os-security-groups/%s' % group_id,
'security_group')
- def list(self):
+ def list(self, search_opts=None):
"""
Get a list of all security_groups
:rtype: list of :class:`SecurityGroup`
"""
- return self._list("/os-security-groups", "security_groups")
+ search_opts = search_opts or {}
+
+ qparams = dict((k, v) for (k, v) in search_opts.iteritems() if v)
+
+ query_string = '?%s' % urllib.urlencode(qparams) if qparams else ''
+
+ return self._list('/os-security-groups%s' % query_string,
+ 'security_groups')
@@ -1529,9 +1529,24 @@ def do_secgroup_delete(cs, args):
cs.security_groups.delete(_get_secgroup(cs, args.secgroup))
+@utils.arg('--all-tenants',
+ dest='all_tenants',
+ metavar='<0|1>',
+ nargs='?',
+ type=int,
+ const=1,
+ default=0,
+ help='Display information from all tenants (Admin only).')
+@utils.arg('--all_tenants',
+ nargs='?',
+ type=int,
+ const=1,
+ help=argparse.SUPPRESS)
def do_secgroup_list(cs, args):
"""List security groups for the current tenant."""
- _print_secgroups(cs.security_groups.list())
+ all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants))
+ search_opts = {'all_tenants': all_tenants}
+ _print_secgroups(cs.security_groups.list(search_opts=search_opts))
@utils.arg('secgroup', metavar='<secgroup>', help='Name of security group.')
@@ -7,12 +7,24 @@
class SecurityGroupsTest(utils.TestCase):
- def test_list_security_groups(self):
- sgs = cs.security_groups.list()
- cs.assert_called('GET', '/os-security-groups')
+ def _do_test_list_security_groups(self, search_opts, path):
+ sgs = cs.security_groups.list(search_opts=search_opts)
+ cs.assert_called('GET', path)
for sg in sgs:
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
+ def test_list_security_groups_all_tenants_on(self):
+ self._do_test_list_security_groups(
+ None, '/os-security-groups')
+
+ def test_list_security_groups_all_tenants_on(self):
+ self._do_test_list_security_groups(
+ {'all_tenants': 1}, '/os-security-groups?all_tenants=1')
+
+ def test_list_security_groups_all_tenants_off(self):
+ self._do_test_list_security_groups(
+ {'all_tenants': 0}, '/os-security-groups')
+
def test_get_security_groups(self):
sg = cs.security_groups.get(1)
cs.assert_called('GET', '/os-security-groups/1')

0 comments on commit eb20c5a

Please sign in to comment.