@@ -211,12 +211,10 @@ def security_group_info_for_ports(self, context, ports):
211
211
# this set will be serialized into a list by rpc code
212
212
remote_address_group_info [remote_ag_id ][ethertype ] = set ()
213
213
direction = rule_in_db ['direction' ]
214
- stateful = self ._is_security_group_stateful (context ,
215
- security_group_id )
216
214
rule_dict = {
217
215
'direction' : direction ,
218
216
'ethertype' : ethertype ,
219
- 'stateful' : stateful }
217
+ }
220
218
221
219
for key in ('protocol' , 'port_range_min' , 'port_range_max' ,
222
220
'remote_ip_prefix' , 'remote_group_id' ,
@@ -234,6 +232,13 @@ def security_group_info_for_ports(self, context, ports):
234
232
if rule_dict not in sg_info ['security_groups' ][security_group_id ]:
235
233
sg_info ['security_groups' ][security_group_id ].append (
236
234
rule_dict )
235
+
236
+ # Populate the security group "stateful" flag in the SGs list of rules.
237
+ for sg_id , stateful in self ._get_sgs_stateful_flag (
238
+ context , sg_info ['security_groups' ].keys ()).items ():
239
+ for rule in sg_info ['security_groups' ][sg_id ]:
240
+ rule ['stateful' ] = stateful
241
+
237
242
# Update the security groups info if they don't have any rules
238
243
sg_ids = self ._select_sg_ids_for_ports (context , ports )
239
244
for (sg_id , ) in sg_ids :
@@ -427,13 +432,13 @@ def _select_sg_ids_for_ports(self, context, ports):
427
432
"""
428
433
raise NotImplementedError ()
429
434
430
- def _is_security_group_stateful (self , context , sg_id ):
431
- """Return whether the security group is stateful or not .
435
+ def _get_sgs_stateful_flag (self , context , sg_id ):
436
+ """Return the security groups stateful flag .
432
437
433
- Return True if the security group associated with the given ID
434
- is stateful, else False.
438
+ Returns a dictionary with the SG ID as key and the stateful flag:
439
+ {sg_1: True, sg_2: False, ...}
435
440
"""
436
- return True
441
+ raise NotImplementedError ()
437
442
438
443
439
444
class SecurityGroupServerRpcMixin (SecurityGroupInfoAPIMixin ,
@@ -530,5 +535,5 @@ def _select_ips_for_remote_address_group(self, context,
530
535
return ips_by_group
531
536
532
537
@db_api .retry_if_session_inactive ()
533
- def _is_security_group_stateful (self , context , sg_id ):
534
- return sg_obj .SecurityGroup .get_sg_by_id (context , sg_id ). stateful
538
+ def _get_sgs_stateful_flag (self , context , sg_ids ):
539
+ return sg_obj .SecurityGroup .get_sgs_stateful_flag (context , sg_ids )
0 commit comments