Here's my code, i'm using pika library instead of amqplib.<div><br></div><div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<p class="p1">import<span class="s1"> pika</span></p>
<p class="p2">connection = pika.BlockingConnection(pika.ConnectionParameters(host=<span class="s2">'localhost'</span>,credentials=pika.PlainCredentials(username=<span class="s2">'guest'</span>,password=<span class="s2">'nova'</span>)))</p>
<p class="p2">channel = connection.channel()</p>
<p class="p3"><span class="s3">print</span><span class="s1"> </span>' [*] Waiting for messages. To exit press CTRL+C'</p>
<p class="p4"><br></p>
<p class="p2"><span class="s3">def</span> callback(ch, method, properties, body):</p>
<p class="p5"><span class="s1"> </span><span class="s3">print</span><span class="s1"> </span>" [x] Method:"<span class="s1">,method</span></p>
<p class="p5"><span class="s1"> </span><span class="s3">print</span><span class="s1"> </span>" Properties:"<span class="s1">, properties </span></p>
<p class="p5"><span class="s1"> </span><span class="s3">print</span><span class="s1"> </span>" Received %r"<span class="s1"> % (body,)</span></p>
<p class="p4"><br></p>
<p class="p4"><br></p>
<p class="p2">result = channel.queue_declare(exclusive=True)</p>
<p class="p2">queue_name = result.method.queue</p>
<p class="p4"><br></p>
<p class="p2">channel.exchange_declare(exchange=<span class="s2">'nova'</span>,type=<span class="s2">'topic'</span>)</p>
<p class="p2">channel.queue_bind(exchange=<span class="s2">'nova'</span>,queue=queue_name, routing_key = <span class="s2">'notifications.#'</span>)</p>
<p class="p2">channel.queue_bind(exchange=<span class="s2">'nova'</span>,queue=queue_name, routing_key = <span class="s2">'compute.#'</span>)</p>
<p class="p2">channel.basic_consume(callback,</p>
<p class="p2"> queue=queue_name,</p>
<p class="p2"> no_ack=True)</p>
<p class="p4"><br></p>
<p class="p2">channel.start_consuming()</p></blockquote><br><div class="gmail_quote">On Thu, Mar 29, 2012 at 6:50 PM, Rogério Vinhal Nunes <span dir="ltr"><<a href="mailto:rogervn@dcc.ufmg.br">rogervn@dcc.ufmg.br</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Actually, I'm having problems in a much simpler layer. I've done the following code thinking that I would start from there to find info:<br>
<br>---------------------<br>conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)<br>
chan = conn.channel()<br>chan.queue_bind(queue="compute", exchange="nova", routing_key="<a href="http://notifications.info" target="_blank">notifications.info</a>")<br><br>def recv_callback(msg):<br>
print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id)<br>
<br>chan.basic_consume(queue='compute', no_ack=True, callback=recv_callback, consumer_tag="testtag")<br>while True:<br> chan.wait()<br>chan.basic_cancel("testtag")<br><br><br>chan.close()<br>
conn.close()<br>---------------------<br><br>But I get no messages at all. The script just stays still. I've added "--notification_driver=nova.notifier.rabbit_notifier" to nova.conf also.<br><br><div class="gmail_quote">
Em 28 de março de 2012 18:46, Sandy Walsh <span dir="ltr"><<a href="mailto:sandy.walsh@rackspace.com" target="_blank">sandy.walsh@rackspace.com</a>></span> escreveu:<div><div class="h5"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Look at<br>
<a href="https://github.com/rackspace/stacktach/blob/master/worker.py" target="_blank">https://github.com/rackspace/stacktach/blob/master/worker.py</a><br>
(ignore the _process() call, just look at how the queue listeners are<br>
set up)<br>
<br>
my worker_conf.py looks something like<br>
DEPLOYMENTS = [<br>
dict(<br>
tenant_id=1,<br>
url='<a href="http://stacktach.example.com" target="_blank">http://stacktach.example.com</a>',<br>
rabbit_host="10.0.0.1",<br>
rabbit_port=5672,<br>
rabbit_userid="nova-staging",<br>
rabbit_password="password",<br>
rabbit_virtual_host="staging"),<br>
dict(<br>
tenant_id=2,<br>
url='<a href="http://stacktach.example.com" target="_blank">http://stacktach.example.com</a>',<br>
rabbit_host="10.99.0.1",<br>
rabbit_port=5672,<br>
rabbit_userid="nova",<br>
rabbit_password="password",<br>
rabbit_virtual_host="production"),<br>
]<br>
<br>
<br>
Or the queue listeners in<br>
<a href="https://github.com/Cerberus98/yagi" target="_blank">https://github.com/Cerberus98/yagi</a><br>
<br>
Hope it helps!<br>
-Sandy<br>
<div><br>
<br>
On 03/28/2012 05:27 PM, Leander Bessa wrote:<br>
>>From what i have figured out so far, the exchange queue is "nova" and<br>
> the routing key in your case is "<a href="http://notifications.info" target="_blank">notifications.info</a><br>
</div>> <<a href="http://notifications.info" target="_blank">http://notifications.info</a>>".<br>
<div>><br>
> On Wed, Mar 28, 2012 at 9:05 PM, Rogério Vinhal Nunes<br>
</div><div>> <<a href="mailto:rogervn@dcc.ufmg.br" target="_blank">rogervn@dcc.ufmg.br</a> <mailto:<a href="mailto:rogervn@dcc.ufmg.br" target="_blank">rogervn@dcc.ufmg.br</a>>> wrote:<br>
><br>
> I'm trying to find out information to make an application that<br>
> consumes the compute info, but I'm having some trouble. Is there a<br>
> better documentation I could follow and the precise details of the<br>
> queue/exchange/routing_key needed to take information at the end of<br>
> each run-instance and terminate-instance?<br>
><br>
> Also, I'm using amqplib and I saw that Openstack uses an internal<br>
> library named Carrot that uses amqplib. Would it be better to use it<br>
> instead?<br>
><br>
> Em 27 de março de 2012 12:42, Sandy Walsh <<a href="mailto:sandy.walsh@rackspace.com" target="_blank">sandy.walsh@rackspace.com</a><br>
</div>> <mailto:<a href="mailto:sandy.walsh@rackspace.com" target="_blank">sandy.walsh@rackspace.com</a>>> escreveu:<br>
<div>><br>
> I believe '.exists' is sent via a periodic update in<br>
> compute.manager.<br>
><br>
><br>
><br>
> On 03/27/2012 12:08 PM, Leander Bessa wrote:<br>
> > Hello,<br>
> ><br>
> > I've been following this topic and i've been trying to receive the<br>
> > notifications directly from rabbitmq with python+pika. So i far<br>
> > i've managed to receive the start/terminate events and<br>
> everything in<br>
> > between. What i am unable to find though is the topic regarding<br>
> > _compute.instance.exists_<br>
> > from <a href="http://wiki.openstack.org/SystemUsageData" target="_blank">http://wiki.openstack.org/SystemUsageData</a>. Does this even<br>
> exist, or<br>
> > is there some extra configuration required with nova?<br>
> ><br>
> > Regards,<br>
> ><br>
> > Leander<br>
> ><br>
> > On Mon, Mar 26, 2012 at 4:54 PM, Russell Bryant<br>
> <<a href="mailto:rbryant@redhat.com" target="_blank">rbryant@redhat.com</a> <mailto:<a href="mailto:rbryant@redhat.com" target="_blank">rbryant@redhat.com</a>><br>
</div><div><div>> > <mailto:<a href="mailto:rbryant@redhat.com" target="_blank">rbryant@redhat.com</a> <mailto:<a href="mailto:rbryant@redhat.com" target="_blank">rbryant@redhat.com</a>>>> wrote:<br>
> ><br>
> > -----BEGIN PGP SIGNED MESSAGE-----<br>
> > Hash: SHA1<br>
> ><br>
> > On 03/26/2012 11:48 AM, Russell Bryant wrote:<br>
> > > On 03/26/2012 10:15 AM, Rogério Vinhal Nunes wrote:<br>
> > >> Hello,<br>
> > >><br>
> > >> I'm developing a application to work along with<br>
> openstack. My<br>
> > >> application needs to keep track of all instances being<br>
> started<br>
> > >> or terminated such as feeding it information about the<br>
> location,<br>
> > >> status and other information about launched and terminated<br>
> > >> instances. The current version makes timed queries to<br>
> OpenStack<br>
> > >> database, but this is showing to be a little consuming and<br>
> > >> inefficient, so I would like to add a portion of code<br>
> to make<br>
> > >> OpenStack actively feed my application information<br>
> whenever an<br>
> > >> instance changes its status or location.<br>
> > >><br>
> > >> What is the least intrusive way to do that? It would be<br>
> very nice<br>
> > >> if OpenStack provided a way to run code on these situations<br>
> > >> without actually changing any code, such as defining a<br>
> directory<br>
> > >> of scripts to run in every instance status change.<br>
> > ><br>
> > > Check out the notifications system:<br>
> > ><br>
> > > <a href="http://wiki.openstack.org/NotificationSystem" target="_blank">http://wiki.openstack.org/NotificationSystem</a><br>
> > ><br>
> ><br>
> > That wasn't the page I thought it was ... I meant:<br>
> ><br>
> > <a href="http://wiki.openstack.org/SystemUsageData" target="_blank">http://wiki.openstack.org/SystemUsageData</a><br>
> ><br>
> > You can consume these events via AMQP if you configure<br>
> nova to use the<br>
> > rabbit notifier.<br>
> ><br>
> > - --<br>
> > Russell Bryant<br>
> > -----BEGIN PGP SIGNATURE-----<br>
> > Version: GnuPG v1.4.12 (GNU/Linux)<br>
> > Comment: Using GnuPG with Mozilla -<br>
> <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
> ><br>
> ><br>
> iEYEARECAAYFAk9wkSgACgkQFg9ft4s9SAYFuACfUu23qtxiH6WLCJNyd9gBf8i1<br>
> > FwQAnifjwWkFHYxo+KhYt8TAWEzTaMYZ<br>
> > =UWlH<br>
> > -----END PGP SIGNATURE-----<br>
> ><br>
> > _______________________________________________<br>
> > Mailing list: <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
</div></div>> <<a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/%7Eopenstack</a>><br>
<div>> > Post to : <a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a><br>
> <mailto:<a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a>><br>
</div>> > <mailto:<a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a><br>
<div>> <mailto:<a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a>>><br>
> > Unsubscribe : <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
</div>> <<a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/%7Eopenstack</a>><br>
<div>> > More help : <a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > Mailing list: <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
</div>> <<a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/%7Eopenstack</a>><br>
<div>> > Post to : <a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a><br>
> <mailto:<a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a>><br>
> > Unsubscribe : <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
</div>> <<a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/%7Eopenstack</a>><br>
<div>> > More help : <a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a><br>
><br>
> _______________________________________________<br>
> Mailing list: <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
</div>> <<a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/%7Eopenstack</a>><br>
<div>> Post to : <a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a><br>
> <mailto:<a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a>><br>
> Unsubscribe : <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
</div>> <<a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/%7Eopenstack</a>><br>
<div><div>> More help : <a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Mailing list: <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
> Post to : <a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a><br>
> <mailto:<a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a>><br>
> Unsubscribe : <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
> More help : <a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Mailing list: <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
> Post to : <a href="mailto:openstack@lists.launchpad.net" target="_blank">openstack@lists.launchpad.net</a><br>
> Unsubscribe : <a href="https://launchpad.net/%7Eopenstack" target="_blank">https://launchpad.net/~openstack</a><br>
> More help : <a href="https://help.launchpad.net/ListHelp" target="_blank">https://help.launchpad.net/ListHelp</a><br>
</div></div></blockquote></div></div></div><br>
</blockquote></div><br></div>