Browse Source

Add notification callback events for FWaaS v2

This patch adds notification callback events (AFTER_CREATE,
AFTER_DELETE, AFTER_UPDATE) for firewall group, firewall policy and
firewall rule resource. These events could be used by the other service
such as logging.

TODO: UTs should be added to cover all of code of driver_api in Stein.

Co-Authored-By: Kim Bao Long <longkb@vn.fujitsu.com>
Change-Id: Ic500270718c128284e337301fb2af0e04d850b5d
Partial-Bug: #1720727
tags/13.0.0.0rc1
Nguyen Phuong An 2 years ago
committed by Yushiro FURUKAWA
parent
commit
d865155757
2 changed files with 84 additions and 0 deletions
  1. +6
    -0
      neutron_fwaas/common/fwaas_constants.py
  2. +78
    -0
      neutron_fwaas/services/firewall/service_drivers/driver_api.py

+ 6
- 0
neutron_fwaas/common/fwaas_constants.py View File

@@ -34,3 +34,9 @@ CREATE_FWG = 'create_firewall_group'
# Port events for L2 agent extension
HANDLE_PORT = 'handle_port'
DELETE_PORT = 'delete_port'

# Resource name

FIREWALL_GROUP = 'firewall_group'
FIREWALL_RULE = 'firewall_rule'
FIREWALL_POLICY = 'firewall_policy'

+ 78
- 0
neutron_fwaas/services/firewall/service_drivers/driver_api.py View File

@@ -18,10 +18,13 @@ import copy

import six

from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib import constants as nl_constants
from neutron_lib.plugins import directory
from oslo_log import log as logging

from neutron_fwaas.common import fwaas_constants as const
from neutron_fwaas.db.firewall.v2 import firewall_db_v2


@@ -136,6 +139,7 @@ class FirewallDriverDBMixin(FirewallDriver):

# Firewall Group
def create_firewall_group(self, context, firewall_group):
request_body = firewall_group
with context.session.begin(subtransactions=True):
firewall_group = self.firewall_db.create_firewall_group(
context, firewall_group)
@@ -143,6 +147,13 @@ class FirewallDriverDBMixin(FirewallDriver):
self._update_resource_status(context, firewall_db_v2.FirewallGroup,
firewall_group)
self.create_firewall_group_postcommit(context, firewall_group)

payload = events.DBEventPayload(context=context,
resource_id=firewall_group['id'],
request_body=request_body,
states=(firewall_group,))
registry.publish(
const.FIREWALL_GROUP, events.AFTER_CREATE, self, payload=payload)
return firewall_group

@abc.abstractmethod
@@ -163,6 +174,12 @@ class FirewallDriverDBMixin(FirewallDriver):
self.firewall_db.delete_firewall_group(context, id)
self.delete_firewall_group_postcommit(context, firewall_group)

payload = events.DBEventPayload(context=context,
resource_id=id,
states=(firewall_group,))
registry.publish(
const.FIREWALL_GROUP, events.AFTER_DELETE, self, payload=payload)

@abc.abstractmethod
def delete_firewall_group_precommit(self, context, firewall_group):
pass
@@ -188,6 +205,14 @@ class FirewallDriverDBMixin(FirewallDriver):
context, id, firewall_group_delta)
self.update_firewall_group_postcommit(context, old_firewall_group,
firewall_group)

payload = events.DBEventPayload(context=context,
resource_id=id,
states=(old_firewall_group,
new_firewall_group))
registry.publish(
const.FIREWALL_GROUP, events.AFTER_UPDATE, self, payload=payload)

return firewall_group

@abc.abstractmethod
@@ -202,11 +227,19 @@ class FirewallDriverDBMixin(FirewallDriver):

# Firewall Policy
def create_firewall_policy(self, context, firewall_policy):
request_body = firewall_policy
with context.session.begin(subtransactions=True):
firewall_policy = self.firewall_db.create_firewall_policy(
context, firewall_policy)
self.create_firewall_policy_precommit(context, firewall_policy)
self.create_firewall_policy_postcommit(context, firewall_policy)

payload = events.DBEventPayload(context=context,
resource_id=firewall_policy['id'],
request_body=request_body,
states=(firewall_policy,))
registry.publish(
const.FIREWALL_POLICY, events.AFTER_CREATE, self, payload=payload)
return firewall_policy

@abc.abstractmethod
@@ -223,6 +256,12 @@ class FirewallDriverDBMixin(FirewallDriver):
self.firewall_db.delete_firewall_policy(context, id)
self.delete_firewall_policy_postcommit(context, firewall_policy)

payload = events.DBEventPayload(context=context,
resource_id=id,
states=(firewall_policy,))
registry.publish(
const.FIREWALL_POLICY, events.AFTER_UPDATE, self, payload=payload)

@abc.abstractmethod
def delete_firewall_policy_precommit(self, context, firewall_policy):
pass
@@ -247,6 +286,12 @@ class FirewallDriverDBMixin(FirewallDriver):
context, id, firewall_policy_delta)
self.update_firewall_policy_postcommit(context, old_firewall_policy,
firewall_policy)

payload = events.DBEventPayload(context=context,
resource_id=id,
states=(firewall_policy,))
registry.publish(
const.FIREWALL_POLICY, events.AFTER_UPDATE, self, payload=payload)
return firewall_policy

@abc.abstractmethod
@@ -261,11 +306,19 @@ class FirewallDriverDBMixin(FirewallDriver):

# Firewall Rule
def create_firewall_rule(self, context, firewall_rule):
request_body = firewall_rule
with context.session.begin(subtransactions=True):
firewall_rule = self.firewall_db.create_firewall_rule(
context, firewall_rule)
self.create_firewall_rule_precommit(context, firewall_rule)
self.create_firewall_rule_postcommit(context, firewall_rule)

payload = events.DBEventPayload(context=context,
resource_id=firewall_rule['id'],
request_body=request_body,
states=(firewall_rule,))
registry.publish(
const.FIREWALL_RULE, events.AFTER_CREATE, self, payload=payload)
return firewall_rule

@abc.abstractmethod
@@ -282,6 +335,12 @@ class FirewallDriverDBMixin(FirewallDriver):
self.firewall_db.delete_firewall_rule(context, id)
self.delete_firewall_rule_postcommit(context, firewall_rule)

payload = events.DBEventPayload(context=context,
resource_id=id,
states=(firewall_rule,))
registry.publish(
const.FIREWALL_RULE, events.AFTER_DELETE, self, payload=payload)

@abc.abstractmethod
def delete_firewall_rule_precommit(self, context, firewall_rule):
pass
@@ -306,6 +365,13 @@ class FirewallDriverDBMixin(FirewallDriver):
context, id, firewall_rule_delta)
self.update_firewall_rule_postcommit(context, old_firewall_rule,
firewall_rule)

payload = events.DBEventPayload(context=context,
resource_id=id,
states=(firewall_rule,))
registry.publish(
const.FIREWALL_RULE, events.AFTER_UPDATE, self, payload=payload)

return firewall_rule

@abc.abstractmethod
@@ -323,6 +389,12 @@ class FirewallDriverDBMixin(FirewallDriver):
firewall_policy = self.firewall_db.insert_rule(context, policy_id,
rule_info)
self.insert_rule_postcommit(context, policy_id, rule_info)
payload = events.DBEventPayload(context=context,
resource_id=policy_id,
states=(firewall_policy,))
registry.publish(
const.FIREWALL_POLICY, events.AFTER_UPDATE, self, payload=payload)

return firewall_policy

@abc.abstractmethod
@@ -338,6 +410,12 @@ class FirewallDriverDBMixin(FirewallDriver):
firewall_policy = self.firewall_db.remove_rule(context, policy_id,
rule_info)
self.remove_rule_postcommit(context, policy_id, rule_info)
payload = events.DBEventPayload(context=context,
resource_id=policy_id,
states=(firewall_policy,))

registry.publish(
const.FIREWALL_POLICY, events.AFTER_UPDATE, self, payload=payload)
return firewall_policy

@abc.abstractmethod


Loading…
Cancel
Save