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()
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()
def create_exchanges(): print "Verifying exchanges" # Create all the AMQP exchanges we require. This should be run before we try # to have ceilometer send zenoss any events. zcml.load_config('meta.zcml', zope.component) zcml.load_config('configure.zcml', zope.component) zcml.load_config('configure.zcml', Products.ZenMessaging.queuemessaging) connectionInfo = getUtility(IAMQPConnectionInfo) queueSchema = getUtility(IQueueSchema) amqpClient = BlockingPublisher(connectionInfo, queueSchema) channel = amqpClient.getChannel() for exchange in ('$OpenStackInbound', ): exchangeConfig = queueSchema.getExchange(exchange) print "Verifying configuration of exchange '%s' (%s)" % (exchange, exchangeConfig.name) # Declare the exchange to which the message is being sent getAdapter(channel, IAMQPChannelAdapter).declareExchange(exchangeConfig) amqpClient.close()
def reconnect(self): connectionInfo = getUtility(IAMQPConnectionInfo) queueSchema = getUtility(IQueueSchema) self._client = BlockingPublisher(connectionInfo, queueSchema)