3030 required = False ,
3131 help = "Scan for a specific OpenStack notification event type" ,
3232)
33+ parser .add_argument (
34+ "--list-event-types" ,
35+ action = "store_true" ,
36+ help = "List event_type values found in the queue" ,
37+ )
3338parser .add_argument (
3439 "--provision-state" ,
3540 type = str ,
@@ -73,32 +78,37 @@ def callback(ch, method, properties, body):
7378 if message :
7479 parsed ["oslo.message" ] = message
7580
76- if args .event_type or args .provision_state :
77- if args .event_type :
78- event_type = message .get ("event_type" )
79- if event_type == args .event_type :
80- print (json .dumps (parsed , indent = 4 ))
81-
82- if args .provision_state :
83- payload = message .get ("payload" , {})
84- ironic_object = payload .get ("ironic_object.data" , {})
85- provision_state = ironic_object .get ("provision_state" )
86- if provision_state == args .provision_state :
87- print (json .dumps (parsed , indent = 4 ))
88- else :
89- print (json .dumps (parsed , indent = 4 ))
90-
91- if args .destroy :
92- print ("Destroying message." )
93- # Acknowledge that the message has been handled, removing it from the queue.
94- ch .basic_ack (delivery_tag = method .delivery_tag )
81+ event_type = message .get ("event_type" )
9582
83+ if args .list_event_types and message .get ("event_type" , None ):
84+ print (event_type )
9685 else :
97- if args .verbose :
98- print ("Re-queueing the message." )
99-
100- # Requeue the message using using nack
101- ch .basic_nack (delivery_tag = method .delivery_tag , requeue = True )
86+ if args .event_type or args .provision_state :
87+ if args .event_type :
88+ event_type = message .get ("event_type" )
89+ if event_type == args .event_type :
90+ print (json .dumps (parsed , indent = 4 ))
91+
92+ if args .provision_state :
93+ payload = message .get ("payload" , {})
94+ ironic_object = payload .get ("ironic_object.data" , {})
95+ provision_state = ironic_object .get ("provision_state" )
96+ if provision_state == args .provision_state :
97+ print (json .dumps (parsed , indent = 4 ))
98+ else :
99+ print (json .dumps (parsed , indent = 4 ))
100+
101+ if args .destroy :
102+ print ("Destroying message." )
103+ # Acknowledge that the message has been handled, removing it from the queue.
104+ ch .basic_ack (delivery_tag = method .delivery_tag )
105+
106+ else :
107+ if args .verbose :
108+ print ("Re-queueing the message." )
109+
110+ # Requeue the message using using nack
111+ ch .basic_nack (delivery_tag = method .delivery_tag , requeue = True )
102112
103113
104114# Set up the consumer to pull messages from the queue
@@ -108,6 +118,7 @@ def callback(ch, method, properties, body):
108118try :
109119 # Start consuming messages
110120 channel .start_consuming ()
121+
111122except KeyboardInterrupt :
112123 # Gracefully stop the consumer on CTRL+C
113124 print ("\n Stopping consumer." )
0 commit comments