-def _EncodeImportExportIO(ieio, ieioargs):
- """Encodes import/export I/O information.
-
- """
- if ieio == constants.IEIO_RAW_DISK:
- assert len(ieioargs) == 1
- return (ieioargs[0].ToDict(), )
-
- if ieio == constants.IEIO_SCRIPT:
- assert len(ieioargs) == 2
- return (ieioargs[0].ToDict(), ieioargs[1])
-
- return ieioargs
-
-
-class RpcRunner(_generated_rpc.RpcClientDefault):
- """RPC runner class.
-
- """
- def __init__(self, context):
- """Initialized the RPC runner.
-
- @type context: C{masterd.GanetiContext}
- @param context: Ganeti context
-
- """
- _generated_rpc.RpcClientDefault.__init__(self)
-
- self._cfg = context.cfg
- self._proc = _RpcProcessor(compat.partial(_NodeConfigResolver,
- self._cfg.GetNodeInfo,
- self._cfg.GetAllNodesInfo),
- netutils.GetDaemonPort(constants.NODED),
- lock_monitor_cb=context.glm.AddToLockMonitor)
-
- def _InstDict(self, instance, hvp=None, bep=None, osp=None):
- """Convert the given instance to a dict.
-
- This is done via the instance's ToDict() method and additionally
- we fill the hvparams with the cluster defaults.
-
- @type instance: L{objects.Instance}
- @param instance: an Instance object
- @type hvp: dict or None
- @param hvp: a dictionary with overridden hypervisor parameters
- @type bep: dict or None
- @param bep: a dictionary with overridden backend parameters
- @type osp: dict or None
- @param osp: a dictionary with overridden os parameters
- @rtype: dict
- @return: the instance dict, with the hvparams filled with the
- cluster defaults
-
- """
- idict = instance.ToDict()
- cluster = self._cfg.GetClusterInfo()
- idict["hvparams"] = cluster.FillHV(instance)
- if hvp is not None:
- idict["hvparams"].update(hvp)
- idict["beparams"] = cluster.FillBE(instance)
- if bep is not None:
- idict["beparams"].update(bep)
- idict["osparams"] = cluster.SimpleFillOS(instance.os, instance.osparams)
- if osp is not None:
- idict["osparams"].update(osp)
- for nic in idict["nics"]:
- nic['nicparams'] = objects.FillDict(
- cluster.nicparams[constants.PP_DEFAULT],
- nic['nicparams'])
- return idict
-
- def _MultiNodeCall(self, node_list, procedure, args, read_timeout=None):
- """Helper for making a multi-node call
-
- """
- body = serializer.DumpJson(args, indent=False)
- return self._proc(node_list, procedure, body, read_timeout=read_timeout)
-
- def _Call(self, node_list, procedure, timeout, args):
- """Entry point for automatically generated RPC wrappers.
-
- """
- return self._MultiNodeCall(node_list, procedure, args, read_timeout=timeout)
-
- @staticmethod
- def _StaticMultiNodeCall(node_list, procedure, args,
- address_list=None, read_timeout=None):
- """Helper for making a multi-node static call