Mercurial > srxproxy
changeset 1:c608c09c7edf
Use even lower level interface for registering a consumer
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 08 Feb 2013 15:29:09 +0100 |
| parents | 927227da56d8 |
| children | 13e45614010e |
| files | srxproxy.py |
| diffstat | 1 files changed, 19 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/srxproxy.py Fri Feb 08 14:49:00 2013 +0100 +++ b/srxproxy.py Fri Feb 08 15:29:09 2013 +0100 @@ -4,20 +4,30 @@ from nova import log -class Consumer(object): - def _associate_floating_ip( - self, - context, - floating_address, - fixed_address, - interface, - ): +class SRXProxy(object): + def __init__(self, topics): + self.topics = topics + + def run(self): + connection = rpc.create_connection() + for topic in self.topics: + connection.declare_topic_consumer(topic, self.on_message) + connection.consume() + + def _associate_floating_ip(self, floating_address, fixed_address, interface, +): print "Associate floating IP %s with static IP %s on interface %s" % ( floating_address, fixed_address, interface, ) + def on_message(self, data): + method = getattr(self, data.get('method', 'default'), None) + if method: + method(**data.get('args', {})) + + if __name__ == '__main__': log.setup() @@ -25,9 +35,4 @@ topics = [ 'srxproxy', ] - connection = rpc.create_connection() - consumer = Consumer() - for topic in topics: - connection.create_consumer(topic, consumer, fanout=False) - connection.consume() - + SRXProxy(topics).run()
