From 87b3cb264dae3c1f156857e2220eed7ab8394f21 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Mon, 26 Sep 2011 12:05:55 +0200
Subject: [PATCH] Keep only one global RPC runner in Ganeti context

Instead of having one RPC runner per mcpu processor this will keep only
one instance as part of the masterd-wide Ganeti context. Upcoming
patches will change the RPC runner to report pending requests to the
lock manager.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/mcpu.py           |  3 +--
 lib/rpc.py            | 14 +++++++-------
 lib/server/masterd.py |  3 +++
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/mcpu.py b/lib/mcpu.py
index 89046c60c..4f6fd1b8f 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -35,7 +35,6 @@ import time
 from ganeti import opcodes
 from ganeti import constants
 from ganeti import errors
-from ganeti import rpc
 from ganeti import cmdlib
 from ganeti import locking
 from ganeti import utils
@@ -188,7 +187,7 @@ class Processor(object):
     self.context = context
     self._ec_id = ec_id
     self._cbs = None
-    self.rpc = rpc.RpcRunner(context.cfg)
+    self.rpc = context.rpc
     self.hmclass = HooksMaster
 
   def _AcquireLocks(self, level, names, shared, timeout, priority):
diff --git a/lib/rpc.py b/lib/rpc.py
index 60a30ab0e..b717ec015 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -414,17 +414,17 @@ def _EncodeImportExportIO(ieio, ieioargs):
 
 
 class RpcRunner(object):
-  """RPC runner class"""
+  """RPC runner class.
 
-  def __init__(self, cfg):
-    """Initialized the rpc runner.
+  """
+  def __init__(self, context):
+    """Initialized the RPC runner.
 
-    @type cfg:  C{config.ConfigWriter}
-    @param cfg: the configuration object that will be used to get data
-                about the cluster
+    @type context: C{masterd.GanetiContext}
+    @param context: Ganeti context
 
     """
-    self._cfg = cfg
+    self._cfg = context.cfg
     self.port = netutils.GetDaemonPort(constants.NODED)
 
   def _InstDict(self, instance, hvp=None, bep=None, osp=None):
diff --git a/lib/server/masterd.py b/lib/server/masterd.py
index 27bf561c4..40c5abfb2 100644
--- a/lib/server/masterd.py
+++ b/lib/server/masterd.py
@@ -399,6 +399,9 @@ class GanetiContext(object):
     # Job queue
     self.jobqueue = jqueue.JobQueue(self)
 
+    # RPC runner
+    self.rpc = rpc.RpcRunner(self)
+
     # setting this also locks the class against attribute modifications
     self.__class__._instance = self
 
-- 
GitLab