File 0001-Fix-listing-security-group-rules-when-there-are-too-.patch of Package python-neutronclient
From 6584861c806388ececf7427c466fcfd7b017f6e7 Mon Sep 17 00:00:00 2001
From: Vincent Untz <vuntz@suse.com>
Date: Wed, 22 Jan 2014 12:19:04 +0100
Subject: [PATCH] Fix listing security group rules when there are too many
security groups
We're hitting a RequestURITooLong exception.
Change-Id: I4ac6447281f4bceb5587c891a900379a073d93bf
Closes-Bug: 1271462
---
neutronclient/neutron/v2_0/securitygroup.py | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
Index: python-neutronclient-2.3.4/neutronclient/neutron/v2_0/securitygroup.py
===================================================================
--- python-neutronclient-2.3.4.orig/neutronclient/neutron/v2_0/securitygroup.py
+++ python-neutronclient-2.3.4/neutronclient/neutron/v2_0/securitygroup.py
@@ -17,6 +17,7 @@
import argparse
import logging
+from neutronclient.common import exceptions
from neutronclient.neutron import v2_0 as neutronV20
from neutronclient.openstack.common.gettextutils import _
@@ -100,6 +101,9 @@ class UpdateSecurityGroup(neutronV20.Upd
class ListSecurityGroupRule(neutronV20.ListCommand):
"""List security group rules that belong to a given tenant."""
+ # Length of a query filter on security group rule id
+ # id=<uuid>& (with len(uuid)=36)
+ sec_group_id_filter_len = 40
resource = 'security_group_rule'
log = logging.getLogger(__name__ + '.ListSecurityGroupRule')
list_columns = ['id', 'security_group_id', 'direction', 'protocol',
@@ -141,9 +145,28 @@ class ListSecurityGroupRule(neutronV20.L
for rule in data:
for key in self.replace_rules:
sec_group_ids.add(rule[key])
- search_opts.update({"id": sec_group_ids})
- secgroups = neutron_client.list_security_groups(**search_opts)
- secgroups = secgroups.get('security_groups', [])
+ sec_group_ids = list(sec_group_ids)
+
+ def _get_sec_group_list(sec_group_ids):
+ search_opts['id'] = sec_group_ids
+ return neutron_client.list_security_groups(
+ **search_opts).get('security_groups', [])
+
+ try:
+ secgroups = _get_sec_group_list(sec_group_ids)
+ except exceptions.RequestURITooLong as uri_len_exc:
+ # The URI is too long because of too many sec_group_id filters
+ # Use the excess attribute of the exception to know how many
+ # sec_group_id filters can be inserted into a single request
+ sec_group_count = len(sec_group_ids)
+ max_size = ((self.sec_group_id_filter_len * sec_group_count) -
+ uri_len_exc.excess)
+ chunk_size = max_size / self.sec_group_id_filter_len
+ secgroups = []
+ for i in range(0, sec_group_count, chunk_size):
+ secgroups.extend(
+ _get_sec_group_list(sec_group_ids[i: i + chunk_size]))
+
sg_dict = dict([(sg['id'], sg['name'])
for sg in secgroups if sg['name']])
for rule in data: