Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
RPC client lazy initialization
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
  • Loading branch information
e0ne committed Aug 6, 2014
1 parent 07534be commit d02f79b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/cinder-manage
Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit d02f79b

Please sign in to comment.