~u-matt-h/nova/aws-api-validation

« back to all changes in this revision

Viewing changes to bin/clear_rabbit_queues

  • Committer: Matthew Hooker
  • Date: 2011-08-17 23:57:07 UTC
  • mfrom: (1416.1.34 nova)
  • Revision ID: matt@cloudscaling.com-20110817235707-djkwr0r5r8ia2u1x
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
3
 
 
4
# Copyright (c) 2011 Openstack, LLC.
 
5
# All Rights Reserved.
 
6
#
 
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
#    not use this file except in compliance with the License. You may obtain
 
9
#    a copy of the License at
 
10
#
 
11
#         http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#    Unless required by applicable law or agreed to in writing, software
 
14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
#    License for the specific language governing permissions and limitations
 
17
#    under the License.
 
18
 
 
19
"""Admin/debug script to wipe rabbitMQ (AMQP) queues nova uses.
 
20
   This can be used if you need to change durable options on queues,
 
21
   or to wipe all messages in the queue system if things are in a
 
22
   serious bad way.
 
23
 
 
24
"""
 
25
 
 
26
import datetime
 
27
import gettext
 
28
import os
 
29
import sys
 
30
import time
 
31
 
 
32
# If ../nova/__init__.py exists, add ../ to Python search path, so that
 
33
# it will override what happens to be installed in /usr/(local/)lib/python...
 
34
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
 
35
                                   os.pardir,
 
36
                                   os.pardir))
 
37
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
 
38
    sys.path.insert(0, POSSIBLE_TOPDIR)
 
39
 
 
40
gettext.install('nova', unicode=1)
 
41
 
 
42
 
 
43
from nova import context
 
44
from nova import exception
 
45
from nova import flags
 
46
from nova import log as logging
 
47
from nova import rpc
 
48
from nova import utils
 
49
 
 
50
 
 
51
FLAGS = flags.FLAGS
 
52
flags.DEFINE_boolean('delete_exchange', False, 'delete nova exchange too.')
 
53
 
 
54
 
 
55
def delete_exchange(exch):
 
56
    conn = rpc.create_connection()
 
57
    x = conn.get_channel()
 
58
    x.exchange_delete(exch)
 
59
 
 
60
 
 
61
def delete_queues(queues):
 
62
    conn = rpc.create_connection()
 
63
    x = conn.get_channel()
 
64
    for q in queues:
 
65
        x.queue_delete(q)
 
66
 
 
67
if __name__ == '__main__':
 
68
    utils.default_flagfile()
 
69
    args = flags.FLAGS(sys.argv)
 
70
    logging.setup()
 
71
    delete_queues(args[1:])
 
72
    if FLAGS.delete_exchange:
 
73
        delete_exchange(FLAGS.control_exchange)