changeset 2:13e45614010e

Simplify
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Fri, 08 Feb 2013 15:41:02 +0100
parents c608c09c7edf
children cecad00e9d9f
files srxproxy.py
diffstat 1 files changed, 16 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/srxproxy.py	Fri Feb 08 15:29:09 2013 +0100
+++ b/srxproxy.py	Fri Feb 08 15:41:02 2013 +0100
@@ -4,35 +4,29 @@
 from nova import log
 
 
-class SRXProxy(object):
-    def __init__(self, topics):
-        self.topics = topics
+TOPICS = [
+    'srxproxy',
+]
 
-    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,
+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,
-        )
+    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', {}))
 
+def on_message(self, data):
+    if data.get('method') == '_associate_floating_ip':
+        _associate_floating_ip(**data.get('args', {}))
 
 
 if __name__ == '__main__':
     log.setup()
     log.root.setLevel(log.DEBUG)
-    topics = [
-        'srxproxy',
-    ]
-    SRXProxy(topics).run()
+    connection = rpc.create_connection()
+    for topic in TOPICS:
+        connection.declare_topic_consumer(topic, on_message)
+    connection.consume()