]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
RPC client lazy initialization
authorIvan Kolodyazhny <e0ne@e0ne.info>
Wed, 6 Aug 2014 10:58:43 +0000 (13:58 +0300)
committerIvan Kolodyazhny <e0ne@e0ne.info>
Wed, 6 Aug 2014 19:45:36 +0000 (22:45 +0300)
All *Command classes are instantiating for each cinder-manage command
execution. RPC client should be initialized for VolumeCommands usage.
Some custom RPC clients (oslo.messaging backends) could init RPC
connection after client initialization so it is no need to create RPC
client for every cinder-manage command invoke.

Related-Bug: #1348787
Change-Id: I7b3388dded6eeec972d9949538e1608c3a538734

bin/cinder-manage

index 0b25ae3abe39dcf23b61082567e81729ae96790d..064cbdc20864f46e82118ce5a42f98dc083caf9e 100755 (executable)
@@ -249,11 +249,17 @@ class VersionCommands(object):
 class VolumeCommands(object):
     """Methods for dealing with a cloud in an odd state."""
 
-    def __init__(self, *args, **kwargs):
-        super(VolumeCommands, self).__init__(*args, **kwargs)
-        rpc.init(CONF)
-        target = messaging.Target(topic=CONF.volume_topic)
-        self.client = rpc.get_client(target)
+    def __init__(self):
+        self._client = None
+
+    @property
+    def rpc_client(self):
+        if not rpc.initialized():
+            rpc.init(CONF)
+            target = messaging.Target(topic=CONF.volume_topic)
+            self._client = rpc.get_client(target)
+
+        return self._client
 
     @args('volume_id',
           help='Volume ID to be deleted')
@@ -276,7 +282,7 @@ class VolumeCommands(object):
             print(_("Detach volume from instance and then try again."))
             return
 
-        cctxt = self.client.prepare(server=host)
+        cctxt = self.rpc_client.prepare(server=host)
         cctxt.cast(ctxt, "delete_volume", volume_id=volume['id'])
 
     @args('--currenthost', required=True, help='Existing volume host name')