From: Ondrej Lichtner <olichtne(a)redhat.com>
Renamed the method to format_match_description and made it return the
formatted string describing a match that gets returned by a
MachineMapper.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
v2: fix match description logging by Controller
- split format_match_description into lines
---
---
lnst/Controller/Controller.py | 15 +++------------
lnst/Controller/MachineMapper.py | 13 +++++++++++++
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/lnst/Controller/Controller.py b/lnst/Controller/Controller.py
index 0d30026..9a5d2dd 100644
--- a/lnst/Controller/Controller.py
+++ b/lnst/Controller/Controller.py
@@ -27,6 +27,7 @@ from lnst.Controller.Config import CtlConfig
from lnst.Controller.MessageDispatcher import MessageDispatcher
from lnst.Controller.SlavePoolManager import SlavePoolManager
from lnst.Controller.MachineMapper import MachineMapper
+from lnst.Controller.MachineMapper import format_match_description
from lnst.Controller.Host import Hosts, Host
from lnst.Controller.Recipe import BaseRecipe
@@ -118,7 +119,8 @@ class Controller(object):
expand="match_%d" % i)
i += 1
- self._print_match_description(match)
+ for line in format_match_description(match).split('\n'):
+ logging.info(line)
try:
self._map_match(match, req)
recipe.test()
@@ -218,14 +220,3 @@ class Controller(object):
config.load_config(gitcfg)
return config
-
- def _print_match_description(self, match):
- logging.info("Pool match description:")
- if match["virtual"]:
- logging.info(" Setup is using virtual machines.")
- for m_id, m in sorted(match["machines"].iteritems()):
- logging.info(" host \"%s\" uses \"%s\"" %
(m_id, m["target"]))
- for if_id, match in m["interfaces"].iteritems():
- pool_id = match["target"]
- logging.info(" interface \"%s\" matched to
\"%s\"" %\
- (if_id, pool_id))
diff --git a/lnst/Controller/MachineMapper.py b/lnst/Controller/MachineMapper.py
index 39b2acc..13488eb 100644
--- a/lnst/Controller/MachineMapper.py
+++ b/lnst/Controller/MachineMapper.py
@@ -16,6 +16,19 @@ from lnst.Controller.Common import ControllerError
class MapperError(ControllerError):
pass
+def format_match_description(match):
+ output = []
+ output.append("Pool match description:")
+ if match["virtual"]:
+ output.append(" Setup is using virtual machines.")
+ for m_id, m in sorted(match["machines"].iteritems()):
+ output.append(" host \"{}\" uses
\"{}\"".format(m_id, m["target"]))
+ for if_id, match in m["interfaces"].iteritems():
+ pool_id = match["target"]
+ output.append(" interface \"{}\" matched to
\"{}\"".
+ format(if_id, pool_id))
+ return "\n".join(output)
+
class MachineMapper(object):
"""Implements a matching algorithm that maps requirements to available
hosts
--
2.16.1