Adit Sarfaty f6b0643782 NSX|V+V3: Preparations for Octavia support
Create internal drivers for each object that will use dictionaries
instead of objects, and will use a generic fail/success notifiers.
The LBaaS nsx-v/v3 drivers will translate the objects to dictionaries
and use the LBaaS callbacks for successful_completion and failed_completion.
Later we can add drivers for Octavia that will use the same internal
drivers.

Change-Id: I5f99f979bd5333ccfc781217379d217d611cb015
2018-06-06 09:17:51 +03:00

65 lines
2.6 KiB
Python

# Copyright 2017 VMware, Inc.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import helpers as log_helpers
from oslo_log import log as logging
from oslo_utils import excutils
from vmware_nsx.common import locking
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v.implementation import l7policy_mgr
LOG = logging.getLogger(__name__)
class EdgeL7RuleManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
@log_helpers.log_method_call
def __init__(self, vcns_driver):
super(EdgeL7RuleManagerFromDict, self).__init__(vcns_driver)
def _handle_l7policy_rules_change(self, context, rule, completor,
delete=False):
# Get the nsx application rule id and edge id
edge_id, app_rule_id = l7policy_mgr.policy_to_edge_and_rule_id(
context, rule['l7policy_id'])
# Create the script for the new policy data.
# The policy obj on the rule is already updated with the
# created/updated/deleted rule.
app_rule = l7policy_mgr.policy_to_application_rule(rule['policy'])
try:
with locking.LockManager.get_lock(edge_id):
# update the backend application rule for the updated policy
self.vcns.update_app_rule(edge_id, app_rule_id, app_rule)
except Exception as e:
with excutils.save_and_reraise_exception():
completor(success=False)
LOG.error('Failed to update L7rules on edge %(edge)s: '
'%(err)s',
{'edge': edge_id, 'err': e})
# complete the transaction
completor(success=True)
def create(self, context, rule, completor):
self._handle_l7policy_rules_change(context, rule, completor)
def update(self, context, old_rule, new_rule, completor):
self._handle_l7policy_rules_change(context, new_rule, completor)
def delete(self, context, rule, completor):
self._handle_l7policy_rules_change(context, rule, completor,
delete=True)