Example #1
0
 def create_router(self, context, router):
     self._warn_on_state_status(router['router'])
     # this also validates if the current tenant can create this router
     tenant_id = Util.get_tenant_id_for_create(context, router['router'])
     # cache the transaction_id
     bsn_transaction_id = uuidutils.generate_uuid()
     # add this unique identifier to the router object upstream, so that it
     # reaches the pre-commit callback
     router['router'][BSN_TRANSACTION_ID] = bsn_transaction_id
     try:
         new_router = super(L3RestProxy,
                            self).create_router(context, router)
         return new_router
     except Exception:
         with excutils.save_and_reraise_exception():
             try:
                 router_id = self.txn_cache.remove_transaction(
                     bsn_transaction_id)
                 self.servers.rest_delete_router(tenant_id, router_id)
             except Exception as e:
                 LOG.error(
                     _LE("Cannot clean up the router object created "
                         "on BCF. Exception: %(exc)s"), {'exc': e})
     finally:
         self.txn_cache.remove_transaction(bsn_transaction_id)
 def bsn_delete_sg_rule(self, sg_rule, context):
     LOG.debug("Deleting security group rule from BCF: %s", sg_rule)
     if not context:
         LOG.error(
             _LE("Context missing when trying to delete security group rule. "
                 "Please force-bcf-sync to ensure consistency with BCF."))
     sg_id = sg_rule['security_group_id']
     # we over write the sg on bcf controller instead of deleting
     try:
         self.bsn_create_security_group(sg_id, context=context)
     except ext_sg.SecurityGroupNotFound:
         # DB query will throw exception when security group is
         # being deleted. delete_security_group_rule callback would
         # try to update BCF with new set of rules.
         LOG.warning(
             _LW("Security group with ID %(sg_id)s not found "
                 "when trying to update."), {'sg_id': sg_id})
Example #3
0
 def add_router_interface(self, context, router_id, interface_info):
     bsn_transaction_id = uuidutils.generate_uuid()
     interface_info[BSN_TRANSACTION_ID] = bsn_transaction_id
     try:
         new_intf_info = super(L3RestProxy, self).add_router_interface(
             context, router_id, interface_info)
         return new_intf_info
     except Exception:
         with excutils.save_and_reraise_exception():
             try:
                 router = self._get_router(context, router_id)
                 tenant_id = router['tenant_id']
                 interface_id = self.txn_cache.remove_transaction(
                     bsn_transaction_id)
                 # we use port's subnet_id as interface's id
                 self.servers.rest_remove_router_interface(
                     tenant_id, router_id, interface_id)
             except Exception as e:
                 LOG.error(
                     _LE("Cannot clean up router interface created "
                         "on BCF. Exception: %(exc)s"), {'exc': e})
     finally:
         self.txn_cache.remove_transaction(bsn_transaction_id)
Example #4
0
    def rest_action(self, action, resource, data='', errstr='%s',
                    ignore_codes=None, headers=None, timeout=False):
        """rest_action

        Wrapper for rest_call that verifies success and raises a
        RemoteRestError on failure with a provided error string
        By default, 404 errors on DELETE calls are ignored because
        they already do not exist on the backend.
        """
        ignore_codes = ignore_codes or []
        headers = headers or {}
        if not ignore_codes and action == 'DELETE':
            ignore_codes = [404]
        resp = self.rest_call(action, resource, data, headers, ignore_codes,
                              timeout)
        if self.server_failure(resp, ignore_codes):
            # Request wasn't success, nor can be ignored,
            # do a full synchronization if auto_sync_on_failure is True
            if (cfg.CONF.RESTPROXY.auto_sync_on_failure and
                    resource != TOPOLOGY_PATH):
                LOG.error(_LE("NeutronRestProxyV2: Inconsistency with backend "
                              "controller, triggering full synchronization. "
                              "%(action)s %(resource)s."),
                          {'action': action, 'resource': resource})
                sync_executed, topo_resp = self.force_topo_sync(check_ts=True)
                if sync_executed:
                    return topo_resp
            # either topo_sync not executed or topo_sync itself failed
            LOG.error(errstr, resp[2])
            raise RemoteRestError(reason=resp[2], status=resp[0])
        if resp[0] in ignore_codes:
            LOG.info("NeutronRestProxyV2: Received and ignored error "
                     "code %(code)s on %(action)s action to resource "
                     "%(resource)s",
                     {'code': resp[2], 'action': action,
                      'resource': resource})
        return resp