Esempio n. 1
0
def removeZenPackQueuesExchanges(path):
    """
    Attempts to remove all the queues that the zenpack registered

    @type  Path: string
    @param Path: Absolute path to the zenpack (from zenpack.path())
    """
    schema = _loadQjs(path)
    if not schema:
        # no queues to remove
        return

    connectionInfo = getUtility(IAMQPConnectionInfo)
    queueSchema = getUtility(IQueueSchema)
    amqpClient = BlockingPublisher(connectionInfo, queueSchema)
    channel = amqpClient.getChannel()
    queues = schema[0].get('queues', [])
    exchanges = schema[0].get('exchanges', [])
    log = logging.getLogger('zen.ZenMessaging')

    # queues
    for identifier, queue in queues.iteritems():
        name = queue['name']
        try:
            substitute_replacements(name, None)
        except MissingReplacementException:
            # Ignore these - they can't be automatically deleted
            continue
        try:
            log.info("Removing queue %s", name)
            channel.queue_delete(name)
        except Exception as e:
            # the queue might already be deleted etc, do not fail if we can't
            # remove it
            log.debug(e)
            log.info("Unable to remove queue %s", name)

    # exchanges
    for identifier, exchange in exchanges.iteritems():
        name = exchange['name']
        try:
            log.info("Removing exchange %s", name)
            channel.exchange_delete(name)
        except Exception as e:
            # the queue might already be deleted etc, do not fail if we can't
            # remove it
            log.debug(e)
            log.info("Unable to remove exchange %s", name)
    amqpClient.close()
Esempio n. 2
0
def onDeviceDeleted(object, event):
    # Clean up any AMQP queues we may have created for this device.

    if not IObjectWillBeAddedEvent.providedBy(event):
        connectionInfo = getUtility(IAMQPConnectionInfo)
        queueSchema = getUtility(IQueueSchema)

        # For some reason, if an error gets thrown by queue_delete, it seems
        # to break the connection, so we'll just use a separate connection
        # for each call to it.
        for queue in ('$OpenStackInboundEvent', '$OpenStackInboundPerf'):
            queueName = substitute_replacements(queueSchema._queue_nodes[queue].name,
                                                {'device': object.id})

            amqpClient = BlockingPublisher(connectionInfo, queueSchema)
            channel = amqpClient.getChannel()
            try:
                LOG.debug("Removing AMQP queue %s" % queueName)
                channel.queue_delete(queueName)
                LOG.info("Removed AMQP queue %s successfully." % queueName)
            except AMQPChannelException, e:
                # if the queue doesn't exist, don't worry about it.
                if e.amqp_reply_code == 404:
                    LOG.debug('Queue %s did not exist', queueName)
                else:
                    LOG.exception(e)

            amqpClient.close()
Esempio n. 3
0
def removeZenPackQueuesExchanges(path):
    """
    Attempts to remove all the queues that the zenpack registered

    @type  Path: string
    @param Path: Absolute path to the zenpack (from zenpack.path())
    """
    schema = _loadQjs(path)
    if not schema:
        # no queues to remove
        return

    connectionInfo = getUtility(IAMQPConnectionInfo)
    queueSchema = getUtility(IQueueSchema)
    amqpClient = BlockingPublisher(connectionInfo, queueSchema)
    channel = amqpClient.getChannel()
    queues = schema[0].get('queues', [])
    exchanges = schema[0].get('exchanges', [])
    log = logging.getLogger('zen.ZenMessaging')

    # queues
    for identifier, queue  in queues.iteritems():
        name = queue['name']
        try:
            substitute_replacements(name, None)
        except MissingReplacementException:
            # Ignore these - they can't be automatically deleted
            continue
        try:
            log.info("Removing queue %s", name)
            channel.queue_delete(name)
        except Exception, e:
            # the queue might already be deleted etc, do not fail if we can't
            # remove it
            log.debug(e)
            log.info("Unable to remove queue %s", name)