Python oslo_utils.excutils.save_and_reraise_exception() Examples

The following are 30 code examples of oslo_utils.excutils.save_and_reraise_exception(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_utils.excutils , or try the search function .
Example #1
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def delete_port_pair_group(self, context, portpairgroup_id):
        portpairgroup = self.get_port_pair_group(context, portpairgroup_id)
        portpairgroup_context = sfc_ctx.PortPairGroupContext(
            self, context, portpairgroup)
        try:
            self.driver_manager.delete_port_pair_group(portpairgroup_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Delete port pair group failed, "
                          "port_pair_group '%s'",
                          portpairgroup_id)

        with db_api.CONTEXT_WRITER.using(context):
            portpairgroup = self.get_port_pair_group(context, portpairgroup_id)
            portpairgroup_context = sfc_ctx.PortPairGroupContext(
                self, context, portpairgroup)
            super(SfcPlugin, self).delete_port_pair_group(context,
                                                          portpairgroup_id)
            self.driver_manager.delete_port_pair_group_precommit(
                portpairgroup_context)
        self.driver_manager.delete_port_pair_group_postcommit(
            portpairgroup_context) 
Example #2
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def update_port_chain(self, context, portchain_id, port_chain):
        with db_api.CONTEXT_WRITER.using(context):
            original_portchain = self.get_port_chain(context, portchain_id)
            updated_portchain = super(SfcPlugin, self).update_port_chain(
                context, portchain_id, port_chain)
            portchain_db_context = sfc_ctx.PortChainContext(
                self, context, updated_portchain,
                original_portchain=original_portchain)
            self.driver_manager.update_port_chain_precommit(
                portchain_db_context)

        try:
            self.driver_manager.update_port_chain_postcommit(
                portchain_db_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Update port chain failed, port_chain '%s'",
                          updated_portchain['id'])

        # TODO(qijing): should we rollback the database update here?
        return updated_portchain 
Example #3
Source File: mount.py    From zun with Apache License 2.0 6 votes vote down vote up
def do_mount(devpath, mountpoint, fstype):
    """Execute device mount operation.

    :param devpath: The path of mount device.
    :param mountpoint: The path of mount point.
    :param fstype: The file system type.
    """
    if check_already_mounted(mountpoint):
        return

    mounter = Mounter()
    try:
        mounter.mount(devpath, mountpoint, fstype)
    except exception.MountException:
        try:
            mounter.make_filesystem(devpath, fstype)
            mounter.mount(devpath, mountpoint, fstype)
        except exception.ZunException as e:
            with excutils.save_and_reraise_exception():
                LOG.error(e.message) 
Example #4
Source File: database_tasks.py    From octavia with Apache License 2.0 6 votes vote down vote up
def execute(self, project_id):
        """Decrements the listener quota.

        :param project_id: The project_id to decrement the quota on.
        :returns: None
        """

        LOG.debug("Decrementing listener quota for "
                  "project: %s ", project_id)

        lock_session = db_apis.get_session(autocommit=False)
        try:
            self.repos.decrement_quota(lock_session,
                                       data_models.Listener,
                                       project_id)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error('Failed to decrement listener quota for project: '
                          '%(proj)s the project may have excess quota in use.',
                          {'proj': project_id})
                lock_session.rollback() 
Example #5
Source File: database_tasks.py    From octavia with Apache License 2.0 6 votes vote down vote up
def execute(self, project_id):
        """Decrements the member quota.

        :param member: The member to decrement the quota on.
        :returns: None
        """

        LOG.debug("Decrementing member quota for "
                  "project: %s ", project_id)

        lock_session = db_apis.get_session(autocommit=False)
        try:
            self.repos.decrement_quota(lock_session,
                                       data_models.Member,
                                       project_id)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error('Failed to decrement member quota for project: '
                          '%(proj)s the project may have excess quota in use.',
                          {'proj': project_id})
                lock_session.rollback() 
Example #6
Source File: manager.py    From zun with Apache License 2.0 6 votes vote down vote up
def _attach_volume(self, context, container, volmap):
        driver = self._get_driver(container)
        context = context.elevated()
        LOG.info('Attaching volume %(volume_id)s to %(host)s',
                 {'volume_id': volmap.cinder_volume_id,
                  'host': CONF.host})
        try:
            driver.attach_volume(context, volmap)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error("Failed to attach volume %(volume_id)s to "
                          "container %(container_id)s",
                          {'volume_id': volmap.cinder_volume_id,
                           'container_id': volmap.container_uuid})
                if volmap.auto_remove:
                    try:
                        driver.delete_volume(context, volmap)
                    except Exception:
                        LOG.exception("Failed to delete volume %s.",
                                      volmap.cinder_volume_id)
                volmap.destroy() 
Example #7
Source File: cinder_workflow.py    From zun with Apache License 2.0 6 votes vote down vote up
def detach_volume(self, context, volmap):
        volume_id = volmap.cinder_volume_id
        try:
            self.cinder_api.begin_detaching(volume_id)
        except cinder_exception.BadRequest as e:
            raise exception.Invalid(_("Invalid volume: %s") %
                                    str(e))

        conn_info = jsonutils.loads(volmap.connection_info)
        if not self._volume_connection_keep(context, volume_id):
            try:
                self._disconnect_volume(conn_info)
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.exception('Failed to disconnect volume %(volume_id)s',
                                  {'volume_id': volume_id})
                    self.cinder_api.roll_detaching(volume_id)

            self.cinder_api.terminate_connection(
                volume_id, get_volume_connector_properties())
        self.cinder_api.detach(volmap) 
Example #8
Source File: barbican_legacy.py    From octavia with Apache License 2.0 6 votes vote down vote up
def delete_cert(self, context, cert_ref, resource_ref, service_name=None):
        """Deregister as a consumer for the specified cert.

        :param context: Oslo context of the request
        :param cert_ref: the UUID of the cert to retrieve
        :param resource_ref: Full HATEOAS reference to the consuming resource
        :param service_name: Friendly name for the consuming service

        :raises Exception: if deregistration fails
        """
        connection = self.auth.get_barbican_client(context.project_id)

        LOG.info('Deregistering as a consumer of %s in Barbican.', cert_ref)
        try:
            connection.containers.remove_consumer(
                container_ref=cert_ref,
                name=service_name,
                url=resource_ref
            )
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error('Error deregistering as a consumer of %s: %s',
                          cert_ref, e) 
Example #9
Source File: manager.py    From zun with Apache License 2.0 6 votes vote down vote up
def _do_container_start(self, context, container):
        LOG.debug('Starting container: %s', container.uuid)
        with self._update_task_state(context, container,
                                     consts.CONTAINER_STARTING):
            try:
                # NOTE(hongbin): capsule shouldn't reach here
                container = self.driver.start(context, container)
                container.started_at = timeutils.utcnow()
                container.save(context)
                return container
            except exception.DockerError as e:
                with excutils.save_and_reraise_exception():
                    LOG.error("Error occurred while calling Docker start "
                              "API: %s", str(e))
                    self._fail_container(context, container, str(e))
            except Exception as e:
                with excutils.save_and_reraise_exception():
                    LOG.exception("Unexpected exception: %s",
                                  str(e))
                    self._fail_container(context, container, str(e)) 
Example #10
Source File: manager.py    From zun with Apache License 2.0 6 votes vote down vote up
def _do_container_create(self, context, container, requested_networks,
                             requested_volumes, pci_requests=None,
                             limits=None):
        LOG.debug('Creating container: %s', container.uuid)

        try:
            rt = self._get_resource_tracker()
            with rt.container_claim(context, container, pci_requests, limits):
                created_container = self._do_container_create_base(
                    context, container, requested_networks, requested_volumes,
                    limits)
                return created_container
        except exception.ResourcesUnavailable as e:
            with excutils.save_and_reraise_exception():
                LOG.exception("Container resource claim failed: %s",
                              str(e))
                self._fail_container(context, container, str(e),
                                     unset_host=True)
                self.reportclient.delete_allocation_for_container(
                    context, container.uuid) 
Example #11
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def create_port_chain(self, context, port_chain):
        with db_api.CONTEXT_WRITER.using(context):
            port_chain_db = super(SfcPlugin, self).create_port_chain(
                context, port_chain)
            portchain_db_context = sfc_ctx.PortChainContext(
                self, context, port_chain_db)
            self.driver_manager.create_port_chain_precommit(
                portchain_db_context)
        try:
            self.driver_manager.create_port_chain_postcommit(
                portchain_db_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Create port chain failed, "
                          "deleting port_chain '%s'",
                          port_chain_db['id'])
                self.delete_port_chain(context, port_chain_db['id'])

        return port_chain_db 
Example #12
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def delete_port_chain(self, context, portchain_id):
        pc = self.get_port_chain(context, portchain_id)
        pc_context = sfc_ctx.PortChainContext(self, context, pc)
        try:
            self.driver_manager.delete_port_chain(pc_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Delete port chain failed, portchain '%s'",
                          portchain_id)

        # TODO(qijing): unsync in case deleted in driver but fail in database
        with db_api.CONTEXT_WRITER.using(context):
            pc = self.get_port_chain(context, portchain_id)
            pc_context = sfc_ctx.PortChainContext(self, context, pc)
            super(SfcPlugin, self).delete_port_chain(context, portchain_id)
            self.driver_manager.delete_port_chain_precommit(pc_context)
        self.driver_manager.delete_port_chain_postcommit(pc_context) 
Example #13
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def update_port_pair(self, context, portpair_id, port_pair):
        with db_api.CONTEXT_WRITER.using(context):
            original_portpair = self.get_port_pair(context, portpair_id)
            updated_portpair = super(SfcPlugin, self).update_port_pair(
                context, portpair_id, port_pair)
            portpair_context = sfc_ctx.PortPairContext(
                self, context, updated_portpair,
                original_portpair=original_portpair)
            self.driver_manager.update_port_pair_precommit(portpair_context)
        try:
            self.driver_manager.update_port_pair_postcommit(portpair_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Update port pair failed, port_pair '%s'",
                          updated_portpair['id'])

        return updated_portpair 
Example #14
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def create_port_pair_group(self, context, port_pair_group):
        with db_api.CONTEXT_WRITER.using(context):
            portpairgroup_db = super(SfcPlugin, self).create_port_pair_group(
                context, port_pair_group)
            portpairgroup_context = sfc_ctx.PortPairGroupContext(
                self, context, portpairgroup_db)
            self.driver_manager.create_port_pair_group_precommit(
                portpairgroup_context)
        try:
            self.driver_manager.create_port_pair_group_postcommit(
                portpairgroup_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Create port pair group failed, "
                          "deleting port_pair_group '%s'",
                          portpairgroup_db['id'])
                self.delete_port_pair_group(context, portpairgroup_db['id'])

        return portpairgroup_db 
Example #15
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def update_port_pair_group(
        self, context, portpairgroup_id, port_pair_group
    ):
        with db_api.CONTEXT_WRITER.using(context):
            original_portpairgroup = self.get_port_pair_group(
                context, portpairgroup_id)
            updated_portpairgroup = super(
                SfcPlugin, self).update_port_pair_group(
                context, portpairgroup_id, port_pair_group)
            portpairgroup_context = sfc_ctx.PortPairGroupContext(
                self, context, updated_portpairgroup,
                original_portpairgroup=original_portpairgroup)
            self.driver_manager.update_port_pair_group_precommit(
                portpairgroup_context)
        try:
            self.driver_manager.update_port_pair_group_postcommit(
                portpairgroup_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Update port pair group failed, "
                          "port_pair_group '%s'",
                          updated_portpairgroup['id'])

        return updated_portpairgroup 
Example #16
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def create_port_pair(self, context, port_pair):
        with db_api.CONTEXT_WRITER.using(context):
            portpair_db = super(SfcPlugin, self).create_port_pair(
                context, port_pair)
            portpair_context = sfc_ctx.PortPairContext(
                self, context, portpair_db)
            self.driver_manager.create_port_pair_precommit(portpair_context)

        try:
            self.driver_manager.create_port_pair_postcommit(portpair_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Create port pair failed, "
                          "deleting port_pair '%s'",
                          portpair_db['id'])
                self.delete_port_pair(context, portpair_db['id'])

        return portpair_db 
Example #17
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def create_service_graph(self, context, service_graph):
        with db_api.CONTEXT_WRITER.using(context):
            service_graph_db = super(SfcPlugin, self).create_service_graph(
                context, service_graph)
            service_graph_db_context = sfc_ctx.ServiceGraphContext(
                self, context, service_graph_db)
            self.driver_manager.create_service_graph_precommit(
                service_graph_db_context)
        try:
            self.driver_manager.create_service_graph_postcommit(
                service_graph_db_context)
        except sfc_exc.SfcDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Create Service Graph failed, "
                          "deleting Service Graph '%s'",
                          service_graph_db['id'])
                self.delete_service_graph(context, service_graph_db['id'])

        return service_graph_db 
Example #18
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def update_service_graph(self, context, id, service_graph):
        with db_api.CONTEXT_WRITER.using(context):
            original_graph = self.get_service_graph(context, id)
            updated_graph = super(SfcPlugin, self).update_service_graph(
                context, id, service_graph)
            service_graph_db_context = sfc_ctx.ServiceGraphContext(
                self, context, updated_graph,
                original_graph=original_graph)
            self.driver_manager.update_service_graph_precommit(
                service_graph_db_context)
        try:
            self.driver_manager.update_service_graph_postcommit(
                service_graph_db_context)
        except sfc_exc.SfcDriverError:
            with excutils.save_and_reraise_exception():
                LOG.error("Update failed, service_graph '%s'",
                          updated_graph['id'])
        return updated_graph 
Example #19
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def create_flow_classifier(self, context, flow_classifier):
        with db_api.CONTEXT_WRITER.using(context):
            fc_db = super(FlowClassifierPlugin, self).create_flow_classifier(
                context, flow_classifier)
            fc_db_context = fc_ctx.FlowClassifierContext(self, context, fc_db)
            self.driver_manager.create_flow_classifier_precommit(
                fc_db_context)

        try:
            self.driver_manager.create_flow_classifier_postcommit(
                fc_db_context)
        except fc_exc.FlowClassifierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Create flow classifier failed, "
                          "deleting flow_classifier '%s'",
                          fc_db['id'])
                self.delete_flow_classifier(context, fc_db['id'])
        return fc_db 
Example #20
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def update_flow_classifier(self, context, id, flow_classifier):
        with db_api.CONTEXT_WRITER.using(context):
            original_flowclassifier = self.get_flow_classifier(context, id)
            updated_fc = super(
                FlowClassifierPlugin, self
            ).update_flow_classifier(
                context, id, flow_classifier)
            fc_db_context = fc_ctx.FlowClassifierContext(
                self, context, updated_fc,
                original_flowclassifier=original_flowclassifier)
            self.driver_manager.update_flow_classifier_precommit(fc_db_context)
        try:
            self.driver_manager.update_flow_classifier_postcommit(
                fc_db_context)
        except fc_exc.FlowClassifierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Update flow classifier failed, "
                          "flow_classifier '%s'",
                          updated_fc['id'])

        return updated_fc 
Example #21
Source File: plugin.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def delete_flow_classifier(self, context, fc_id):
        fc = self.get_flow_classifier(context, fc_id)
        fc_context = fc_ctx.FlowClassifierContext(self, context, fc)
        try:
            self.driver_manager.delete_flow_classifier(fc_context)
        except fc_exc.FlowClassifierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error("Delete flow classifier failed, "
                          "flow_classifier '%s'",
                          fc_id)

        with db_api.CONTEXT_WRITER.using(context):
            fc = self.get_flow_classifier(context, fc_id)
            fc_context = fc_ctx.FlowClassifierContext(self, context, fc)
            super(FlowClassifierPlugin, self).delete_flow_classifier(
                context, fc_id)
            self.driver_manager.delete_flow_classifier_precommit(fc_context)
        self.driver_manager.delete_flow_classifier_postcommit(fc_context) 
Example #22
Source File: __init__.py    From designate with Apache License 2.0 6 votes vote down vote up
def transaction(f):
    """Transaction decorator, to be used on class instances with a
    self.storage attribute
    """
    @retry(cb=_retry_on_deadlock)
    @functools.wraps(f)
    def transaction_wrapper(self, *args, **kwargs):
        self.storage.begin()
        try:
            result = f(self, *args, **kwargs)
            self.storage.commit()
            return result
        except Exception:
            with excutils.save_and_reraise_exception():
                self.storage.rollback()

    transaction_wrapper.__wrapped_function = f
    transaction_wrapper.__wrapper_name = 'transaction'
    return transaction_wrapper 
Example #23
Source File: barbican_key_manager.py    From castellan with Apache License 2.0 6 votes vote down vote up
def _get_secret(self, context, object_id):
        """Returns the metadata of the secret.

        :param context: contains information of the user and the environment
                        for the request (castellan/context.py)
        :param object_id: UUID of the secret
        :return: the secret's metadata
        :raises HTTPAuthError: if object retrieval fails with 401
        :raises HTTPClientError: if object retrieval fails with 4xx
        :raises HTTPServerError: if object retrieval fails with 5xx
        """

        barbican_client = self._get_barbican_client(context)

        try:
            secret_ref = self._create_secret_ref(object_id)
            return barbican_client.secrets.get(secret_ref)
        except (barbican_exceptions.HTTPAuthError,
                barbican_exceptions.HTTPClientError,
                barbican_exceptions.HTTPServerError) as e:
            with excutils.save_and_reraise_exception():
                LOG.error("Error getting secret metadata: %s", e) 
Example #24
Source File: vpn_db.py    From neutron-vpnaas with Apache License 2.0 6 votes vote down vote up
def _get_resource(self, context, model, v_id):
        try:
            r = model_query.get_by_id(context, model, v_id)
        except exc.NoResultFound:
            with excutils.save_and_reraise_exception(reraise=False) as ctx:
                if issubclass(model, vpn_models.IPsecSiteConnection):
                    raise vpnaas.IPsecSiteConnectionNotFound(
                        ipsec_site_conn_id=v_id
                    )
                elif issubclass(model, vpn_models.IKEPolicy):
                    raise vpnaas.IKEPolicyNotFound(ikepolicy_id=v_id)
                elif issubclass(model, vpn_models.IPsecPolicy):
                    raise vpnaas.IPsecPolicyNotFound(ipsecpolicy_id=v_id)
                elif issubclass(model, vpn_models.VPNService):
                    raise vpnaas.VPNServiceNotFound(vpnservice_id=v_id)
                elif issubclass(model, vpn_models.VPNEndpointGroup):
                    raise vpnaas.VPNEndpointGroupNotFound(
                        endpoint_group_id=v_id)
                ctx.reraise = True
        return r 
Example #25
Source File: impl_multi.py    From designate with Apache License 2.0 6 votes vote down vote up
def delete_zone(self, context, zone):
        # Fetch the full zone from Central first, as we may
        # have to recreate it on slave if delete on master fails
        deleted_context = context.deepcopy()
        deleted_context.show_deleted = True

        full_domain = self.central.find_zone(
            deleted_context, {'id': zone['id']})

        self.slave.delete_zone(context, zone)
        try:
            self.master.delete_zone(context, zone)
        except Exception:
            with excutils.save_and_reraise_exception():
                self.slave.create_zone(context, zone)

                [self.slave.create_record(context, zone, record)
                 for record in self.central.find_records(
                     context, {'domain_id': full_domain['id']})] 
Example #26
Source File: database_tasks.py    From octavia with Apache License 2.0 6 votes vote down vote up
def execute(self, member):
        """Decrements the member quota.

        :param member: The member to decrement the quota on.
        :returns: None
        """

        LOG.debug("Decrementing member quota for "
                  "project: %s ", member.project_id)

        lock_session = db_apis.get_session(autocommit=False)
        try:
            self.repos.decrement_quota(lock_session,
                                       data_models.Member,
                                       member.project_id)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error('Failed to decrement member quota for project: '
                          '%(proj)s the project may have excess quota in use.',
                          {'proj': member.project_id})
                lock_session.rollback() 
Example #27
Source File: database_tasks.py    From octavia with Apache License 2.0 6 votes vote down vote up
def execute(self, listener):
        """Decrements the listener quota.

        :param listener: The listener to decrement the quota on.
        :returns: None
        """

        LOG.debug("Decrementing listener quota for "
                  "project: %s ", listener.project_id)

        lock_session = db_apis.get_session(autocommit=False)
        try:
            self.repos.decrement_quota(lock_session,
                                       data_models.Listener,
                                       listener.project_id)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error('Failed to decrement listener quota for project: '
                          '%(proj)s the project may have excess quota in use.',
                          {'proj': listener.project_id})
                lock_session.rollback() 
Example #28
Source File: database_tasks.py    From octavia with Apache License 2.0 6 votes vote down vote up
def execute(self, health_mon):
        """Decrements the health monitor quota.

        :param health_mon: The health monitor to decrement the quota on.
        :returns: None
        """

        LOG.debug("Decrementing health monitor quota for "
                  "project: %s ", health_mon.project_id)

        lock_session = db_apis.get_session(autocommit=False)
        try:
            self.repos.decrement_quota(lock_session,
                                       data_models.HealthMonitor,
                                       health_mon.project_id)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error('Failed to decrement health monitor quota for '
                          'project: %(proj)s the project may have excess '
                          'quota in use.', {'proj': health_mon.project_id})
                lock_session.rollback() 
Example #29
Source File: amphora.py    From octavia with Apache License 2.0 6 votes vote down vote up
def put(self):
        """Update amphora agent configuration"""
        pcontext = pecan_request.context
        context = pcontext.get('octavia_context')
        db_amp = self._get_db_amp(context.session, self.amp_id,
                                  show_deleted=False)

        # Check to see if the amphora is a spare (not associated with an LB)
        if db_amp.load_balancer:
            self._auth_validate_action(
                context, db_amp.load_balancer.project_id,
                constants.RBAC_PUT_CONFIG)
        else:
            self._auth_validate_action(
                context, context.project_id, constants.RBAC_PUT_CONFIG)

        try:
            LOG.info("Sending amphora agent update request for amphora %s to "
                     "the queue.", self.amp_id)
            payload = {constants.AMPHORA_ID: db_amp.id}
            self.client.cast({}, 'update_amphora_agent_config', **payload)
        except Exception:
            with excutils.save_and_reraise_exception(reraise=True):
                LOG.error("Unable to send amphora agent update request for "
                          "amphora %s to the queue.", self.amp_id) 
Example #30
Source File: __init__.py    From designate with Apache License 2.0 6 votes vote down vote up
def transaction_shallow_copy(f):
    """Transaction decorator, to be used on class instances with a
    self.storage attribute where shallow copy of args, kwargs is used
    """
    @retry(cb=_retry_on_deadlock, deep_copy=False)
    @functools.wraps(f)
    def transaction_wrapper(self, *args, **kwargs):
        self.storage.begin()
        try:
            result = f(self, *args, **kwargs)
            self.storage.commit()
            return result
        except Exception:
            with excutils.save_and_reraise_exception():
                self.storage.rollback()

    transaction_wrapper.__wrapped_function = f
    transaction_wrapper.__wrapper_name = 'transaction_shallow_copy'
    return transaction_wrapper