Пример #1
0
    def update(self, context, old_policy, new_policy, completor):
        rule_client = self.core_plugin.nsxlib.load_balancer.rule
        binding = nsx_db.get_nsx_lbaas_l7policy_binding(
            context.session, old_policy['id'])
        if not binding:
            completor(success=False)
            msg = _('Cannot find nsx lbaas binding for policy '
                    '%(policy_id)s') % {
                        'policy_id': old_policy['id']
                    }
            raise n_exc.BadRequest(resource='lbaas-l7policy-update', msg=msg)

        vs_id = binding['lb_vs_id']
        lb_rule_id = binding['lb_rule_id']
        rule_body = lb_utils.convert_l7policy_to_lb_rule(context, new_policy)
        try:
            rule_client.update(lb_rule_id, **rule_body)
            if new_policy['position'] != old_policy['position']:
                self._update_policy_position(vs_id, lb_rule_id,
                                             new_policy['position'])

        except Exception as e:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update L7policy %(policy)s: '
                          '%(err)s', {
                              'policy': old_policy['id'],
                              'err': e
                          })

        completor(success=True)
Пример #2
0
    def _update_l7rule_change(self, context, rule, completor, delete=False):
        rule_client = self.core_plugin.nsxlib.load_balancer.rule
        policy_id = rule['policy']['id']
        binding = nsx_db.get_nsx_lbaas_l7policy_binding(
            context.session, policy_id)
        if not binding:
            completor(success=False)
            msg = _('Cannot find nsx lbaas binding for policy '
                    '%(policy_id)s') % {
                        'policy_id': policy_id
                    }
            raise n_exc.BadRequest(resource='lbaas-l7policy-update', msg=msg)

        lb_rule_id = binding['lb_rule_id']
        if delete:
            lb_utils.remove_rule_from_policy(rule)
        else:
            lb_utils.update_rule_in_policy(rule)
        rule_body = lb_utils.convert_l7policy_to_lb_rule(
            context, rule['policy'])
        try:
            rule_client.update(lb_rule_id, **rule_body)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update L7policy %(policy)s: '
                          '%(err)s', {
                              'policy': policy_id,
                              'err': e
                          })

        completor(success=True)
Пример #3
0
    def _update_l7rule_change(self, context, rule, completor,
                              delete=False):
        rule_client = self.core_plugin.nsxlib.load_balancer.rule
        policy_id = rule['policy']['id']
        binding = nsx_db.get_nsx_lbaas_l7policy_binding(context.session,
                                                        policy_id)
        if not binding:
            completor(success=False)
            msg = _('Cannot find nsx lbaas binding for policy '
                    '%(policy_id)s') % {'policy_id': policy_id}
            raise n_exc.BadRequest(resource='lbaas-l7policy-update', msg=msg)

        lb_rule_id = binding['lb_rule_id']
        if delete:
            lb_utils.remove_rule_from_policy(rule)
        else:
            lb_utils.update_rule_in_policy(rule)
        rule_body = lb_utils.convert_l7policy_to_lb_rule(
            context, rule['policy'])
        try:
            rule_client.update(lb_rule_id, **rule_body)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update L7policy %(policy)s: '
                          '%(err)s', {'policy': policy_id, 'err': e})

        completor(success=True)
Пример #4
0
    def update(self, context, old_policy, new_policy, completor):
        rule_client = self.core_plugin.nsxlib.load_balancer.rule
        binding = nsx_db.get_nsx_lbaas_l7policy_binding(context.session,
                                                        old_policy['id'])
        if not binding:
            completor(success=False)
            msg = _('Cannot find nsx lbaas binding for policy '
                    '%(policy_id)s') % {'policy_id': old_policy['id']}
            raise n_exc.BadRequest(resource='lbaas-l7policy-update', msg=msg)

        vs_id = binding['lb_vs_id']
        lb_rule_id = binding['lb_rule_id']
        rule_body = lb_utils.convert_l7policy_to_lb_rule(context, new_policy)
        try:
            rule_client.update(lb_rule_id, **rule_body)
            if new_policy['position'] != old_policy['position']:
                self._update_policy_position(vs_id, lb_rule_id,
                                             new_policy['position'])

        except Exception as e:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update L7policy %(policy)s: '
                          '%(err)s', {'policy': old_policy['id'], 'err': e})

        completor(success=True)
Пример #5
0
    def create(self, context, policy, completor):
        lb_id = policy['listener']['loadbalancer_id']
        listener_id = policy['listener_id']
        rule_client = self.core_plugin.nsxlib.load_balancer.rule
        tags = lb_utils.get_tags(self.core_plugin, policy['id'],
                                 lb_const.LB_L7POLICY_TYPE,
                                 policy['tenant_id'], context.project_name)

        binding = nsx_db.get_nsx_lbaas_listener_binding(
            context.session, lb_id, listener_id)
        if not binding:
            completor(success=False)
            msg = _('Cannot find nsx lbaas binding for listener '
                    '%(listener_id)s') % {
                        'listener_id': listener_id
                    }
            raise n_exc.BadRequest(resource='lbaas-l7policy-create', msg=msg)

        vs_id = binding['lb_vs_id']
        rule_body = lb_utils.convert_l7policy_to_lb_rule(context, policy)
        try:
            lb_rule = rule_client.create(tags=tags, **rule_body)
        except nsxlib_exc.ManagerError:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to create lb rule at NSX backend')
        try:
            self._update_policy_position(vs_id, lb_rule['id'],
                                         policy['position'])
        except nsxlib_exc.ManagerError:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error(
                    'Failed to add rule %(rule)% to virtual server '
                    '%(vs)s at NSX backend', {
                        'rule': lb_rule['id'],
                        'vs': vs_id
                    })

        nsx_db.add_nsx_lbaas_l7policy_binding(context.session, policy['id'],
                                              lb_rule['id'], vs_id)
        completor(success=True)
Пример #6
0
    def create(self, context, policy, completor):
        lb_id = policy['listener']['loadbalancer_id']
        listener_id = policy['listener_id']
        rule_client = self.core_plugin.nsxlib.load_balancer.rule
        tags = lb_utils.get_tags(self.core_plugin, policy['id'],
                                 lb_const.LB_L7POLICY_TYPE,
                                 policy['tenant_id'], context.project_name)

        binding = nsx_db.get_nsx_lbaas_listener_binding(
            context.session, lb_id, listener_id)
        if not binding:
            completor(success=False)
            msg = _('Cannot find nsx lbaas binding for listener '
                    '%(listener_id)s') % {'listener_id': listener_id}
            raise n_exc.BadRequest(resource='lbaas-l7policy-create', msg=msg)

        vs_id = binding['lb_vs_id']
        rule_body = lb_utils.convert_l7policy_to_lb_rule(context, policy)
        try:
            lb_rule = rule_client.create(tags=tags, **rule_body)
        except nsxlib_exc.ManagerError:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to create lb rule at NSX backend')
        try:
            self._update_policy_position(vs_id, lb_rule['id'],
                                         policy['position'])
        except nsxlib_exc.ManagerError:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to add rule %(rule)% to virtual server '
                          '%(vs)s at NSX backend', {'rule': lb_rule['id'],
                                                    'vs': vs_id})

        nsx_db.add_nsx_lbaas_l7policy_binding(
            context.session, policy['id'], lb_rule['id'], vs_id)
        completor(success=True)