Commit d36e433d authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Let RPC clients handle their socket address



.. instead of AbstractClient itself. Also let every client call
_InitTransport() as needed. This allows to determine socket addresses
later than during the initialization of a class.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 59881a0b
......@@ -30,6 +30,7 @@ The module is also used by the master daemon.
"""
from ganeti import constants
from ganeti import pathutils
from ganeti import objects
import ganeti.rpc.client as cl
from ganeti.rpc.errors import RequestError
......@@ -81,9 +82,17 @@ class Client(cl.AbstractClient):
Arguments are the same as for L{AbstractClient}.
"""
super(Client, self).__init__(address, timeouts, transport)
super(Client, self).__init__(timeouts, transport)
# Override the version of the protocol:
self.version = constants.LUXI_VERSION
# Store the socket address
if address is None:
address = pathutils.QUERY_SOCKET
self.address = address
self._InitTransport()
def _GetAddress(self):
return self.address
def SetQueueDrainFlag(self, drain_flag):
return self.CallMethod(REQ_SET_DRAIN_FLAG, (drain_flag, ))
......
......@@ -25,7 +25,6 @@
import logging
from ganeti import pathutils
import ganeti.rpc.transport as t
from ganeti import constants
......@@ -157,8 +156,7 @@ class AbstractClient(object):
"""
def __init__(self, address=None, timeouts=None,
transport=t.Transport):
def __init__(self, timeouts=None, transport=t.Transport):
"""Constructor for the Client class.
Arguments:
......@@ -171,22 +169,24 @@ class AbstractClient(object):
class are used.
"""
if address is None:
address = pathutils.QUERY_SOCKET
self.address = address
self.timeouts = timeouts
self.transport_class = transport
self.transport = None
self._InitTransport()
# The version used in RPC communication, by default unused:
self.version = None
def _GetAddress(self):
"""Returns the socket address
"""
raise NotImplementedError
def _InitTransport(self):
"""(Re)initialize the transport if needed.
"""
if self.transport is None:
self.transport = self.transport_class(self.address,
self.transport = self.transport_class(self._GetAddress(),
timeouts=self.timeouts)
def _CloseTransport(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment